Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(governance): add check for strict Multisig threshold validation #177

Merged
merged 16 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions contracts/governance/BaseWeightedMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,13 @@ abstract contract BaseWeightedMultisig is IBaseWeightedMultisig {
// accumulating signatures weight
totalWeight = totalWeight + signers[signerIndex].weight;

// weight needs to reach or surpass threshold
if (totalWeight >= weightedSigners.threshold) return;
// weight needs to reach threshold
if (totalWeight >= weightedSigners.threshold) {
// check if number of signatures exceed required amount of signatures
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
if (signaturesLength - 1 != i) revert InvalidSignaturesLength(signaturesLength, i + 1);
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

return;
}

// increasing signers index if match was found
++signerIndex;
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IBaseWeightedMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IBaseWeightedMultisig {
error LowSignaturesWeight();
error InvalidWeights();
error DuplicateSigners(bytes32 signersHash);
error InvalidSignaturesLength(uint256 provided, uint256 required);
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
error InsufficientRotationDelay(uint256 minimumRotationDelay, uint256 lastRotationTimestamp, uint256 timeElapsed);

event SignersRotated(uint256 indexed epoch, bytes32 indexed signersHash, bytes signers);
Expand Down
20 changes: 12 additions & 8 deletions test/governance/BaseWeightedMultisig.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,6 @@ describe('BaseWeightedMultisig', () => {
await multisig.validateProofCall(dataHash, proof).then((tx) => tx.wait());
});

it('validate the proof from the current signers with extra signatures', async () => {
// sign with all signers, i.e more than threshold
const proof = await getWeightedSignersProof(data, domainSeparator, weightedSigners, signers);

const isCurrentSigners = await multisig.validateProof(dataHash, proof);
expect(isCurrentSigners).to.be.true;
});

it('validate the proof with last threshold signers', async () => {
const proof = await getWeightedSignersProof(
data,
Expand Down Expand Up @@ -481,6 +473,18 @@ describe('BaseWeightedMultisig', () => {
'LowSignaturesWeight',
);
});

it('reject the proof if number of total signatures exceed required signatures', async () => {
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
// sign with all signers, i.e more than threshold
const proof = await getWeightedSignersProof(data, domainSeparator, weightedSigners, signers);

await expectRevert(
async (gasOptions) => multisig.validateProof(dataHash, proof),
multisig,
'InvalidSignaturesLength',
[proof.signatures.length, signers.slice(0, threshold)],
);
});
});
});

Expand Down
Loading