-
Notifications
You must be signed in to change notification settings - Fork 32
/
IStatementInbox.sol
251 lines (236 loc) · 13.5 KB
/
IStatementInbox.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
interface IStatementInbox {
// ══════════════════════════════════════════ SUBMIT AGENT STATEMENTS ══════════════════════════════════════════════
/**
* @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,
* as well as Notary signature for the Snapshot.
* > StateReport is a Guard statement saying "Reported state is invalid".
* - This results in an opened Dispute between the Guard and the Notary.
* - Note: Guard could (but doesn't have to) form a StateReport and use other values from
* `verifyStateWithSnapshot()` successful call that led to Notary being slashed in remote Origin.
* > Will revert if any of these is true:
* > - State Report signer is not an active Guard.
* > - Snapshot payload is not properly formatted.
* > - Snapshot signer is not an active Notary.
* > - State index is out of range.
* > - The Guard or the Notary are already in a Dispute
* @param stateIndex Index of the reported State in the Snapshot
* @param srSignature Guard signature for the report
* @param snapPayload Raw payload with Snapshot data
* @param snapSignature Notary signature for the Snapshot
* @return wasAccepted Whether the Report was accepted (resulting in Dispute between the agents)
*/
function submitStateReportWithSnapshot(
uint8 stateIndex,
bytes memory srSignature,
bytes memory snapPayload,
bytes memory snapSignature
) external returns (bool wasAccepted);
/**
* @notice Accepts a Guard's state report signature, a Snapshot containing the reported State,
* as well as Notary signature for the Attestation created from this Snapshot.
* > StateReport is a Guard statement saying "Reported state is invalid".
* - This results in an opened Dispute between the Guard and the Notary.
* - Note: Guard could (but doesn't have to) form a StateReport and use other values from
* `verifyStateWithAttestation()` successful call that led to Notary being slashed in remote Origin.
* > Will revert if any of these is true:
* > - State Report signer is not an active Guard.
* > - Snapshot payload is not properly formatted.
* > - State index is out of range.
* > - Attestation payload is not properly formatted.
* > - Attestation signer is not an active Notary.
* > - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.
* > - The Guard or the Notary are already in a Dispute
* @param stateIndex Index of the reported State in the Snapshot
* @param srSignature Guard signature for the report
* @param snapPayload Raw payload with Snapshot data
* @param attPayload Raw payload with Attestation data
* @param attSignature Notary signature for the Attestation
* @return wasAccepted Whether the Report was accepted (resulting in Dispute between the agents)
*/
function submitStateReportWithAttestation(
uint8 stateIndex,
bytes memory srSignature,
bytes memory snapPayload,
bytes memory attPayload,
bytes memory attSignature
) external returns (bool wasAccepted);
/**
* @notice Accepts a Guard's state report signature, a proof of inclusion of the reported State in an Attestation,
* as well as Notary signature for the Attestation.
* > StateReport is a Guard statement saying "Reported state is invalid".
* - This results in an opened Dispute between the Guard and the Notary.
* - Note: Guard could (but doesn't have to) form a StateReport and use other values from
* `verifyStateWithSnapshotProof()` successful call that led to Notary being slashed in remote Origin.
* > Will revert if any of these is true:
* > - State payload is not properly formatted.
* > - State Report signer is not an active Guard.
* > - Attestation payload is not properly formatted.
* > - Attestation signer is not an active Notary.
* > - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.
* > - Snapshot Proof's first element does not match the State metadata.
* > - Snapshot Proof length exceeds Snapshot Tree Height.
* > - State index is out of range.
* > - The Guard or the Notary are already in a Dispute
* @param stateIndex Index of the reported State in the Snapshot
* @param statePayload Raw payload with State data that Guard reports as invalid
* @param srSignature Guard signature for the report
* @param snapProof Proof of inclusion of reported State's Left Leaf into Snapshot Merkle Tree
* @param attPayload Raw payload with Attestation data
* @param attSignature Notary signature for the Attestation
* @return wasAccepted Whether the Report was accepted (resulting in Dispute between the agents)
*/
function submitStateReportWithSnapshotProof(
uint8 stateIndex,
bytes memory statePayload,
bytes memory srSignature,
bytes32[] memory snapProof,
bytes memory attPayload,
bytes memory attSignature
) external returns (bool wasAccepted);
// ══════════════════════════════════════════ VERIFY AGENT STATEMENTS ══════════════════════════════════════════════
/**
* @notice Verifies a message receipt signed by the Notary.
* - Does nothing, if the receipt is valid (matches the saved receipt data for the referenced message).
* - Slashes the Notary, if the receipt is invalid.
* > Will revert if any of these is true:
* > - Receipt payload is not properly formatted.
* > - Receipt signer is not an active Notary.
* > - Receipt's destination chain does not refer to this chain.
* @param rcptPayload Raw payload with Receipt data
* @param rcptSignature Notary signature for the receipt
* @return isValidReceipt Whether the provided receipt is valid.
* Notary is slashed, if return value is FALSE.
*/
function verifyReceipt(bytes memory rcptPayload, bytes memory rcptSignature)
external
returns (bool isValidReceipt);
/**
* @notice Verifies a Guard's receipt report signature.
* - Does nothing, if the report is valid (if the reported receipt is invalid).
* - Slashes the Guard, if the report is invalid (if the reported receipt is valid).
* > Will revert if any of these is true:
* > - Receipt payload is not properly formatted.
* > - Receipt Report signer is not an active Guard.
* > - Receipt does not refer to this chain.
* @param rcptPayload Raw payload with Receipt data that Guard reports as invalid
* @param rrSignature Guard signature for the report
* @return isValidReport Whether the provided report is valid.
* Guard is slashed, if return value is FALSE.
*/
function verifyReceiptReport(bytes memory rcptPayload, bytes memory rrSignature)
external
returns (bool isValidReport);
/**
* @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.
* - Does nothing, if the state is valid (matches the historical state of this contract).
* - Slashes the Notary, if the state is invalid.
* > Will revert if any of these is true:
* > - Attestation payload is not properly formatted.
* > - Attestation signer is not an active Notary.
* > - Attestation's snapshot root is not equal to Merkle Root derived from the Snapshot.
* > - Snapshot payload is not properly formatted.
* > - State index is out of range.
* > - State does not refer to this chain.
* @param stateIndex State index to check
* @param snapPayload Raw payload with snapshot data
* @param attPayload Raw payload with Attestation data
* @param attSignature Notary signature for the attestation
* @return isValidState Whether the provided state is valid.
* Notary is slashed, if return value is FALSE.
*/
function verifyStateWithAttestation(
uint8 stateIndex,
bytes memory snapPayload,
bytes memory attPayload,
bytes memory attSignature
) external returns (bool isValidState);
/**
* @notice Verifies a state from the snapshot, that was used for the Notary-signed attestation.
* - Does nothing, if the state is valid (matches the historical state of this contract).
* - Slashes the Notary, if the state is invalid.
* > Will revert if any of these is true:
* > - Attestation payload is not properly formatted.
* > - Attestation signer is not an active Notary.
* > - Attestation's snapshot root is not equal to Merkle Root derived from State and Snapshot Proof.
* > - Snapshot Proof's first element does not match the State metadata.
* > - Snapshot Proof length exceeds Snapshot Tree Height.
* > - State payload is not properly formatted.
* > - State index is out of range.
* > - State does not refer to this chain.
* @param stateIndex Index of state in the snapshot
* @param statePayload Raw payload with State data to check
* @param snapProof Proof of inclusion of provided State's Left Leaf into Snapshot Merkle Tree
* @param attPayload Raw payload with Attestation data
* @param attSignature Notary signature for the attestation
* @return isValidState Whether the provided state is valid.
* Notary is slashed, if return value is FALSE.
*/
function verifyStateWithSnapshotProof(
uint8 stateIndex,
bytes memory statePayload,
bytes32[] memory snapProof,
bytes memory attPayload,
bytes memory attSignature
) external returns (bool isValidState);
/**
* @notice Verifies a state from the snapshot (a list of states) signed by a Guard or a Notary.
* - Does nothing, if the state is valid (matches the historical state of this contract).
* - Slashes the Agent, if the state is invalid.
* > Will revert if any of these is true:
* > - Snapshot payload is not properly formatted.
* > - Snapshot signer is not an active Agent.
* > - State index is out of range.
* > - State does not refer to this chain.
* @param stateIndex State index to check
* @param snapPayload Raw payload with snapshot data
* @param snapSignature Agent signature for the snapshot
* @return isValidState Whether the provided state is valid.
* Agent is slashed, if return value is FALSE.
*/
function verifyStateWithSnapshot(uint8 stateIndex, bytes memory snapPayload, bytes memory snapSignature)
external
returns (bool isValidState);
/**
* @notice Verifies a Guard's state report signature.
* - Does nothing, if the report is valid (if the reported state is invalid).
* - Slashes the Guard, if the report is invalid (if the reported state is valid).
* > Will revert if any of these is true:
* > - State payload is not properly formatted.
* > - State Report signer is not an active Guard.
* > - Reported State does not refer to this chain.
* @param statePayload Raw payload with State data that Guard reports as invalid
* @param srSignature Guard signature for the report
* @return isValidReport Whether the provided report is valid.
* Guard is slashed, if return value is FALSE.
*/
function verifyStateReport(bytes memory statePayload, bytes memory srSignature)
external
returns (bool isValidReport);
// ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════
/**
* @notice Returns the amount of Guard Reports stored in StatementInbox.
* > Only reports that led to opening a Dispute are stored.
*/
function getReportsAmount() external view returns (uint256);
/**
* @notice Returns the Guard report with the given index stored in StatementInbox.
* > Only reports that led to opening a Dispute are stored.
* @dev Will revert if report with given index doesn't exist.
* @param index Report index
* @return statementPayload Raw payload with statement that Guard reported as invalid
* @return reportSignature Guard signature for the report
*/
function getGuardReport(uint256 index)
external
view
returns (bytes memory statementPayload, bytes memory reportSignature);
/**
* @notice Returns the signature with the given index stored in StatementInbox.
* @dev Will revert if signature with given index doesn't exist.
* @param index Signature index
* @return Raw payload with signature
*/
function getStoredSignature(uint256 index) external view returns (bytes memory);
}