-
Notifications
You must be signed in to change notification settings - Fork 64
/
IBCCommitment.sol
170 lines (145 loc) · 5.72 KB
/
IBCCommitment.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
library IBCCommitment {
// Commitment paths comply with https://github.com/cosmos/ibc/tree/main/spec/core/ics-024-host-requirements#path-space
function clientStatePath(string memory clientId) internal pure returns (bytes memory) {
return abi.encodePacked("clients/", clientId, "/clientState");
}
function consensusStatePath(string memory clientId, uint64 revisionNumber, uint64 revisionHeight)
internal
pure
returns (bytes memory)
{
return abi.encodePacked(
"clients/",
clientId,
"/consensusStates/",
Strings.toString(revisionNumber),
"-",
Strings.toString(revisionHeight)
);
}
function connectionPath(string memory connectionId) internal pure returns (bytes memory) {
return abi.encodePacked("connections/", connectionId);
}
function channelPath(string memory portId, string memory channelId) internal pure returns (bytes memory) {
return abi.encodePacked("channelEnds/ports/", portId, "/channels/", channelId);
}
function packetCommitmentPathCalldata(string calldata portId, string calldata channelId, uint64 sequence)
internal
pure
returns (bytes memory)
{
return abi.encodePacked(
"commitments/ports/", portId, "/channels/", channelId, "/sequences/", Strings.toString(sequence)
);
}
function packetAcknowledgementCommitmentPathCalldata(
string calldata portId,
string calldata channelId,
uint64 sequence
) internal pure returns (bytes memory) {
return
abi.encodePacked("acks/ports/", portId, "/channels/", channelId, "/sequences/", Strings.toString(sequence));
}
function packetReceiptCommitmentPathCalldata(string calldata portId, string calldata channelId, uint64 sequence)
internal
pure
returns (bytes memory)
{
return abi.encodePacked(
"receipts/ports/", portId, "/channels/", channelId, "/sequences/", Strings.toString(sequence)
);
}
function nextSequenceRecvCommitmentPath(string memory portId, string memory channelId)
internal
pure
returns (bytes memory)
{
return abi.encodePacked("nextSequenceRecv/ports/", portId, "/channels/", channelId);
}
function nextSequenceRecvCommitmentPathCalldata(string calldata portId, string calldata channelId)
internal
pure
returns (bytes memory)
{
return abi.encodePacked("nextSequenceRecv/ports/", portId, "/channels/", channelId);
}
function channelUpgradePath(string memory portId, string memory channelId) internal pure returns (bytes memory) {
return abi.encodePacked("channelUpgrades/upgrades/ports/", portId, "/channels/", channelId);
}
function channelUpgradeErrorPath(string memory portId, string memory channelId)
internal
pure
returns (bytes memory)
{
return abi.encodePacked("channelUpgrades/upgradeError/ports/", portId, "/channels/", channelId);
}
// Key generators for Commitment mapping
function clientStateCommitmentKey(string memory clientId) internal pure returns (bytes32) {
return keccak256(clientStatePath(clientId));
}
function consensusStateCommitmentKey(string memory clientId, uint64 revisionNumber, uint64 revisionHeight)
internal
pure
returns (bytes32)
{
return keccak256(consensusStatePath(clientId, revisionNumber, revisionHeight));
}
function connectionCommitmentKey(string memory connectionId) internal pure returns (bytes32) {
return keccak256(connectionPath(connectionId));
}
function channelCommitmentKey(string memory portId, string memory channelId) internal pure returns (bytes32) {
return keccak256(channelPath(portId, channelId));
}
function nextSequenceRecvCommitmentKey(string memory portId, string memory channelId)
internal
pure
returns (bytes32)
{
return keccak256(nextSequenceRecvCommitmentPath(portId, channelId));
}
function packetCommitmentKeyCalldata(string calldata portId, string calldata channelId, uint64 sequence)
internal
pure
returns (bytes32)
{
return keccak256(packetCommitmentPathCalldata(portId, channelId, sequence));
}
function packetAcknowledgementCommitmentKeyCalldata(
string calldata portId,
string calldata channelId,
uint64 sequence
) internal pure returns (bytes32) {
return keccak256(packetAcknowledgementCommitmentPathCalldata(portId, channelId, sequence));
}
function packetReceiptCommitmentKeyCalldata(string calldata portId, string calldata channelId, uint64 sequence)
internal
pure
returns (bytes32)
{
return keccak256(packetReceiptCommitmentPathCalldata(portId, channelId, sequence));
}
function nextSequenceRecvCommitmentKeyCalldata(string calldata portId, string calldata channelId)
internal
pure
returns (bytes32)
{
return keccak256(nextSequenceRecvCommitmentPathCalldata(portId, channelId));
}
function channelUpgradeCommitmentKey(string memory portId, string memory channelId)
internal
pure
returns (bytes32)
{
return keccak256(channelUpgradePath(portId, channelId));
}
function channelUpgradeErrorCommitmentKey(string memory portId, string memory channelId)
internal
pure
returns (bytes32)
{
return keccak256(channelUpgradeErrorPath(portId, channelId));
}
}