Skip to content

Commit

Permalink
Use old validator set nonce instead of latest nonce. (#121)
Browse files Browse the repository at this point in the history
* Use old validator set nonce instead of latest nonce.

* Update go wrapper.
  • Loading branch information
adlerjohn authored Jun 22, 2022
1 parent 210a1fb commit 72a20c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
7 changes: 5 additions & 2 deletions src/QuantumGravityBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,15 @@ contract QuantumGravityBridge is IDAOracle {
///
/// The validator set hash that is signed over is domain separated as per
/// `domainSeparateValidatorSetHash`.
/// @param _newValidatorSetHash The hash of the new validator set.
/// @param _newNonce The new event nonce.
/// @param _oldNonce The nonce of the latest update to the validator set.
/// @param _newPowerThreshold At least this much power must have signed.
/// @param _newValidatorSetHash The hash of the new validator set.
/// @param _currentValidatorSet The current validator set.
/// @param _sigs Signatures.
function updateValidatorSet(
uint256 _newNonce,
uint256 _oldNonce,
uint256 _newPowerThreshold,
bytes32 _newValidatorSetHash,
Validator[] calldata _currentValidatorSet,
Expand All @@ -272,7 +275,7 @@ contract QuantumGravityBridge is IDAOracle {
// Check that the supplied current validator set matches the saved checkpoint.
bytes32 currentValidatorSetHash = computeValidatorSetHash(_currentValidatorSet);
if (
domainSeparateValidatorSetHash(BRIDGE_ID, currentNonce, currentPowerThreshold, currentValidatorSetHash) !=
domainSeparateValidatorSetHash(BRIDGE_ID, _oldNonce, currentPowerThreshold, currentValidatorSetHash) !=
state_lastValidatorSetCheckpoint
) {
revert SuppliedValidatorSetInvalid();
Expand Down
4 changes: 3 additions & 1 deletion src/test/QuantumGravityBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ contract RelayerTest is DSTest {
}

function testUpdateValidatorSet() public {
uint256 initialVelsetNonce = 0;

// Save the old test validator set before we add to it.
Validator[] memory oldVS = new Validator[](1);
oldVS[0] = Validator(cheats.addr(testPriv1), votingPower);
Expand All @@ -64,7 +66,7 @@ contract RelayerTest is DSTest {
(uint8 v, bytes32 r, bytes32 s) = cheats.sign(testPriv1, digest_eip191);
sigs[0] = Signature(v, r, s);

bridge.updateValidatorSet(newNonce, newPowerThreshold, newVSHash, oldVS, sigs);
bridge.updateValidatorSet(newNonce, initialVelsetNonce, newPowerThreshold, newVSHash, oldVS, sigs);

assertEq(bridge.state_eventNonce(), newNonce);
assertEq(bridge.state_powerThreshold(), newPowerThreshold);
Expand Down
Loading

0 comments on commit 72a20c2

Please sign in to comment.