Skip to content

Commit

Permalink
Merge branch 'main' into refactor/express-executable
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Oct 29, 2024
2 parents 9d02b33 + 53c9a1e commit d805fdd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-eyes-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-gmp-sdk-solidity': patch
---

update signerHash to signersHash
22 changes: 11 additions & 11 deletions contracts/governance/BaseWeightedMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
struct BaseWeightedMultisigStorage {
uint256 epoch;
uint256 lastRotationTimestamp;
mapping(uint256 => bytes32) signerHashByEpoch;
mapping(bytes32 => uint256) epochBySignerHash;
mapping(uint256 => bytes32) signersHashByEpoch;
mapping(bytes32 => uint256) epochBySignersHash;
}

/// @dev Previous signers retention. 0 means only the current signers are valid
Expand Down Expand Up @@ -68,17 +68,17 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
* @param signerEpoch The given epoch
* @return bytes32 The signers hash for the given epoch
*/
function signerHashByEpoch(uint256 signerEpoch) external view returns (bytes32) {
return _baseWeightedMultisigStorage().signerHashByEpoch[signerEpoch];
function signersHashByEpoch(uint256 signerEpoch) external view returns (bytes32) {
return _baseWeightedMultisigStorage().signersHashByEpoch[signerEpoch];
}

/**
* @notice This function returns the epoch for a given signers hash
* @param signerHash The signers hash
* @param signersHash The signers hash
* @return uint256 The epoch for the given signers hash
*/
function epochBySignerHash(bytes32 signerHash) external view returns (uint256) {
return _baseWeightedMultisigStorage().epochBySignerHash[signerHash];
function epochBySignersHash(bytes32 signersHash) external view returns (uint256) {
return _baseWeightedMultisigStorage().epochBySignersHash[signersHash];
}

/**
Expand Down Expand Up @@ -117,7 +117,7 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
WeightedSigners calldata signers = proof.signers;

bytes32 signersHash = keccak256(abi.encode(signers));
uint256 signerEpoch = slot.epochBySignerHash[signersHash];
uint256 signerEpoch = slot.epochBySignersHash[signersHash];
uint256 currentEpoch = slot.epoch;

isLatestSigners = signerEpoch == currentEpoch;
Expand Down Expand Up @@ -150,12 +150,12 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
// assign the next epoch to the new signers
uint256 newEpoch = slot.epoch + 1;
slot.epoch = newEpoch;
slot.signerHashByEpoch[newEpoch] = newSignersHash;
slot.signersHashByEpoch[newEpoch] = newSignersHash;

// signers must be distinct, since nonce should guarantee uniqueness even if signers are repeated
if (slot.epochBySignerHash[newSignersHash] != 0) revert DuplicateSigners(newSignersHash);
if (slot.epochBySignersHash[newSignersHash] != 0) revert DuplicateSigners(newSignersHash);

slot.epochBySignerHash[newSignersHash] = newEpoch;
slot.epochBySignersHash[newSignersHash] = newEpoch;

emit SignersRotated(newEpoch, newSignersHash, newSignersData);
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IBaseWeightedMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ interface IBaseWeightedMultisig {
* @param signerEpoch The epoch to get the hash for
* @return The hash for the given epoch
*/
function signerHashByEpoch(uint256 signerEpoch) external view returns (bytes32);
function signersHashByEpoch(uint256 signerEpoch) external view returns (bytes32);

/**
* @dev Returns the epoch for a given hash
* @param signerHash The hash to get the epoch for
* @param signersHash The hash to get the epoch for
* @return The epoch for the given hash
*/
function epochBySignerHash(bytes32 signerHash) external view returns (uint256);
function epochBySignersHash(bytes32 signersHash) external view returns (uint256);

/**
* @notice This function returns the timestamp for the last signer rotation
Expand Down
10 changes: 5 additions & 5 deletions test/governance/BaseWeightedMultisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ describe('BaseWeightedMultisig', () => {
expect(messageHash).to.be.equal(expectedMessageHash);
});

it('signerHashByEpoch and epochBySignerHash', async () => {
it('signersHashByEpoch and epochBySignersHash', async () => {
const hash = keccak256(encodeWeightedSigners(weightedSigners));
expect(await multisig.signerHashByEpoch(1)).to.be.equal(hash);
expect(await multisig.epochBySignerHash(hash)).to.be.equal(1);
expect(await multisig.signersHashByEpoch(1)).to.be.equal(hash);
expect(await multisig.epochBySignersHash(hash)).to.be.equal(1);
});

it('lastRotationTimestamp', async () => {
Expand Down Expand Up @@ -160,8 +160,8 @@ describe('BaseWeightedMultisig', () => {
.withArgs(prevEpoch + 2, newSigners2Hash, encodeWeightedSigners(newSigners2));

// Both weighted signer should be available
expect(await multisig.epochBySignerHash(newSignersHash)).to.be.equal(prevEpoch + 1);
expect(await multisig.epochBySignerHash(newSigners2Hash)).to.be.equal(prevEpoch + 2);
expect(await multisig.epochBySignersHash(newSignersHash)).to.be.equal(prevEpoch + 1);
expect(await multisig.epochBySignersHash(newSigners2Hash)).to.be.equal(prevEpoch + 2);
});

it('should allow signer rotation to a large set of 40 signers', async () => {
Expand Down

0 comments on commit d805fdd

Please sign in to comment.