Skip to content

Commit 35c6764

Browse files
committed
upgrade openzeppelin-contracts
1 parent ec65bf0 commit 35c6764

File tree

44 files changed

+83
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+83
-106
lines changed

foundry.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ evm_version = "cancun"
88

99
ignored_error_codes = [
1010
"license", # warning[1878]: Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
11-
3628, # Warning (3628): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
12-
3860, # Warning (3860): Contract initcode size is X bytes and exceeds Y bytes (a limit introduced in Shanghai). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
13-
5159, # Warning (5159): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.
14-
5574, # Warning (5574): Contract code size is 24870 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
15-
9302, # Warning (9302): Return value of low-level calls not used.
11+
2394, # Warning (2394): Transient storage as defined by EIP-1153 can break the composability of smart contracts: Since transient storage is cleared only at the end of the transaction and not at the end of the outermost call frame to the contract within a transaction, your contract may unintentionally misbehave when invoked multiple times in a complex transaction. To avoid this, be sure to clear all transient storage at the end of any call to your contract. The use of transient storage for reentrancy guards that are cleared at the end of the call is safe.
12+
3628, # Warning (3628): This contract has a payable fallback function, but no receive ether function. Consider adding a receive ether function.
13+
3860, # Warning (3860): Contract initcode size is X bytes and exceeds Y bytes (a limit introduced in Shanghai). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
14+
5159, # Warning (5159): "selfdestruct" has been deprecated. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.
15+
5574, # Warning (5574): Contract code size is 24870 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
16+
9302, # Warning (9302): Return value of low-level calls not used.
1617
]
1718

1819
# For Huff

lib/openzeppelin-contracts

src/0CTF2022/TctfNftMarket/CalldataBug.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity 0.8.15;
33

4-
import "forge-std/Test.sol";
4+
import {Test} from "forge-std/Test.sol";
55

