Skip to content

Commit 12ad9ea

Browse files
Transpile dc57a7e
1 parent 5843c07 commit 12ad9ea

File tree

12 files changed

+83
-13
lines changed

12 files changed

+83
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog
22

3-
## 4.7.2
3+
## 4.7.2 (2022-07-27)
44

55
* `LibArbitrumL2`, `CrossChainEnabledArbitrumL2`: Fixed detection of cross-chain calls for EOAs. Previously, calls from EOAs would be classified as cross-chain calls. ([#3578](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3578))
6+
* `GovernorVotesQuorumFraction`: Fixed quorum updates so they do not affect past proposals that failed due to lack of quorum. ([#3561](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3561))
7+
* `ERC165Checker`: Added protection against large returndata. ([#3587](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3587))
68

79
## 4.7.1 (2022-07-19)
810

contracts/crosschain/arbitrum/LibArbitrumL2Upgradeable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.7.0) (crosschain/arbitrum/LibArbitrumL2.sol)
2+
// OpenZeppelin Contracts (last updated v4.7.2) (crosschain/arbitrum/LibArbitrumL2.sol)
33

44
pragma solidity ^0.8.4;
55

contracts/governance/GovernorUpgradeable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.7.0) (governance/Governor.sol)
2+
// OpenZeppelin Contracts (last updated v4.7.2) (governance/Governor.sol)
33

44
pragma solidity ^0.8.0;
55

contracts/governance/IGovernorUpgradeable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.7.0) (governance/IGovernor.sol)
2+
// OpenZeppelin Contracts (last updated v4.7.2) (governance/IGovernor.sol)
33

44
pragma solidity ^0.8.0;
55

contracts/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.5.0) (governance/extensions/GovernorVotesQuorumFraction.sol)
2+
// OpenZeppelin Contracts (last updated v4.7.2) (governance/extensions/GovernorVotesQuorumFraction.sol)
33

44
pragma solidity ^0.8.0;
55

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "../../utils/introspection/IERC165Upgradeable.sol";
6+
import "../../proxy/utils/Initializable.sol";
7+
8+
contract ERC165ReturnBombMockUpgradeable is Initializable, IERC165Upgradeable {
9+
function __ERC165ReturnBombMock_init() internal onlyInitializing {
10+
}
11+
12+
function __ERC165ReturnBombMock_init_unchained() internal onlyInitializing {
13+
}
14+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
15+
if (interfaceId == type(IERC165Upgradeable).interfaceId) {
16+
assembly {
17+
mstore(0, 1)
18+
}
19+
}
20+
assembly {
21+
return(0, 101500)
22+
}
23+
}
24+
25+
/**
26+
* @dev This empty reserved space is put in place to allow future versions to add new
27+
* variables without shifting down storage in the inheritance chain.
28+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
29+
*/
30+
uint256[50] private __gap;
31+
}

contracts/mocks/WithInit.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ contract ERC165CheckerMockUpgradeableWithInit is ERC165CheckerMockUpgradeable {
341341
__ERC165CheckerMock_init();
342342
}
343343
}
344+
import "./ERC165/ERC165ReturnBombUpgradeable.sol";
345+
346+
contract ERC165ReturnBombMockUpgradeableWithInit is ERC165ReturnBombMockUpgradeable {
347+
constructor() payable initializer {
348+
__ERC165ReturnBombMock_init();
349+
}
350+
}
344351
import "./ERC165/ERC165InterfacesSupportedUpgradeable.sol";
345352

346353
contract SupportsInterfaceWithLookupMockUpgradeableWithInit is SupportsInterfaceWithLookupMockUpgradeable {

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openzeppelin/contracts-upgradeable",
33
"description": "Secure Smart Contract library for Solidity",
4-
"version": "4.7.1",
4+
"version": "4.7.2",
55
"files": [
66
"**/*.sol",
77
"/build/contracts/*.json",

contracts/utils/introspection/ERC165CheckerUpgradeable.sol

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// OpenZeppelin Contracts (last updated v4.7.1) (utils/introspection/ERC165Checker.sol)
2+
// OpenZeppelin Contracts (last updated v4.7.2) (utils/introspection/ERC165Checker.sol)
33

44
pragma solidity ^0.8.0;
55

@@ -105,9 +105,19 @@ library ERC165CheckerUpgradeable {
105105
* Interface identification is specified in ERC-165.
106106
*/
107107
function _supportsERC165Interface(address account, bytes4 interfaceId) private view returns (bool) {
108+
// prepare call
108109
bytes memory encodedParams = abi.encodeWithSelector(IERC165Upgradeable.supportsInterface.selector, interfaceId);
109-
(bool success, bytes memory result) = account.staticcall{gas: 30000}(encodedParams);
110-
if (result.length < 32) return false;
111-
return success && abi.decode(result, (uint256)) > 0;
110+
111+
// perform static call
112+
bool success;
113+
uint256 returnSize;
114+
uint256 returnValue;
115+
assembly {
116+
success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20)
117+
returnSize := returndatasize()
118+
returnValue := mload(0x00)
119+
}
120+
121+
return success && returnSize >= 0x20 && returnValue > 0;
112122
}
113123
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"name": "openzeppelin-solidity",
44
"description": "Secure Smart Contract library for Solidity",
5-
"version": "4.7.1",
5+
"version": "4.7.2",
66
"files": [
77
"/contracts/**/*.sol",
88
"/build/contracts/*.json",

test/utils/introspection/ERC165Checker.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ERC165MissingData = artifacts.require('ERC165MissingData');
77
const ERC165MaliciousData = artifacts.require('ERC165MaliciousData');
88
const ERC165NotSupported = artifacts.require('ERC165NotSupported');
99
const ERC165InterfacesSupported = artifacts.require('ERC165InterfacesSupported');
10+
const ERC165ReturnBombMock = artifacts.require('ERC165ReturnBombMock');
1011

1112
const DUMMY_ID = '0xdeadbeef';
1213
const DUMMY_ID_2 = '0xcafebabe';
@@ -243,4 +244,23 @@ contract('ERC165Checker', function (accounts) {
243244
expect(supported[0]).to.equal(false);
244245
});
245246
});
247+
248+
it('Return bomb resistance', async function () {
249+
this.target = await ERC165ReturnBombMock.new();
250+
251+
const tx1 = await this.mock.supportsInterface.sendTransaction(this.target.address, DUMMY_ID);
252+
expect(tx1.receipt.gasUsed).to.be.lessThan(120000); // 3*30k + 21k + some margin
253+
254+
const tx2 = await this.mock.getSupportedInterfaces.sendTransaction(
255+
this.target.address,
256+
[
257+
DUMMY_ID,
258+
DUMMY_ID_2,
259+
DUMMY_ID_3,
260+
DUMMY_UNSUPPORTED_ID,
261+
DUMMY_UNSUPPORTED_ID_2,
262+
],
263+
);
264+
expect(tx2.receipt.gasUsed).to.be.lessThan(250000); // (2+5)*30k + 21k + some margin
265+
});
246266
});

0 commit comments

Comments
 (0)