@@ -51,10 +51,8 @@ contract QuantumGravityBridge is IDAOracle {
51
51
bytes32 public state_lastValidatorSetCheckpoint;
52
52
/// @notice Voting power required to submit a new update.
53
53
uint256 public state_powerThreshold;
54
- /// @notice Unique nonce of validator set updates.
55
- uint256 public state_lastValidatorSetNonce;
56
- /// @notice Unique nonce of data root tuple root updates.
57
- uint256 public state_lastDataRootTupleRootNonce;
54
+ /// @notice Nonce for bridge events. Must be incremented sequentially.
55
+ uint256 public state_eventNonce;
58
56
/// @notice Mapping of data root tuple root nonces to data root tuple roots.
59
57
mapping (uint256 => bytes32 ) public state_dataRootTupleRoots;
60
58
@@ -63,13 +61,13 @@ contract QuantumGravityBridge is IDAOracle {
63
61
////////////
64
62
65
63
/// @notice Emitted when a new root of data root tuples is relayed.
66
- /// @param nonce Nonce .
64
+ /// @param nonce Event nonce .
67
65
/// @param dataRootTupleRoot Merkle root of relayed data root tuples.
68
66
/// See `submitDataRootTupleRoot`.
69
67
event DataRootTupleRootEvent (uint256 indexed nonce , bytes32 dataRootTupleRoot );
70
68
71
69
/// @notice Emitted when the validator set is updated.
72
- /// @param nonce Nonce .
70
+ /// @param nonce Event nonce .
73
71
/// @param powerThreshold New voting power threshold.
74
72
/// @param validatorSetHash Hash of new validator set.
75
73
/// See `updateValidatorSet`.
@@ -103,7 +101,7 @@ contract QuantumGravityBridge is IDAOracle {
103
101
104
102
/// @param _bridge_id Identifier of the bridge, used in signatures for
105
103
/// domain separation.
106
- /// @param _nonce Celestia block height at which bridge is initialized .
104
+ /// @param _nonce Initial event nonce .
107
105
/// @param _powerThreshold Initial voting power that is needed to approve
108
106
/// operations.
109
107
/// @param _validatorSetHash Initial validator set hash. This does not need
@@ -123,7 +121,7 @@ contract QuantumGravityBridge is IDAOracle {
123
121
124
122
// EFFECTS
125
123
126
- state_lastValidatorSetNonce = _nonce;
124
+ state_eventNonce = _nonce;
127
125
state_lastValidatorSetCheckpoint = newCheckpoint;
128
126
state_powerThreshold = _powerThreshold;
129
127
@@ -180,19 +178,17 @@ contract QuantumGravityBridge is IDAOracle {
180
178
/// @dev Make a domain-separated commitment to a data root tuple root.
181
179
/// A hash of all relevant information about a data root tuple root.
182
180
/// The format of the hash is:
183
- /// keccak256(bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, oldNonce, newNonce , dataRootTupleRoot)
181
+ /// keccak256(bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, nonce , dataRootTupleRoot)
184
182
/// @param _bridge_id Bridge ID.
185
- /// @param _oldNonce Celestia block height at which commitment begins.
186
- /// @param _newNonce Celestia block height at which commitment ends.
183
+ /// @param _nonce Event nonce.
187
184
/// @param _dataRootTupleRoot Data root tuple root.
188
185
function domainSeparateDataRootTupleRoot (
189
186
bytes32 _bridge_id ,
190
- uint256 _oldNonce ,
191
- uint256 _newNonce ,
187
+ uint256 _nonce ,
192
188
bytes32 _dataRootTupleRoot
193
189
) private pure returns (bytes32 ) {
194
190
bytes32 c = keccak256 (
195
- abi.encode (_bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _oldNonce, _newNonce , _dataRootTupleRoot)
191
+ abi.encode (_bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _nonce , _dataRootTupleRoot)
196
192
);
197
193
198
194
return c;
@@ -248,7 +244,7 @@ contract QuantumGravityBridge is IDAOracle {
248
244
/// The validator set hash that is signed over is domain separated as per
249
245
/// `domainSeparateValidatorSetHash`.
250
246
/// @param _newValidatorSetHash The hash of the new validator set.
251
- /// @param _newNonce The new Celestia block height .
247
+ /// @param _newNonce The new event nonce .
252
248
/// @param _currentValidatorSet The current validator set.
253
249
/// @param _sigs Signatures.
254
250
function updateValidatorSet (
@@ -260,11 +256,11 @@ contract QuantumGravityBridge is IDAOracle {
260
256
) external {
261
257
// CHECKS
262
258
263
- uint256 currentNonce = state_lastValidatorSetNonce ;
259
+ uint256 currentNonce = state_eventNonce ;
264
260
uint256 currentPowerThreshold = state_powerThreshold;
265
261
266
- // Check that the new validator set nonce is greater than the old one.
267
- if (_newNonce < = currentNonce) {
262
+ // Check that the new nonce is one more than the current one.
263
+ if (_newNonce ! = currentNonce + 1 ) {
268
264
revert InvalidValidatorSetNonce ();
269
265
}
270
266
@@ -295,7 +291,7 @@ contract QuantumGravityBridge is IDAOracle {
295
291
296
292
state_lastValidatorSetCheckpoint = newCheckpoint;
297
293
state_powerThreshold = _newPowerThreshold;
298
- state_lastValidatorSetNonce = _newNonce;
294
+ state_eventNonce = _newNonce;
299
295
300
296
// LOGS
301
297
@@ -314,24 +310,26 @@ contract QuantumGravityBridge is IDAOracle {
314
310
///
315
311
/// The data tuple root that is signed over is domain separated as per
316
312
/// `domainSeparateDataRootTupleRoot`.
317
- /// @param _nonce The Celestia block height up to which the data root tuple
318
- /// root commits to.
313
+ /// @param _newNonce The new event nonce.
314
+ /// @param _validatorSetNonce The nonce of the latest update to the
315
+ /// validator set.
319
316
/// @param _dataRootTupleRoot The Merkle root of data root tuples.
320
317
/// @param _currentValidatorSet The current validator set.
321
318
/// @param _sigs Signatures.
322
319
function submitDataRootTupleRoot (
323
- uint256 _nonce ,
320
+ uint256 _newNonce ,
321
+ uint256 _validatorSetNonce ,
324
322
bytes32 _dataRootTupleRoot ,
325
323
Validator[] calldata _currentValidatorSet ,
326
324
Signature[] calldata _sigs
327
325
) external {
328
326
// CHECKS
329
327
330
- uint256 currentNonce = state_lastDataRootTupleRootNonce ;
328
+ uint256 currentNonce = state_eventNonce ;
331
329
uint256 currentPowerThreshold = state_powerThreshold;
332
330
333
- // Check that the data root tuple root nonce is higher than the last nonce .
334
- if (_nonce < = currentNonce) {
331
+ // Check that the new nonce is one more than the current one .
332
+ if (_newNonce ! = currentNonce + 1 ) {
335
333
revert InvalidDataRootTupleRootNonce ();
336
334
}
337
335
@@ -345,7 +343,7 @@ contract QuantumGravityBridge is IDAOracle {
345
343
if (
346
344
domainSeparateValidatorSetHash (
347
345
BRIDGE_ID,
348
- state_lastValidatorSetNonce ,
346
+ _validatorSetNonce ,
349
347
currentPowerThreshold,
350
348
currentValidatorSetHash
351
349
) != state_lastValidatorSetCheckpoint
@@ -355,32 +353,32 @@ contract QuantumGravityBridge is IDAOracle {
355
353
356
354
// Check that enough current validators have signed off on the data
357
355
// root tuple root and nonce.
358
- bytes32 c = domainSeparateDataRootTupleRoot (BRIDGE_ID, currentNonce, _nonce , _dataRootTupleRoot);
356
+ bytes32 c = domainSeparateDataRootTupleRoot (BRIDGE_ID, _newNonce , _dataRootTupleRoot);
359
357
checkValidatorSignatures (_currentValidatorSet, _sigs, c, currentPowerThreshold);
360
358
361
359
// EFFECTS
362
360
363
- state_lastDataRootTupleRootNonce = _nonce ;
364
- state_dataRootTupleRoots[_nonce ] = _dataRootTupleRoot;
361
+ state_eventNonce = _newNonce ;
362
+ state_dataRootTupleRoots[_newNonce ] = _dataRootTupleRoot;
365
363
366
364
// LOGS
367
365
368
- emit DataRootTupleRootEvent (_nonce , _dataRootTupleRoot);
366
+ emit DataRootTupleRootEvent (_newNonce , _dataRootTupleRoot);
369
367
}
370
368
371
369
/// @dev see "./IDAOracle.sol"
372
370
function verifyAttestation (
373
- uint256 _tupleRootIndex ,
371
+ uint256 _tupleRootNonce ,
374
372
DataRootTuple memory _tuple ,
375
373
BinaryMerkleProof memory _proof
376
374
) external view override returns (bool ) {
377
375
// Tuple must have been committed before.
378
- if (_tupleRootIndex > state_lastDataRootTupleRootNonce ) {
376
+ if (_tupleRootNonce > state_eventNonce ) {
379
377
return false ;
380
378
}
381
379
382
380
// Load the tuple root at the given index from storage.
383
- bytes32 root = state_dataRootTupleRoots[_tupleRootIndex ];
381
+ bytes32 root = state_dataRootTupleRoots[_tupleRootNonce ];
384
382
385
383
// Verify the proof.
386
384
bool isProofValid = BinaryMerkleTree.verify (root, _proof, abi.encode (_tuple));
0 commit comments