66
struct A {
77
B b;

src/0x41414141CTF/RichClub/Exploit.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.16;
2+
pragma solidity ^0.8.16;
33

44
import "forge-std/Script.sol";
55
import "src/utils/UniswapV2Library.sol";

src/BalsnCTF2022/NFTMarketplace/Exploit.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.9;
2+
pragma solidity ^0.8.9;
33

44
import {NFTMarketplace} from "./challenge/NFTMarketplace.sol";
55
import {Create2} from "src/utils/Create2.sol";

src/BalsnCTF2022/NFTMarketplace/Exploit.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.9;
2+
pragma solidity ^0.8.9;
33

44
import "forge-std/Test.sol";
55
import {NFTMarketplace} from "./challenge/NFTMarketplace.sol";

src/BalsnCTF2022/NFTMarketplace/challenge/NFTMarketplace.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.9;
2+
pragma solidity ^0.8.9;
33

44
import "openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
55
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

src/Curta/20_Lana/Exploit.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: UNLICENSED
2-
pragma solidity 0.8.13;
2+
pragma solidity ^0.8.13;
33

44
import {Test, console2} from "forge-std/Test.sol";
55
import {Curta} from "../general/CurtaLocal.sol";

src/DeFiSecuritySummitStanford/tokens/tokenERC223.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ contract SimpleERC223Token is ERC20 {
99
_mint(msg.sender, _supply);
1010
}
1111

12-
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual override {
12+
function _update(address from, address to, uint256 amount) internal virtual override {
1313
// Call parent hook
14-
super._afterTokenTransfer(from, to, amount);
15-
if (Address.isContract(to)) {
14+
super._update(from, to, amount);
15+
if (to.code.length > 0) {
1616
// this is wrong and broken on many ways, but it works for this example
1717
// instead of a try catch perhaps we should use a ERC165...
1818
// the tokenFallback function is run if the contract has this function

src/DownUnderCTF2022/CryptoCasino/Casino.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract Casino is Ownable {
1212
uint256 lastPlayed = 0;
1313
mapping(address => uint256) public balances;
1414

15-
constructor(address token) {
15+
constructor(address token) Ownable(msg.sender) {
1616
ducoin = DUCoin(token);
1717
}
1818

src/DownUnderCTF2022/CryptoCasino/DUCoin.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
77
import "openzeppelin-contracts/contracts/access/Ownable.sol";
88

99
contract DUCoin is ERC20, Ownable {
10-
constructor() ERC20("DUCoin", "DUC") {}
10+
constructor() ERC20("DUCoin", "DUC") Ownable(msg.sender) {}
1111

1212
function freeMoney(address addr) external onlyOwner {
1313
_mint(addr, 1337);

src/Ethernaut/Denial/Denial.sol

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.13;
33

4-
import "openzeppelin/utils/math/SafeMath.sol";
5-
64
contract Denial {
7-
using SafeMath for uint256;
8-
95
address public partner; // withdrawal partner - pay the gas, split the withdraw
106
address payable public constant owner = payable(address(0xA9E));
117
uint256 timeLastWithdrawn;
@@ -17,15 +13,15 @@ contract Denial {
1713

1814
// withdraw 1% to recipient and 1% to owner
1915
function withdraw() public {
20-
uint256 amountToSend = address(this).balance.div(100);
16+
uint256 amountToSend = address(this).balance / 100;
2117
// perform a call without checking return
2218
// The recipient can revert, the owner will still get their share
2319
(bool _result,) = partner.call{value: amountToSend}("");
2420
_result;
2521
owner.transfer(amountToSend);
2622
// keep track of last withdrawal time
2723
timeLastWithdrawn = block.timestamp;
28-
withdrawPartnerBalances[partner] = withdrawPartnerBalances[partner].add(amountToSend);
24+
withdrawPartnerBalances[partner] = withdrawPartnerBalances[partner] + amountToSend;
2925
}
3026

3127
// allow deposit of funds

src/Ethernaut/Dex/Dex.sol

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ pragma solidity ^0.8.13;
33

44
import "openzeppelin/token/ERC20/IERC20.sol";
55
import "openzeppelin/token/ERC20/ERC20.sol";
6-
import "openzeppelin/utils/math/SafeMath.sol";
76
import "openzeppelin/access/Ownable.sol";
87

98
contract Dex is Ownable {
10-
using SafeMath for uint256;
11-
129
address public token1;
1310
address public token2;
1411

15-
constructor() {}
12+
constructor() Ownable(msg.sender) {}
1613

1714
function setTokens(address _token1, address _token2) public onlyOwner {
1815
token1 = _token1;

src/Ethernaut/DexTwo/DexTwo.sol

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ pragma solidity ^0.8.13;
33

44
import "openzeppelin/token/ERC20/IERC20.sol";
55
import "openzeppelin/token/ERC20/ERC20.sol";
6-
import "openzeppelin/utils/math/SafeMath.sol";
76
import "openzeppelin/access/Ownable.sol";
87

98
contract DexTwo is Ownable {
10-
using SafeMath for uint256;
11-
129
address public token1;
1310
address public token2;
1411

15-
constructor() {}
12+
constructor() Ownable(msg.sender) {}
1613

1714
function setTokens(address _token1, address _token2) public onlyOwner {
1815
token1 = _token1;

src/Ethernaut/DoubleEntryPoint/DoubleEntryPoint.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ contract CryptoVault {
7272
contract LegacyToken is ERC20("LegacyToken", "LGT"), Ownable {
7373
DelegateERC20 public delegate;
7474

75+
constructor() Ownable(msg.sender) {}
76+
7577
function mint(address to, uint256 amount) public onlyOwner {
7678
_mint(to, amount);
7779
}
@@ -95,7 +97,9 @@ contract DoubleEntryPoint is ERC20("DoubleEntryPointToken", "DET"), DelegateERC2
9597
address public delegatedFrom;
9698
Forta public forta;
9799

98-
constructor(address legacyToken, address vaultAddress, address fortaAddress, address playerAddress) {
100+
constructor(address legacyToken, address vaultAddress, address fortaAddress, address playerAddress)
101+
Ownable(msg.sender)
102+
{
99103
delegatedFrom = legacyToken;
100104
forta = Forta(fortaAddress);
101105
player = playerAddress;

src/Ethernaut/Ethernaut/Ethernaut.sol

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "openzeppelin/access/Ownable.sol";
99
address constant ETHERNAUT_ADDRESS = 0xD991431D8b033ddCb84dAD257f4821E9d5b38C33;
1010

1111
contract Ethernaut is Ownable {
12+
constructor() Ownable(msg.sender) {}
1213
// ----------------------------------
1314
// Owner interaction
1415
// ----------------------------------

src/Ethernaut/Ethernaut/Level.sol

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.13;
55
import "openzeppelin/access/Ownable.sol";
66

77
abstract contract Level is Ownable {
8+
constructor() Ownable(msg.sender) {}
89
function createInstance(address _player) public payable virtual returns (address);
910

1011
function validateInstance(address payable _instance, address _player) public virtual returns (bool);

src/Ethernaut/Fallout/Fallout.sol

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.13;
33

4-
import "openzeppelin/utils/math/SafeMath.sol";
5-
64
contract Fallout {
7-
using SafeMath for uint256;
8-
95
mapping(address => uint256) allocations;
106
address payable public owner;
117

@@ -21,7 +17,7 @@ contract Fallout {
2117
}
2218

2319
function allocate() public payable {
24-
allocations[msg.sender] = allocations[msg.sender].add(msg.value);
20+
allocations[msg.sender] = allocations[msg.sender] + msg.value;
2521
}
2622

2723
function sendAllocation(address payable allocator) public {

src/Ethernaut/GoodSamaritan/GoodSamaritan.sol

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity >=0.8.0 <0.9.0;
33

4-
import "openzeppelin-contracts/contracts/utils/Address.sol";
5-
64
contract GoodSamaritan {
75
Wallet public wallet;
86
Coin public coin;
@@ -29,8 +27,6 @@ contract GoodSamaritan {
2927
}
3028

3129
contract Coin {
32-
using Address for address;
33-
3430
mapping(address => uint256) public balances;
3531

3632
error InsufficientBalance(uint256 current, uint256 required);
@@ -48,7 +44,7 @@ contract Coin {
4844
balances[msg.sender] -= amount_;
4945
balances[dest_] += amount_;
5046

51-
if (dest_.isContract()) {
47+
if (dest_.code.length > 0) {
5248
// notify contract
5349
INotifyable(dest_).notify(amount_);
5450
}

src/Ethernaut/Motorbike/Motorbike.sol

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
pragma solidity ^0.8.13;
44

5-
import "openzeppelin/utils/Address.sol";
65
import "openzeppelin/proxy/utils/Initializable.sol";
76

87
contract Motorbike {
@@ -15,7 +14,7 @@ contract Motorbike {
1514

1615
// Initializes the upgradeable proxy with an initial implementation specified by `_logic`.
1716
constructor(address _logic) {
18-
require(Address.isContract(_logic), "ERC1967: new implementation is not a contract");
17+
require(_logic.code.length > 0, "ERC1967: new implementation is not a contract");
1918
_getAddressSlot(_IMPLEMENTATION_SLOT).value = _logic;
2019
(bool success,) = _logic.delegatecall(abi.encodeWithSignature("initialize()"));
2120
require(success, "Call failed");
@@ -88,7 +87,7 @@ contract Engine is Initializable {
8887

8988
// Stores a new address in the EIP1967 implementation slot.
9089
function _setImplementation(address newImplementation) private {
91-
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
90+
require(newImplementation.code.length > 0, "ERC1967: new implementation is not a contract");
9291

9392
AddressSlot storage r;
9493
assembly {

src/Ethernaut/Motorbike/MotorbikeFactory.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ contract MotorbikeFactory is Level {
3333

3434
function validateInstance(address payable _instance, address _player) public view override returns (bool) {
3535
_player;
36-
return !Address.isContract(engines[_instance]);
36+
return !(engines[_instance].code.length > 0);
3737
}
3838
}

src/Ethernaut/PuzzleWallet/PuzzleWallet.sol

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.13;
33

4-
import "openzeppelin/utils/math/SafeMath.sol";
5-
import "openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
4+
import {ERC1967Proxy, ERC1967Utils} from "openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
65

76
contract PuzzleProxy is ERC1967Proxy {
87
address public pendingAdmin;
@@ -29,13 +28,11 @@ contract PuzzleProxy is ERC1967Proxy {
2928
}
3029

3130
function upgradeTo(address _newImplementation) external onlyAdmin {
32-
_upgradeTo(_newImplementation);
31+
ERC1967Utils.upgradeToAndCall(_newImplementation, "");
3332
}
3433
}
3534

3635
contract PuzzleWallet {
37-
using SafeMath for uint256;
38-
3936
address public owner;
4037
uint256 public maxBalance;
4138
mapping(address => bool) public whitelisted;
@@ -64,12 +61,12 @@ contract PuzzleWallet {
6461

6562
function deposit() external payable onlyWhitelisted {
6663
require(address(this).balance <= maxBalance, "Max balance reached");
67-
balances[msg.sender] = balances[msg.sender].add(msg.value);
64+
balances[msg.sender] = balances[msg.sender] + msg.value;
6865
}
6966

7067
function execute(address to, uint256 value, bytes calldata data) external payable onlyWhitelisted {
7168
require(balances[msg.sender] >= value, "Insufficient balance");
72-
balances[msg.sender] = balances[msg.sender].sub(value);
69+
balances[msg.sender] = balances[msg.sender] - value;
7370
(bool success,) = to.call{value: value}(data);
7471
require(success, "Execution failed");
7572
}

src/Ethernaut/Recovery/Recovery.sol

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.13;
33

4-
import "openzeppelin/utils/math/SafeMath.sol";
5-
64
contract Recovery {
75
//generate tokens
86
function generateToken(string memory _name, uint256 _initialSupply) public {
@@ -11,8 +9,6 @@ contract Recovery {
119
}
1210

1311
contract SimpleToken {
14-
using SafeMath for uint256;
15-
1612
// public variables
1713
string public name;
1814
mapping(address => uint256) public balances;
@@ -25,13 +21,13 @@ contract SimpleToken {
2521

2622
// collect ether in return for tokens
2723
receive() external payable {
28-
balances[msg.sender] = msg.value.mul(10);
24+
balances[msg.sender] = msg.value * 10;
2925
}
3026

3127
// allow transfers of tokens
3228
function transfer(address _to, uint256 _amount) public {
3329
require(balances[msg.sender] >= _amount);
34-
balances[msg.sender] = balances[msg.sender].sub(_amount);
30+
balances[msg.sender] = balances[msg.sender] - _amount;
3531
balances[_to] = _amount;
3632
}
3733

src/Ethernaut/Reentrance/Reentrance.sol

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.13;
33

4-
import "openzeppelin/utils/math/SafeMath.sol";
5-
64
contract Reentrance {
7-
using SafeMath for uint256;
8-
95
mapping(address => uint256) public balances;
106

117
function donate(address _to) public payable {
12-
balances[_to] = balances[_to].add(msg.value);
8+
balances[_to] = balances[_to] + msg.value;
139
}
1410

1511
function balanceOf(address _who) public view returns (uint256 balance) {

src/EthernautDAO/CarMarket/CarMarket.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract CarMarket is Ownable {
3535
* @notice Sets the car token during deployment.
3636
* @param _carToken The token used to purchase cars
3737
*/
38-
constructor(address _carToken) {
38+
constructor(address _carToken) Ownable(msg.sender) {
3939
carToken = ICarToken(_carToken);
4040
}
4141

src/EthernautDAO/CarMarket/CarToken.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ contract CarToken is ERC20, Ownable {
2121
/**
2222
* @dev Car Company Contract Constructor.
2323
*/
24-
constructor() ERC20("Car Company", "CCY") {}
24+
constructor() ERC20("Car Company", "CCY") Ownable(msg.sender) {}
2525

2626
/**
2727
* @dev Checks to see if the user has minted previously.

0 commit comments

Comments
 (0)