Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gorgeous-apes-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`TimelockController`: Receive function is now virtual.
18 changes: 9 additions & 9 deletions contracts/access/manager/AuthorityUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ library AuthorityUtils {
address target,
bytes4 selector
) internal view returns (bool immediate, uint32 delay) {
(bool success, bytes memory data) = authority.staticcall(
abi.encodeCall(IAuthority.canCall, (caller, target, selector))
);
if (success) {
if (data.length >= 0x40) {
(immediate, delay) = abi.decode(data, (bool, uint32));
} else if (data.length >= 0x20) {
immediate = abi.decode(data, (bool));
bytes memory data = abi.encodeCall(IAuthority.canCall, (caller, target, selector));

assembly ("memory-safe") {
mstore(0x00, 0x00)
mstore(0x20, 0x00)

if staticcall(gas(), authority, add(data, 0x20), mload(data), 0x00, 0x40) {
immediate := mload(0x00)
delay := mload(0x20)
}
}
return (immediate, delay);
}
}
2 changes: 1 addition & 1 deletion contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
1 change: 0 additions & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions test/helpers/precompiles.js
Original file line number Diff line number Diff line change
@@ -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',
};
28 changes: 21 additions & 7 deletions test/utils/cryptography/SignatureChecker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -25,35 +27,47 @@ 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;
});
});

describe('ERC1271 wallet', 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;
});
});
}
Expand Down
3 changes: 3 additions & 0 deletions test/utils/math/Math.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ contract MathTest is Test {
assertEq(xyLo, qdRemLo);
}

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

Expand All @@ -216,6 +217,7 @@ contract MathTest is Test {
}

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

/// forge-config: default.allow_internal_expect_revert = true
function testModExpMemory(uint256 b, uint256 e, uint256 m) public {
if (m == 0) {
vm.expectRevert(stdError.divisionError);
Expand Down
Loading