@@ -6,238 +6,14 @@ pragma solidity ^0.8.17;
6
6
7
7
import "../rollup/Assertion.sol " ;
8
8
import "./libraries/UintUtilsLib.sol " ;
9
- import "./IAssertionChain .sol " ;
9
+ import "./IEdgeChallengeManager .sol " ;
10
10
import "./libraries/EdgeChallengeManagerLib.sol " ;
11
11
import "../libraries/Constants.sol " ;
12
12
import "../state/Machine.sol " ;
13
13
14
14
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol " ;
15
15
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol " ;
16
16
17
- /// @title EdgeChallengeManager interface
18
- interface IEdgeChallengeManager {
19
- /// @notice Initialize the EdgeChallengeManager. EdgeChallengeManagers are upgradeable
20
- /// so use the initializer paradigm
21
- /// @param _assertionChain The assertion chain contract
22
- /// @param _challengePeriodBlocks The amount of cumulative time an edge must spend unrivaled before it can be confirmed
23
- /// This should be the censorship period + the cumulative amount of time needed to do any
24
- /// offchain calculation. We currently estimate around 10 mins for each layer zero edge and 1
25
- /// one minute for each other edge.
26
- /// @param _oneStepProofEntry The one step proof logic
27
- /// @param layerZeroBlockEdgeHeight The end height of layer zero edges of type Block
28
- /// @param layerZeroBigStepEdgeHeight The end height of layer zero edges of type BigStep
29
- /// @param layerZeroSmallStepEdgeHeight The end height of layer zero edges of type SmallStep
30
- /// @param _stakeToken The token that stake will be provided in when creating zero layer block edges
31
- /// @param _excessStakeReceiver The address that excess stake will be sent to when 2nd+ block edge is created
32
- /// @param _numBigStepLevel The number of bigstep levels
33
- /// @param _stakeAmounts The stake amount for each level. (first element is for block level)
34
- function initialize (
35
- IAssertionChain _assertionChain ,
36
- uint64 _challengePeriodBlocks ,
37
- IOneStepProofEntry _oneStepProofEntry ,
38
- uint256 layerZeroBlockEdgeHeight ,
39
- uint256 layerZeroBigStepEdgeHeight ,
40
- uint256 layerZeroSmallStepEdgeHeight ,
41
- IERC20 _stakeToken ,
42
- address _excessStakeReceiver ,
43
- uint8 _numBigStepLevel ,
44
- uint256 [] calldata _stakeAmounts
45
- ) external ;
46
-
47
- function challengePeriodBlocks () external view returns (uint64 );
48
-
49
- /// @notice The one step proof resolver used to decide between rival SmallStep edges of length 1
50
- function oneStepProofEntry () external view returns (IOneStepProofEntry);
51
-
52
- /// @notice Performs necessary checks and creates a new layer zero edge
53
- /// @param args Edge creation args
54
- function createLayerZeroEdge (
55
- CreateEdgeArgs calldata args
56
- ) external returns (bytes32 );
57
-
58
- /// @notice Bisect an edge. This creates two child edges:
59
- /// lowerChild: has the same start root and height as this edge, but a different end root and height
60
- /// upperChild: has the same end root and height as this edge, but a different start root and height
61
- /// The lower child end root and height are equal to the upper child start root and height. This height
62
- /// is the mandatoryBisectionHeight.
63
- /// The lower child may already exist, however it's not possible for the upper child to exist as that would
64
- /// mean that the edge has already been bisected
65
- /// @param edgeId Edge to bisect
66
- /// @param bisectionHistoryRoot The new history root to be used in the lower and upper children
67
- /// @param prefixProof A proof to show that the bisectionHistoryRoot commits to a prefix of the current endHistoryRoot
68
- /// @return lowerChildId The id of the newly created lower child edge
69
- /// @return upperChildId The id of the newly created upper child edge
70
- function bisectEdge (
71
- bytes32 edgeId ,
72
- bytes32 bisectionHistoryRoot ,
73
- bytes calldata prefixProof
74
- ) external returns (bytes32 , bytes32 );
75
-
76
- /// @notice An edge can be confirmed if the total amount of time it and a single chain of its direct ancestors
77
- /// has spent unrivaled is greater than the challenge period.
78
- /// @dev Edges inherit time from their parents, so the sum of unrivaled timers is compared against the threshold.
79
- /// Given that an edge cannot become unrivaled after becoming rivaled, once the threshold is passed
80
- /// it will always remain passed. The direct ancestors of an edge are linked by parent-child links for edges
81
- /// of the same level, and claimId-edgeId links for zero layer edges that claim an edge in the level below.
82
- /// This method also includes the amount of time the assertion being claimed spent without a sibling
83
- /// @param edgeId The id of the edge to confirm
84
- function confirmEdgeByTime (
85
- bytes32 edgeId ,
86
- AssertionStateData calldata claimStateData
87
- ) external ;
88
-
89
- /// @notice Update multiple edges' timer cache by their children. Equivalent to calling updateTimerCacheByChildren for each edge.
90
- /// May update timer cache above maximum if the last edge's timer cache was below maximumCachedTime.
91
- /// Revert when the last edge's timer cache is already equal to or above maximumCachedTime.
92
- /// @param edgeIds The ids of the edges to update
93
- /// @param maximumCachedTime The maximum amount of cached time allowed on the last edge (β∗)
94
- function multiUpdateTimeCacheByChildren (
95
- bytes32 [] calldata edgeIds ,
96
- uint256 maximumCachedTime
97
- ) external ;
98
-
99
- /// @notice Update an edge's timer cache by its children.
100
- /// Sets the edge's timer cache to its timeUnrivaled + (minimum timer cache of its children).
101
- /// May update timer cache above maximum if the last edge's timer cache was below maximumCachedTime.
102
- /// Revert when the edge's timer cache is already equal to or above maximumCachedTime.
103
- /// @param edgeId The id of the edge to update
104
- /// @param maximumCachedTime The maximum amount of cached time allowed on the edge (β∗)
105
- function updateTimerCacheByChildren (bytes32 edgeId , uint256 maximumCachedTime ) external ;
106
-
107
- /// @notice Given a one step fork edge and an edge with matching claim id,
108
- /// set the one step fork edge's timer cache to its timeUnrivaled + claiming edge's timer cache.
109
- /// May update timer cache above maximum if the last edge's timer cache was below maximumCachedTime.
110
- /// Revert when the edge's timer cache is already equal to or above maximumCachedTime.
111
- /// @param edgeId The id of the edge to update
112
- /// @param claimingEdgeId The id of the edge which has a claimId equal to edgeId
113
- /// @param maximumCachedTime The maximum amount of cached time allowed on the edge (β∗)
114
- function updateTimerCacheByClaim (
115
- bytes32 edgeId ,
116
- bytes32 claimingEdgeId ,
117
- uint256 maximumCachedTime
118
- ) external ;
119
-
120
- /// @notice Confirm an edge by executing a one step proof
121
- /// @dev One step proofs can only be executed against edges that have length one and of type SmallStep
122
- /// @param edgeId The id of the edge to confirm
123
- /// @param oneStepData Input data to the one step proof
124
- /// @param prevConfig Data about the config set in prev
125
- /// @param beforeHistoryInclusionProof Proof that the state which is the start of the edge is committed to by the startHistoryRoot
126
- /// @param afterHistoryInclusionProof Proof that the state which is the end of the edge is committed to by the endHistoryRoot
127
- function confirmEdgeByOneStepProof (
128
- bytes32 edgeId ,
129
- OneStepData calldata oneStepData ,
130
- ConfigData calldata prevConfig ,
131
- bytes32 [] calldata beforeHistoryInclusionProof ,
132
- bytes32 [] calldata afterHistoryInclusionProof
133
- ) external ;
134
-
135
- /// @notice When zero layer block edges are created a stake is also provided
136
- /// The stake on this edge can be refunded if the edge is confirme
137
- function refundStake (
138
- bytes32 edgeId
139
- ) external ;
140
-
141
- /// @notice Zero layer edges have to be a fixed height.
142
- /// This function returns the end height for a given edge type
143
- function getLayerZeroEndHeight (
144
- EdgeType eType
145
- ) external view returns (uint256 );
146
-
147
- /// @notice Calculate the unique id of an edge
148
- /// @param level The level of the edge
149
- /// @param originId The origin id of the edge
150
- /// @param startHeight The start height of the edge
151
- /// @param startHistoryRoot The start history root of the edge
152
- /// @param endHeight The end height of the edge
153
- /// @param endHistoryRoot The end history root of the edge
154
- function calculateEdgeId (
155
- uint8 level ,
156
- bytes32 originId ,
157
- uint256 startHeight ,
158
- bytes32 startHistoryRoot ,
159
- uint256 endHeight ,
160
- bytes32 endHistoryRoot
161
- ) external pure returns (bytes32 );
162
-
163
- /// @notice Calculate the mutual id of the edge
164
- /// Edges that are rivals share the same mutual id
165
- /// @param level The level of the edge
166
- /// @param originId The origin id of the edge
167
- /// @param startHeight The start height of the edge
168
- /// @param startHistoryRoot The start history root of the edge
169
- /// @param endHeight The end height of the edge
170
- function calculateMutualId (
171
- uint8 level ,
172
- bytes32 originId ,
173
- uint256 startHeight ,
174
- bytes32 startHistoryRoot ,
175
- uint256 endHeight
176
- ) external pure returns (bytes32 );
177
-
178
- /// @notice Has the edge already been stored in the manager
179
- function edgeExists (
180
- bytes32 edgeId
181
- ) external view returns (bool );
182
-
183
- /// @notice Get full edge data for an edge
184
- function getEdge (
185
- bytes32 edgeId
186
- ) external view returns (ChallengeEdge memory );
187
-
188
- /// @notice The length of the edge, from start height to end height
189
- function edgeLength (
190
- bytes32 edgeId
191
- ) external view returns (uint256 );
192
-
193
- /// @notice Does this edge currently have one or more rivals
194
- /// Rival edges share the same mutual id
195
- function hasRival (
196
- bytes32 edgeId
197
- ) external view returns (bool );
198
-
199
- /// @notice The confirmed rival of this mutual id
200
- /// Returns 0 if one does not exist
201
- function confirmedRival (
202
- bytes32 mutualId
203
- ) external view returns (bytes32 );
204
-
205
- /// @notice Does the edge have at least one rival, and it has length one
206
- function hasLengthOneRival (
207
- bytes32 edgeId
208
- ) external view returns (bool );
209
-
210
- /// @notice The amount of time this edge has spent without rivals
211
- /// This value is increasing whilst an edge is unrivaled, once a rival is created
212
- /// it is fixed. If an edge has rivals from the moment it is created then it will have
213
- /// a zero time unrivaled
214
- function timeUnrivaled (
215
- bytes32 edgeId
216
- ) external view returns (uint256 );
217
-
218
- /// @notice Get the id of the prev assertion that this edge is originates from
219
- /// @dev Uses the parent chain to traverse upwards SmallStep->BigStep->Block->Assertion
220
- /// until it gets to the origin assertion
221
- function getPrevAssertionHash (
222
- bytes32 edgeId
223
- ) external view returns (bytes32 );
224
-
225
- /// @notice Fetch the raw first rival record for the given mutual id
226
- /// @dev Returns 0 if there is no edge with the given mutual id
227
- /// Returns a magic value if there is one edge but it is unrivaled
228
- /// Returns the id of the second edge created with the mutual id, if > 1 exists
229
- function firstRival (
230
- bytes32 mutualId
231
- ) external view returns (bytes32 );
232
-
233
- /// @notice True if an account has made a layer zero edge with the given mutual id.
234
- /// This is only tracked when the validator whitelist is enabled
235
- function hasMadeLayerZeroRival (
236
- address account ,
237
- bytes32 mutualId
238
- ) external view returns (bool );
239
- }
240
-
241
17
/// @title A challenge manager that uses edge structures to decide between Assertions
242
18
/// @notice When two assertions are created that have the same predecessor the protocol needs to decide which of the two is correct
243
19
/// This challenge manager allows the staker who has created the valid assertion to enforce that it will be confirmed, and all
0 commit comments