Skip to content

Commit ba35d58

Browse files
authored
Cause _addSigners to revert if it triggers a totalWeight overflow (#5790)
1 parent f9f7db0 commit ba35d58

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ abstract contract MultiSignerERC7913Weighted is MultiSignerERC7913 {
129129
_validateReachableThreshold();
130130
}
131131

132+
/**
133+
* @dev See {MultiSignerERC7913-_addSigners}.
134+
*
135+
* In cases where {totalWeight} is almost `type(uint64).max` (due to a large `_totalExtraWeight`), adding new
136+
* signers could cause the {totalWeight} computation to overflow. Adding a {totalWeight} calls after the new
137+
* signers are added ensures no such overflow happens.
138+
*/
139+
function _addSigners(bytes[] memory newSigners) internal virtual override {
140+
super._addSigners(newSigners);
141+
142+
// This will revert if the new signers cause an overflow
143+
_validateReachableThreshold();
144+
}
145+
132146
/**
133147
* @dev See {MultiSignerERC7913-_removeSigners}.
134148
*

test/account/AccountMultiSignerWeighted.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { getDomain } = require('../helpers/eip712');
66
const { ERC4337Helper } = require('../helpers/erc4337');
77
const { NonNativeSigner, P256SigningKey, RSASHA256SigningKey, MultiERC7913SigningKey } = require('../helpers/signers');
88
const { PackedUserOperation } = require('../helpers/eip712-types');
9+
const { MAX_UINT64 } = require('../helpers/constants');
910

1011
const { shouldBehaveLikeAccountCore, shouldBehaveLikeAccountHolder } = require('./Account.behavior');
1112
const { shouldBehaveLikeERC1271 } = require('../utils/cryptography/ERC1271.behavior');
@@ -292,5 +293,20 @@ describe('AccountMultiSignerWeighted', function () {
292293
.withArgs(signer1)
293294
.to.not.emit(this.mock, 'ERC7913SignerWeightChanged');
294295
});
296+
297+
it('should revert if total weight to overflow (_setSignerWeights)', async function () {
298+
await expect(this.mock.$_setSignerWeights([signer1, signer2, signer3], [1n, 1n, MAX_UINT64 - 1n]))
299+
.to.be.revertedWithCustomError(this.mock, 'SafeCastOverflowedUintDowncast')
300+
.withArgs(64, MAX_UINT64 + 1n);
301+
});
302+
303+
it('should revert if total weight to overflow (_addSigner)', async function () {
304+
await this.mock.$_setSignerWeights([signer1, signer2, signer3], [1n, 1n, MAX_UINT64 - 2n]);
305+
await expect(this.mock.totalWeight()).to.eventually.equal(MAX_UINT64);
306+
307+
await expect(this.mock.$_addSigners([signer4]))
308+
.to.be.revertedWithCustomError(this.mock, 'SafeCastOverflowedUintDowncast')
309+
.withArgs(64, MAX_UINT64 + 1n);
310+
});
295311
});
296312
});

0 commit comments

Comments
 (0)