Skip to content

Commit dbd9805

Browse files
authored
Test behavior of SignatureChecker against the identity precompile (0x4) (#5501)
1 parent 7ccb79f commit dbd9805

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

test/helpers/precompiles.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
ecRecover: '0x0000000000000000000000000000000000000001',
3+
SHA2_256: '0x0000000000000000000000000000000000000002',
4+
RIPEMD_160: '0x0000000000000000000000000000000000000003',
5+
identity: '0x0000000000000000000000000000000000000004',
6+
modexp: '0x0000000000000000000000000000000000000005',
7+
ecAdd: '0x0000000000000000000000000000000000000006',
8+
ecMul: '0x0000000000000000000000000000000000000007',
9+
ecPairing: '0x0000000000000000000000000000000000000008',
10+
blake2f: '0x0000000000000000000000000000000000000009',
11+
pointEvaluation: '0x000000000000000000000000000000000000000a',
12+
};

test/utils/cryptography/SignatureChecker.test.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

5+
const precompile = require('../../helpers/precompiles');
6+
57
const TEST_MESSAGE = ethers.id('OpenZeppelin');
68
const TEST_MESSAGE_HASH = ethers.hashMessage(TEST_MESSAGE);
79

@@ -25,35 +27,47 @@ describe('SignatureChecker (ERC1271)', function () {
2527

2628
describe('EOA account', function () {
2729
it('with matching signer and signature', async function () {
28-
expect(await this.mock.$isValidSignatureNow(this.signer, TEST_MESSAGE_HASH, this.signature)).to.be.true;
30+
await expect(this.mock.$isValidSignatureNow(this.signer, TEST_MESSAGE_HASH, this.signature)).to.eventually.be
31+
.true;
2932
});
3033

3134
it('with invalid signer', async function () {
32-
expect(await this.mock.$isValidSignatureNow(this.other, TEST_MESSAGE_HASH, this.signature)).to.be.false;
35+
await expect(this.mock.$isValidSignatureNow(this.other, TEST_MESSAGE_HASH, this.signature)).to.eventually.be
36+
.false;
3337
});
3438

3539
it('with invalid signature', async function () {
36-
expect(await this.mock.$isValidSignatureNow(this.signer, WRONG_MESSAGE_HASH, this.signature)).to.be.false;
40+
await expect(this.mock.$isValidSignatureNow(this.signer, WRONG_MESSAGE_HASH, this.signature)).to.eventually.be
41+
.false;
3742
});
3843
});
3944

4045
describe('ERC1271 wallet', function () {
4146
for (const fn of ['isValidERC1271SignatureNow', 'isValidSignatureNow']) {
4247
describe(fn, function () {
4348
it('with matching signer and signature', async function () {
44-
expect(await this.mock.getFunction(`$${fn}`)(this.wallet, TEST_MESSAGE_HASH, this.signature)).to.be.true;
49+
await expect(this.mock.getFunction(`$${fn}`)(this.wallet, TEST_MESSAGE_HASH, this.signature)).to.eventually.be
50+
.true;
4551
});
4652

4753
it('with invalid signer', async function () {
48-
expect(await this.mock.getFunction(`$${fn}`)(this.mock, TEST_MESSAGE_HASH, this.signature)).to.be.false;
54+
await expect(this.mock.getFunction(`$${fn}`)(this.mock, TEST_MESSAGE_HASH, this.signature)).to.eventually.be
55+
.false;
56+
});
57+
58+
it('with identity precompile', async function () {
59+
await expect(this.mock.getFunction(`$${fn}`)(precompile.identity, TEST_MESSAGE_HASH, this.signature)).to
60+
.eventually.be.false;
4961
});
5062

5163
it('with invalid signature', async function () {
52-
expect(await this.mock.getFunction(`$${fn}`)(this.wallet, WRONG_MESSAGE_HASH, this.signature)).to.be.false;
64+
await expect(this.mock.getFunction(`$${fn}`)(this.wallet, WRONG_MESSAGE_HASH, this.signature)).to.eventually
65+
.be.false;
5366
});
5467

5568
it('with malicious wallet', async function () {
56-
expect(await this.mock.getFunction(`$${fn}`)(this.malicious, TEST_MESSAGE_HASH, this.signature)).to.be.false;
69+
await expect(this.mock.getFunction(`$${fn}`)(this.malicious, TEST_MESSAGE_HASH, this.signature)).to.eventually
70+
.be.false;
5771
});
5872
});
5973
}

0 commit comments

Comments
 (0)