Skip to content

Commit 77a459e

Browse files
Amxxfrangiodangerousfoodarr00RenanSouza2
authored
Release v5.3 cherrypick #1 (#5509)
Signed-off-by: Hadrien Croubois <[email protected]> Co-authored-by: Francisco Giordano <[email protected]> Co-authored-by: Joseph Delong <[email protected]> Co-authored-by: Arr00 <[email protected]> Co-authored-by: Renan Souza <[email protected]>
1 parent 9671043 commit 77a459e

File tree

7 files changed

+51
-18
lines changed

7 files changed

+51
-18
lines changed

.changeset/gorgeous-apes-jam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': minor
3+
---
4+
5+
`TimelockController`: Receive function is now virtual.

contracts/access/manager/AuthorityUtils.sol

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ library AuthorityUtils {
1717
address target,
1818
bytes4 selector
1919
) internal view returns (bool immediate, uint32 delay) {
20-
(bool success, bytes memory data) = authority.staticcall(
21-
abi.encodeCall(IAuthority.canCall, (caller, target, selector))
22-
);
23-
if (success) {
24-
if (data.length >= 0x40) {
25-
(immediate, delay) = abi.decode(data, (bool, uint32));
26-
} else if (data.length >= 0x20) {
27-
immediate = abi.decode(data, (bool));
20+
bytes memory data = abi.encodeCall(IAuthority.canCall, (caller, target, selector));
21+
22+
assembly ("memory-safe") {
23+
mstore(0x00, 0x00)
24+
mstore(0x20, 0x00)
25+
26+
if staticcall(gas(), authority, add(data, 0x20), mload(data), 0x00, 0x40) {
27+
immediate := mload(0x00)
28+
delay := mload(0x20)
2829
}
2930
}
30-
return (immediate, delay);
3131
}
3232
}

contracts/governance/TimelockController.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
152152
/**
153153
* @dev Contract might receive/hold ETH as part of the maintenance process.
154154
*/
155-
receive() external payable {}
155+
receive() external payable virtual {}
156156

157157
/**
158158
* @dev See {IERC165-supportsInterface}.

hardhat.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ module.exports = {
9090
'initcode-size': 'off',
9191
},
9292
'*': {
93-
'code-size': true,
9493
'unused-param': !argv.coverage, // coverage causes unused-param warnings
9594
'transient-storage': false,
9695
default: 'error',

test/helpers/precompiles.js

+12
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

+21-7
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
}

test/utils/math/Math.t.sol

+3
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ contract MathTest is Test {
204204
assertEq(xyLo, qdRemLo);
205205
}
206206

207+
/// forge-config: default.allow_internal_expect_revert = true
207208
function testMulDivDomain(uint256 x, uint256 y, uint256 d) public {
208209
(uint256 xyHi, ) = _mulHighLow(x, y);
209210

@@ -216,6 +217,7 @@ contract MathTest is Test {
216217
}
217218

218219
// MOD EXP
220+
/// forge-config: default.allow_internal_expect_revert = true
219221
function testModExp(uint256 b, uint256 e, uint256 m) public {
220222
if (m == 0) {
221223
vm.expectRevert(stdError.divisionError);
@@ -236,6 +238,7 @@ contract MathTest is Test {
236238
}
237239
}
238240

241+
/// forge-config: default.allow_internal_expect_revert = true
239242
function testModExpMemory(uint256 b, uint256 e, uint256 m) public {
240243
if (m == 0) {
241244
vm.expectRevert(stdError.divisionError);

0 commit comments

Comments
 (0)