Skip to content

Commit 362e7da

Browse files
authored
chore: remove unnecessary BRIDGE_ID (#130)
1 parent 5f3d1ff commit 362e7da

File tree

3 files changed

+19
-73
lines changed

3 files changed

+19
-73
lines changed

src/QuantumGravityBridge.sol

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ contract QuantumGravityBridge is IDAOracle {
3737
// be accounted for in any upgrades. Always test an exact upgrade on testnet
3838
// and localhost before mainnet upgrades.
3939

40-
////////////////
41-
// Immutables //
42-
////////////////
43-
44-
bytes32 public immutable BRIDGE_ID;
45-
4640
/////////////
4741
// Storage //
4842
/////////////
@@ -99,25 +93,20 @@ contract QuantumGravityBridge is IDAOracle {
9993
// Functions //
10094
///////////////
10195

102-
/// @param _bridge_id Identifier of the bridge, used in signatures for
103-
/// domain separation.
10496
/// @param _nonce Initial event nonce.
10597
/// @param _powerThreshold Initial voting power that is needed to approve
10698
/// operations.
10799
/// @param _validatorSetHash Initial validator set hash. This does not need
108100
/// to be the genesis validator set of the bridged chain, only the initial
109101
/// validator set of the bridge.
110102
constructor(
111-
bytes32 _bridge_id,
112103
uint256 _nonce,
113104
uint256 _powerThreshold,
114105
bytes32 _validatorSetHash
115106
) {
116-
BRIDGE_ID = _bridge_id;
117-
118107
// CHECKS
119108

120-
bytes32 newCheckpoint = domainSeparateValidatorSetHash(_bridge_id, _nonce, _powerThreshold, _validatorSetHash);
109+
bytes32 newCheckpoint = domainSeparateValidatorSetHash(_nonce, _powerThreshold, _validatorSetHash);
121110

122111
// EFFECTS
123112

@@ -156,20 +145,18 @@ contract QuantumGravityBridge is IDAOracle {
156145
/// @dev Make a domain-separated commitment to the validator set.
157146
/// A hash of all relevant information about the validator set.
158147
/// The format of the hash is:
159-
/// keccak256(bridge_id, VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, nonce, power_threshold, validator_set_hash)
148+
/// keccak256(VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, nonce, power_threshold, validator_set_hash)
160149
/// The elements in the validator set should be monotonically decreasing by power.
161-
/// @param _bridge_id Bridge ID.
162150
/// @param _nonce Nonce.
163151
/// @param _powerThreshold The voting power threshold.
164152
/// @param _validatorSetHash Validator set hash.
165153
function domainSeparateValidatorSetHash(
166-
bytes32 _bridge_id,
167154
uint256 _nonce,
168155
uint256 _powerThreshold,
169156
bytes32 _validatorSetHash
170157
) private pure returns (bytes32) {
171158
bytes32 c = keccak256(
172-
abi.encode(_bridge_id, VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, _nonce, _powerThreshold, _validatorSetHash)
159+
abi.encode(VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, _nonce, _powerThreshold, _validatorSetHash)
173160
);
174161

175162
return c;
@@ -178,17 +165,15 @@ contract QuantumGravityBridge is IDAOracle {
178165
/// @dev Make a domain-separated commitment to a data root tuple root.
179166
/// A hash of all relevant information about a data root tuple root.
180167
/// The format of the hash is:
181-
/// keccak256(bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, nonce, dataRootTupleRoot)
182-
/// @param _bridge_id Bridge ID.
168+
/// keccak256(DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, nonce, dataRootTupleRoot)
183169
/// @param _nonce Event nonce.
184170
/// @param _dataRootTupleRoot Data root tuple root.
185171
function domainSeparateDataRootTupleRoot(
186-
bytes32 _bridge_id,
187172
uint256 _nonce,
188173
bytes32 _dataRootTupleRoot
189174
) private pure returns (bytes32) {
190175
bytes32 c = keccak256(
191-
abi.encode(_bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _nonce, _dataRootTupleRoot)
176+
abi.encode(DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _nonce, _dataRootTupleRoot)
192177
);
193178

194179
return c;
@@ -276,15 +261,14 @@ contract QuantumGravityBridge is IDAOracle {
276261
// Check that the supplied current validator set matches the saved checkpoint.
277262
bytes32 currentValidatorSetHash = computeValidatorSetHash(_currentValidatorSet);
278263
if (
279-
domainSeparateValidatorSetHash(BRIDGE_ID, _oldNonce, currentPowerThreshold, currentValidatorSetHash) !=
264+
domainSeparateValidatorSetHash(_oldNonce, currentPowerThreshold, currentValidatorSetHash) !=
280265
state_lastValidatorSetCheckpoint
281266
) {
282267
revert SuppliedValidatorSetInvalid();
283268
}
284269

285270
// Check that enough current validators have signed off on the new validator set.
286271
bytes32 newCheckpoint = domainSeparateValidatorSetHash(
287-
BRIDGE_ID,
288272
_newNonce,
289273
_newPowerThreshold,
290274
_newValidatorSetHash
@@ -346,7 +330,6 @@ contract QuantumGravityBridge is IDAOracle {
346330
bytes32 currentValidatorSetHash = computeValidatorSetHash(_currentValidatorSet);
347331
if (
348332
domainSeparateValidatorSetHash(
349-
BRIDGE_ID,
350333
_validatorSetNonce,
351334
currentPowerThreshold,
352335
currentValidatorSetHash
@@ -357,7 +340,7 @@ contract QuantumGravityBridge is IDAOracle {
357340

358341
// Check that enough current validators have signed off on the data
359342
// root tuple root and nonce.
360-
bytes32 c = domainSeparateDataRootTupleRoot(BRIDGE_ID, _newNonce, _dataRootTupleRoot);
343+
bytes32 c = domainSeparateDataRootTupleRoot(_newNonce, _dataRootTupleRoot);
361344
checkValidatorSignatures(_currentValidatorSet, _sigs, c, currentPowerThreshold);
362345

363346
// EFFECTS

src/test/QuantumGravityBridge.t.sol

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ contract RelayerTest is DSTest {
2626
uint256 constant testPriv1 = 0x64a1d6f0e760a8d62b4afdde4096f16f51b401eaaecc915740f71770ea76a8ad;
2727
uint256 constant testPriv2 = 0x6e8bdfa979ab645b41c4d17cb1329b2a44684c82b61b1b060ea9b6e1c927a4f4;
2828

29-
// 32 bytes, chosen at random.
30-
bytes32 constant BRIDGE_ID = 0x6de92bac0b357560d821f8e7b6f5c9fe4f3f88f6c822283efd7ab51ad56a640e;
31-
3229
QuantumGravityBridge bridge;
3330

3431
Validator[] private validators;
@@ -43,7 +40,7 @@ contract RelayerTest is DSTest {
4340

4441
validators.push(Validator(cheats.addr(testPriv1), votingPower));
4542
bytes32 hash = computeValidatorSetHash(validators);
46-
bridge = new QuantumGravityBridge(BRIDGE_ID, initialVelsetNonce, (2 * votingPower) / 3, hash);
43+
bridge = new QuantumGravityBridge(initialVelsetNonce, (2 * votingPower) / 3, hash);
4744
}
4845

4946
function testUpdateValidatorSet() public {
@@ -58,7 +55,7 @@ contract RelayerTest is DSTest {
5855
votingPower += votingPower;
5956
uint256 newPowerThreshold = (2 * votingPower) / 3;
6057
bytes32 newVSHash = keccak256(abi.encode(validators));
61-
bytes32 newCheckpoint = domainSeparateValidatorSetHash(BRIDGE_ID, newNonce, newPowerThreshold, newVSHash);
58+
bytes32 newCheckpoint = domainSeparateValidatorSetHash(newNonce, newPowerThreshold, newVSHash);
6259

6360
// Signature for the first validator set update.
6461
Signature[] memory sigs = new Signature[](1);
@@ -79,7 +76,7 @@ contract RelayerTest is DSTest {
7976
// 32 bytes, chosen at random.
8077
bytes32 newTupleRoot = 0x0de92bac0b356560d821f8e7b6f5c9fe4f3f88f6c822283efd7ab51ad56a640e;
8178

82-
bytes32 newDataRootTupleRoot = domainSeparateDataRootTupleRoot(BRIDGE_ID, nonce, newTupleRoot);
79+
bytes32 newDataRootTupleRoot = domainSeparateDataRootTupleRoot(nonce, newTupleRoot);
8380

8481
// Signature for the update.
8582
Signature[] memory sigs = new Signature[](1);
@@ -101,25 +98,23 @@ contract RelayerTest is DSTest {
10198
}
10299

103100
function domainSeparateValidatorSetHash(
104-
bytes32 _bridge_id,
105101
uint256 _nonce,
106102
uint256 _powerThreshold,
107103
bytes32 _validatorSetHash
108104
) private pure returns (bytes32) {
109105
bytes32 c = keccak256(
110-
abi.encode(_bridge_id, VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, _nonce, _powerThreshold, _validatorSetHash)
106+
abi.encode(VALIDATOR_SET_HASH_DOMAIN_SEPARATOR, _nonce, _powerThreshold, _validatorSetHash)
111107
);
112108

113109
return c;
114110
}
115111

116112
function domainSeparateDataRootTupleRoot(
117-
bytes32 _bridge_id,
118113
uint256 _nonce,
119114
bytes32 _dataRootTupleRoot
120115
) private pure returns (bytes32) {
121116
bytes32 c = keccak256(
122-
abi.encode(_bridge_id, DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _nonce, _dataRootTupleRoot)
117+
abi.encode(DATA_ROOT_TUPLE_ROOT_DOMAIN_SEPARATOR, _nonce, _dataRootTupleRoot)
123118
);
124119

125120
return c;

0 commit comments

Comments
 (0)