From dbd980520790cfc5b950f106a8543d3b84f6fe70 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 13 Feb 2025 16:21:24 +0100 Subject: [PATCH 1/3] Test behavior of SignatureChecker against the identity precompile (0x4) (#5501) --- test/helpers/precompiles.js | 12 ++++++++ .../cryptography/SignatureChecker.test.js | 28 ++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 test/helpers/precompiles.js diff --git a/test/helpers/precompiles.js b/test/helpers/precompiles.js new file mode 100644 index 000000000..fb6b7132a --- /dev/null +++ b/test/helpers/precompiles.js @@ -0,0 +1,12 @@ +module.exports = { + ecRecover: '0x0000000000000000000000000000000000000001', + SHA2_256: '0x0000000000000000000000000000000000000002', + RIPEMD_160: '0x0000000000000000000000000000000000000003', + identity: '0x0000000000000000000000000000000000000004', + modexp: '0x0000000000000000000000000000000000000005', + ecAdd: '0x0000000000000000000000000000000000000006', + ecMul: '0x0000000000000000000000000000000000000007', + ecPairing: '0x0000000000000000000000000000000000000008', + blake2f: '0x0000000000000000000000000000000000000009', + pointEvaluation: '0x000000000000000000000000000000000000000a', +}; diff --git a/test/utils/cryptography/SignatureChecker.test.js b/test/utils/cryptography/SignatureChecker.test.js index e6a08491a..2b14f2f4c 100644 --- a/test/utils/cryptography/SignatureChecker.test.js +++ b/test/utils/cryptography/SignatureChecker.test.js @@ -2,6 +2,8 @@ const { ethers } = require('hardhat'); const { expect } = require('chai'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); +const precompile = require('../../helpers/precompiles'); + const TEST_MESSAGE = ethers.id('OpenZeppelin'); const TEST_MESSAGE_HASH = ethers.hashMessage(TEST_MESSAGE); @@ -25,15 +27,18 @@ describe('SignatureChecker (ERC1271)', function () { describe('EOA account', function () { it('with matching signer and signature', async function () { - expect(await this.mock.$isValidSignatureNow(this.signer, TEST_MESSAGE_HASH, this.signature)).to.be.true; + await expect(this.mock.$isValidSignatureNow(this.signer, TEST_MESSAGE_HASH, this.signature)).to.eventually.be + .true; }); it('with invalid signer', async function () { - expect(await this.mock.$isValidSignatureNow(this.other, TEST_MESSAGE_HASH, this.signature)).to.be.false; + await expect(this.mock.$isValidSignatureNow(this.other, TEST_MESSAGE_HASH, this.signature)).to.eventually.be + .false; }); it('with invalid signature', async function () { - expect(await this.mock.$isValidSignatureNow(this.signer, WRONG_MESSAGE_HASH, this.signature)).to.be.false; + await expect(this.mock.$isValidSignatureNow(this.signer, WRONG_MESSAGE_HASH, this.signature)).to.eventually.be + .false; }); }); @@ -41,19 +46,28 @@ describe('SignatureChecker (ERC1271)', function () { for (const fn of ['isValidERC1271SignatureNow', 'isValidSignatureNow']) { describe(fn, function () { it('with matching signer and signature', async function () { - expect(await this.mock.getFunction(`$${fn}`)(this.wallet, TEST_MESSAGE_HASH, this.signature)).to.be.true; + await expect(this.mock.getFunction(`$${fn}`)(this.wallet, TEST_MESSAGE_HASH, this.signature)).to.eventually.be + .true; }); it('with invalid signer', async function () { - expect(await this.mock.getFunction(`$${fn}`)(this.mock, TEST_MESSAGE_HASH, this.signature)).to.be.false; + await expect(this.mock.getFunction(`$${fn}`)(this.mock, TEST_MESSAGE_HASH, this.signature)).to.eventually.be + .false; + }); + + it('with identity precompile', async function () { + await expect(this.mock.getFunction(`$${fn}`)(precompile.identity, TEST_MESSAGE_HASH, this.signature)).to + .eventually.be.false; }); it('with invalid signature', async function () { - expect(await this.mock.getFunction(`$${fn}`)(this.wallet, WRONG_MESSAGE_HASH, this.signature)).to.be.false; + await expect(this.mock.getFunction(`$${fn}`)(this.wallet, WRONG_MESSAGE_HASH, this.signature)).to.eventually + .be.false; }); it('with malicious wallet', async function () { - expect(await this.mock.getFunction(`$${fn}`)(this.malicious, TEST_MESSAGE_HASH, this.signature)).to.be.false; + await expect(this.mock.getFunction(`$${fn}`)(this.malicious, TEST_MESSAGE_HASH, this.signature)).to.eventually + .be.false; }); }); } From fa8bed68af414836b157d16d077f8cc1e8f2ea26 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 13 Feb 2025 14:16:21 -0300 Subject: [PATCH 2/3] Treat code-size warnings as errors (#5101) Co-authored-by: Hadrien Croubois --- hardhat.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/hardhat.config.js b/hardhat.config.js index d39d3d073..b4b8d630f 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -90,7 +90,6 @@ module.exports = { 'initcode-size': 'off', }, '*': { - 'code-size': true, 'unused-param': !argv.coverage, // coverage causes unused-param warnings 'transient-storage': false, default: 'error', From f281e98c94cf668d13e6d064d3d0b9c173fb8014 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Fri, 14 Feb 2025 02:28:26 -0600 Subject: [PATCH 3/3] Make `TimelockController` receive function virtual (#5506) Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com> Co-authored-by: Hadrien Croubois --- .changeset/gorgeous-apes-jam.md | 5 +++++ contracts/governance/TimelockController.sol | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/gorgeous-apes-jam.md diff --git a/.changeset/gorgeous-apes-jam.md b/.changeset/gorgeous-apes-jam.md new file mode 100644 index 000000000..14ca3522e --- /dev/null +++ b/.changeset/gorgeous-apes-jam.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': minor +--- + +`TimelockController`: Receive function is now virtual. diff --git a/contracts/governance/TimelockController.sol b/contracts/governance/TimelockController.sol index 349d940fd..d2ba17016 100644 --- a/contracts/governance/TimelockController.sol +++ b/contracts/governance/TimelockController.sol @@ -152,7 +152,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder { /** * @dev Contract might receive/hold ETH as part of the maintenance process. */ - receive() external payable {} + receive() external payable virtual {} /** * @dev See {IERC165-supportsInterface}.