Skip to content

Commit 292b354

Browse files
authored
Do not emit an event when setSignerWeight is a no-op (#5775)
1 parent 6e14ecc commit 292b354

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

contracts/utils/cryptography/signers/MultiSignerERC7913Weighted.sol

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,22 @@ abstract contract MultiSignerERC7913Weighted is MultiSignerERC7913 {
104104
uint256 extraWeightRemoved = 0;
105105
for (uint256 i = 0; i < signers.length; ++i) {
106106
bytes memory signer = signers[i];
107-
uint64 weight = weights[i];
108-
109107
require(isSigner(signer), MultiSignerERC7913NonexistentSigner(signer));
108+
109+
uint64 weight = weights[i];
110110
require(weight > 0, MultiSignerERC7913WeightedInvalidWeight(signer, weight));
111111

112112
unchecked {
113-
// Overflow impossible: weight values are bounded by uint64 and economic constraints
114-
extraWeightRemoved += _extraWeights[signer];
115-
extraWeightAdded += _extraWeights[signer] = weight - 1;
113+
uint64 oldExtraWeight = _extraWeights[signer];
114+
uint64 newExtraWeight = weight - 1;
115+
116+
if (oldExtraWeight != newExtraWeight) {
117+
// Overflow impossible: weight values are bounded by uint64 and economic constraints
118+
extraWeightRemoved += oldExtraWeight;
119+
extraWeightAdded += _extraWeights[signer] = newExtraWeight;
120+
emit ERC7913SignerWeightChanged(signer, weight);
121+
}
116122
}
117-
118-
emit ERC7913SignerWeightChanged(signer, weight);
119123
}
120124
unchecked {
121125
// Safe from underflow: `extraWeightRemoved` is bounded by `_totalExtraWeight` by construction

test/account/AccountMultiSignerWeighted.test.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ describe('AccountMultiSignerWeighted', function () {
158158
await expect(this.mock.signerWeight(signer3)).to.eventually.equal(3); // unchanged
159159
});
160160

161+
it("no-op doesn't emit an event", async function () {
162+
await expect(this.mock.$_setSignerWeights([signer1], [1])).to.not.emit(this.mock, 'ERC7913SignerWeightChanged');
163+
});
164+
161165
it('cannot set weight to non-existent signer', async function () {
162166
// Reverts when setting weight for non-existent signer
163167
await expect(this.mock.$_setSignerWeights([signer4], [1]))
@@ -186,28 +190,28 @@ describe('AccountMultiSignerWeighted', function () {
186190
});
187191

188192
it('validates threshold is reachable when updating weights', async function () {
189-
// First, lower the weights so the sum is exactly 6 (just enough for threshold=6)
190-
await expect(this.mock.$_setSignerWeights([signer1, signer2, signer3], [1, 2, 3]))
193+
// First, lower the weights so the sum is exactly 9 (just enough for threshold=9)
194+
await expect(this.mock.$_setSignerWeights([signer1, signer2, signer3], [2, 3, 4]))
191195
.to.emit(this.mock, 'ERC7913SignerWeightChanged')
192-
.withArgs(signer1, 1)
196+
.withArgs(signer1, 2)
193197
.to.emit(this.mock, 'ERC7913SignerWeightChanged')
194-
.withArgs(signer2, 2)
198+
.withArgs(signer2, 3)
195199
.to.emit(this.mock, 'ERC7913SignerWeightChanged')
196-
.withArgs(signer3, 3);
200+
.withArgs(signer3, 4);
197201

198-
// Increase threshold to 6
199-
await expect(this.mock.$_setThreshold(6)).to.emit(this.mock, 'ERC7913ThresholdSet').withArgs(6);
202+
// Increase threshold to 9
203+
await expect(this.mock.$_setThreshold(9)).to.emit(this.mock, 'ERC7913ThresholdSet').withArgs(9);
200204

201205
// Now try to lower weights so their sum is less than the threshold
202-
await expect(this.mock.$_setSignerWeights([signer1, signer2, signer3], [1, 1, 1])).to.be.revertedWithCustomError(
206+
await expect(this.mock.$_setSignerWeights([signer1, signer2, signer3], [2, 2, 2])).to.be.revertedWithCustomError(
203207
this.mock,
204208
'MultiSignerERC7913UnreachableThreshold',
205209
);
206210

207211
// Try to increase threshold to be larger than the total weight
208-
await expect(this.mock.$_setThreshold(7))
212+
await expect(this.mock.$_setThreshold(10))
209213
.to.be.revertedWithCustomError(this.mock, 'MultiSignerERC7913UnreachableThreshold')
210-
.withArgs(6, 7);
214+
.withArgs(9, 10);
211215
});
212216

213217
it('reports default weight of 1 for signers without explicit weight', async function () {

0 commit comments

Comments
 (0)