Skip to content

Commit 78eb160

Browse files
KitHatAmxx
andauthored
Fix "non-canonical s" check with [email protected] (#5978)
Signed-off-by: Nikita Khateev <[email protected]> Co-authored-by: Hadrien Croubois <[email protected]>
1 parent d9f966f commit 78eb160

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/utils/cryptography/ECDSA.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
4+
const { secp256k1 } = require('@noble/curves/secp256k1');
45

56
const TEST_MESSAGE = ethers.id('OpenZeppelin');
67
const WRONG_MESSAGE = ethers.id('Nope');
@@ -242,6 +243,10 @@ describe('ECDSA', function () {
242243
const s = ethers.dataSlice(highSSignature, 32, 64);
243244
const v = ethers.dataSlice(highSSignature, 64, 65);
244245

246+
// In ethers v6.15.0+, the library no longer throws 'non-canonical s' error for high-s signatures. This
247+
// assertion verifies we are in fact dealing with a high-s value that the ECDSA library should reject.
248+
expect(ethers.toBigInt(s)).to.be.gt(secp256k1.CURVE.n / 2n);
249+
245250
await expect(this.mock.$recover(message, highSSignature))
246251
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureS')
247252
.withArgs(s);
@@ -251,7 +256,6 @@ describe('ECDSA', function () {
251256
await expect(this.mock.getFunction('$recover(bytes32,uint8,bytes32,bytes32)')(TEST_MESSAGE, v, r, s))
252257
.to.be.revertedWithCustomError(this.mock, 'ECDSAInvalidSignatureS')
253258
.withArgs(s);
254-
expect(() => ethers.Signature.from(highSSignature)).to.throw('non-canonical s');
255259
});
256260
});
257261

0 commit comments

Comments
 (0)