From 931970b7b9efa592b82c39d06844b96f94810b7c Mon Sep 17 00:00:00 2001 From: Boris Date: Thu, 5 Dec 2024 23:49:32 +0800 Subject: [PATCH] OPT forge lib to yarn --- .../Damn-Vulnerable-DeFi/01.Unstoppable.sol | 3 +- .../02.Naive-Receiver.sol | 1 - .../CTF/Damn-Vulnerable-DeFi/08.Puppet.sol | 3 +- .../CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol | 6 +-- .../Damn-Vulnerable-DeFi/10.Free-Rider.sol | 2 +- .../CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol | 7 +-- contracts/CTF/Ethernaut/00_Ethernaut.s.sol | 43 ++++++++++++++++++ .../CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol | 2 +- contracts/Hack/20231012-Platypus.sol | 6 +-- foundry.toml | 4 +- foundry/lib/@chainlink/contracts-ccip | 1 - foundry/lib/@dev/forge-std | 1 - foundry/lib/@dev/prb-test | 1 - foundry/lib/@gnosis.pm/safe-contracts | 1 - foundry/lib/@gnosis.pm/safe-contracts-v1.3.0 | 1 - foundry/lib/@openzeppelin/contracts | 1 - .../lib/@openzeppelin/contracts-upgradeable | 1 - .../contracts-upgradeable-v4.7.1 | 1 - foundry/lib/@openzeppelin/contracts-v4.7.1 | 1 - foundry/lib/@openzeppelin/contracts-v4.7.3 | 1 - foundry/lib/@uniswap/v2-core | 1 - foundry/lib/@uniswap/v2-periphery | 1 - foundry/lib/@uniswap/v3-core | 1 - foundry/lib/@uniswap/v3-periphery | 1 - foundry/lib/@uniswap/v4-core | 1 - foundry/lib/@uniswap/v4-periphery | 1 - foundry/lib/aave-v3-core | 1 - foundry/lib/aave-v3-periphery | 1 - foundry/lib/solady | 1 - foundry/lib/solmate | 1 - .../script/CTF/Ethernaut/00_Ethernaut.s.sol | 44 +++++++++++++++++++ .../script/CTF/ONLYPWNER/01.TUTORIAL.s.sol | 6 +-- .../CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol | 4 +- foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol | 4 +- .../CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol | 4 +- .../Damn-Vulnerable-DeFi/01.Unstoppable.t.sol | 2 +- .../02.Naive-Receiver.t.sol | 2 +- .../CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol | 2 +- .../04.Side-Entrance.t.sol | 2 +- .../05.The-Rewarder.t.sol | 7 +-- .../CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol | 2 +- .../Damn-Vulnerable-DeFi/07.Compromised.t.sol | 4 +- .../CTF/Damn-Vulnerable-DeFi/08.Puppet.t.sol | 2 +- .../Damn-Vulnerable-DeFi/10.Free-Rider.t.sol | 7 +-- .../Damn-Vulnerable-DeFi/11.Backdoor.t.sol | 8 ++-- .../CTF/Damn-Vulnerable-DeFi/12.Climber.t.sol | 2 +- .../13.Wallet-Mining.t.sol | 2 +- .../Damn-Vulnerable-DeFi/14.Puppet-V3.t.sol | 2 +- foundry/test/CTF/Ethernaut/01_Fallback.t.sol | 6 +-- foundry/test/CTF/Ethernaut/02_Fallout.t.sol | 4 +- .../CTF/ONLYPWNER/03.REVERSE-RUGPULL.t.sol | 4 +- .../CTF/ONLYPWNER/04.UNDER-THE-FLOW.t.sol | 10 ++--- .../test/CTF/ONLYPWNER/05.WRAPPED-ETHER.t.sol | 2 +- foundry/test/Hack/20231012-Platypus.t.sol | 2 +- package.json | 38 +++++++++++----- remappings.txt | 28 ++++++------ 56 files changed, 187 insertions(+), 110 deletions(-) create mode 100644 contracts/CTF/Ethernaut/00_Ethernaut.s.sol delete mode 160000 foundry/lib/@chainlink/contracts-ccip delete mode 160000 foundry/lib/@dev/forge-std delete mode 160000 foundry/lib/@dev/prb-test delete mode 160000 foundry/lib/@gnosis.pm/safe-contracts delete mode 160000 foundry/lib/@gnosis.pm/safe-contracts-v1.3.0 delete mode 160000 foundry/lib/@openzeppelin/contracts delete mode 160000 foundry/lib/@openzeppelin/contracts-upgradeable delete mode 160000 foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1 delete mode 160000 foundry/lib/@openzeppelin/contracts-v4.7.1 delete mode 160000 foundry/lib/@openzeppelin/contracts-v4.7.3 delete mode 160000 foundry/lib/@uniswap/v2-core delete mode 160000 foundry/lib/@uniswap/v2-periphery delete mode 160000 foundry/lib/@uniswap/v3-core delete mode 160000 foundry/lib/@uniswap/v3-periphery delete mode 160000 foundry/lib/@uniswap/v4-core delete mode 160000 foundry/lib/@uniswap/v4-periphery delete mode 160000 foundry/lib/aave-v3-core delete mode 160000 foundry/lib/aave-v3-periphery delete mode 160000 foundry/lib/solady delete mode 160000 foundry/lib/solmate create mode 100644 foundry/script/CTF/Ethernaut/00_Ethernaut.s.sol diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol b/contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol index e405767..2aa427e 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol @@ -4,14 +4,13 @@ pragma solidity ^0.8.0; import { Owned } from "@solmate/auth/Owned.sol"; import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol"; import { ReentrancyGuard } from "@solmate/utils/ReentrancyGuard.sol"; -import { SafeTransferLib, ERC4626, ERC20 } from "@solmate/mixins/ERC4626.sol"; +import { SafeTransferLib, ERC4626, ERC20 } from "@solmate/tokens/ERC4626.sol"; import { IERC3156FlashBorrower, IERC3156FlashLender } from "@openzeppelin/contracts-v4.7.1/interfaces/IERC3156.sol"; /** * @title UnstoppableVault * @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz) */ - contract UnstoppableVault is IERC3156FlashLender, ReentrancyGuard, Owned, ERC4626 { using SafeTransferLib for ERC20; using FixedPointMathLib for uint256; diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.sol b/contracts/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.sol index be3af19..64d35ee 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.sol @@ -9,7 +9,6 @@ import { IERC3156FlashBorrower, IERC3156FlashLender } from "@openzeppelin/contra * @title FlashLoanReceiver * @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz) */ - contract FlashLoanReceiver is IERC3156FlashBorrower { address private pool; address private constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/08.Puppet.sol b/contracts/CTF/Damn-Vulnerable-DeFi/08.Puppet.sol index ad2d77b..75f4543 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/08.Puppet.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/08.Puppet.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { Address } from "@openzeppelin/contracts-v4.7.1/utils/Address.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts-v4.7.1/security/ReentrancyGuard.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; @@ -212,7 +212,6 @@ interface IUniswapV1Factory { * @title PuppetPool * @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz) */ - contract PuppetPool is ReentrancyGuard { using Address for address payable; diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol b/contracts/CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol index 81fc7a4..56d8ea9 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { IUniswapV2Pair } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { IWETH } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/WETH9.sol"; @@ -118,7 +118,7 @@ library UniswapV2Library { returns (uint256[] memory amounts) { require(path.length >= 2, "UniswapV2Library: INVALID_PATH"); - amounts = new uint[](path.length); + amounts = new uint256[](path.length); amounts[0] = amountIn; for (uint256 i; i < path.length - 1; i++) { (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i], path[i + 1]); @@ -137,7 +137,7 @@ library UniswapV2Library { returns (uint256[] memory amounts) { require(path.length >= 2, "UniswapV2Library: INVALID_PATH"); - amounts = new uint[](path.length); + amounts = new uint256[](path.length); amounts[amounts.length - 1] = amountOut; for (uint256 i = path.length - 1; i > 0; i--) { (uint256 reserveIn, uint256 reserveOut) = getReserves(factory, path[i - 1], path[i]); diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.sol b/contracts/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.sol index 92de145..f53335b 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { IWETH } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/WETH9.sol"; import { IERC721 } from "@openzeppelin/contracts-v4.7.1/token/ERC721/IERC721.sol"; import { Address } from "@openzeppelin/contracts-v4.7.1/utils/Address.sol"; diff --git a/contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol b/contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol index 8994a5f..330bdd7 100644 --- a/contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol +++ b/contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol @@ -4,11 +4,8 @@ pragma solidity ^0.8.0; import { Ownable } from "@solady/auth/Ownable.sol"; import { SafeTransferLib } from "@solady/utils/SafeTransferLib.sol"; import { IERC20 } from "@openzeppelin/contracts-v4.7.1/token/ERC20/IERC20.sol"; -import { GnosisSafe } from "@gnosis.pm/safe-contracts-v1.3.0/GnosisSafe.sol"; -import { - GnosisSafeProxy, - IProxyCreationCallback -} from "@gnosis.pm/safe-contracts-v1.3.0/proxies/IProxyCreationCallback.sol"; +import { GnosisSafe } from "@gnosis.pm/safe-contracts/GnosisSafe.sol"; +import { GnosisSafeProxy, IProxyCreationCallback } from "@gnosis.pm/safe-contracts/proxies/IProxyCreationCallback.sol"; /** * @title WalletRegistry diff --git a/contracts/CTF/Ethernaut/00_Ethernaut.s.sol b/contracts/CTF/Ethernaut/00_Ethernaut.s.sol new file mode 100644 index 0000000..6875997 --- /dev/null +++ b/contracts/CTF/Ethernaut/00_Ethernaut.s.sol @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0 <=0.9.0; + +import { Script } from "@dev/forge-std/Script.sol"; + +abstract contract EthernautScript is Script { + /// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. + string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk"; + + /// @dev Needed for the deterministic deployments. + bytes32 internal constant ZERO_SALT = bytes32(0); + + /// @dev The address of the transaction broadcaster. + address internal broadcaster; + + /// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined. + string internal mnemonic; + uint256 internal mnemonicAccountIndex; + + /// @dev Initializes the transaction broadcaster like this: + /// + /// - If $ETH_FROM is defined, use it. + /// - Otherwise, derive the broadcaster address from $MNEMONIC. + /// - If $MNEMONIC is not defined, default to a test mnemonic. + /// + /// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line. + constructor() { + address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) }); + if (from != address(0)) { + broadcaster = from; + } else { + mnemonic = vm.envOr({ name: "MNEMONIC_DEV", defaultValue: TEST_MNEMONIC }); + mnemonicAccountIndex = vm.envOr({ name: "MNEMONIC_ACCOUNT_INDEX", defaultValue: uint256(0) }); + // (broadcaster,) = deriveRememberKey({ mnemonic: mnemonic, index: uint32(mnemonicAccountIndex) }); + } + } + + modifier broadcast() { + vm.startBroadcast(broadcaster); + _; + vm.stopBroadcast(); + } +} diff --git a/contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol b/contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol index a71efde..40c7ed1 100644 --- a/contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol +++ b/contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/Hack/20231012-Platypus.sol b/contracts/Hack/20231012-Platypus.sol index 94f5a73..d289e90 100644 --- a/contracts/Hack/20231012-Platypus.sol +++ b/contracts/Hack/20231012-Platypus.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { WETH } from "@solady/tokens/WETH.sol"; -import { FlashLoanReceiverBase } from "@aave/v3-core/flashloan/base/FlashLoanReceiverBase.sol"; -import { IPoolAddressesProvider } from "@aave/v3-core/interfaces/IPoolAddressesProvider.sol"; +import { FlashLoanReceiverBase } from "@aave/core-v3/flashloan/base/FlashLoanReceiverBase.sol"; +import { IPoolAddressesProvider } from "@aave/core-v3/interfaces/IPoolAddressesProvider.sol"; /* https://snowtrace.io/tx/0xab5f6242fb073af1bb3cd6e891bc93d247e748a69e599a3744ff070447acb20f diff --git a/foundry.toml b/foundry.toml index 35532e8..1089017 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,12 +5,12 @@ block_timestamp = 1_680_220_800 # March 31, 2023 at 00:00 GMT bytecode_hash = "none" cbor_metadata = false - evm_version = "paris" # See https://www.evmdiff.com/features?name=PUSH0&kind=opcode + evm_version = "shanghai" # See https://www.evmdiff.com/features?name=PUSH0&kind=opcode fuzz = { runs = 1_000 } gas_reports = ["*"] optimizer = true optimizer_runs = 10_000 - solc = "0.8.23" + solc = "0.8.28" src = "contracts" libs = ["foundry/lib"] test = "foundry/test" diff --git a/foundry/lib/@chainlink/contracts-ccip b/foundry/lib/@chainlink/contracts-ccip deleted file mode 160000 index 8f6b610..0000000 --- a/foundry/lib/@chainlink/contracts-ccip +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8f6b6107fcbfc7732f677b1503b365207f5faee9 diff --git a/foundry/lib/@dev/forge-std b/foundry/lib/@dev/forge-std deleted file mode 160000 index f73c73d..0000000 --- a/foundry/lib/@dev/forge-std +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 diff --git a/foundry/lib/@dev/prb-test b/foundry/lib/@dev/prb-test deleted file mode 160000 index 2ece875..0000000 --- a/foundry/lib/@dev/prb-test +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2ece8755d9afe7d66440ef9ca19b8a9dab40164b diff --git a/foundry/lib/@gnosis.pm/safe-contracts b/foundry/lib/@gnosis.pm/safe-contracts deleted file mode 160000 index 810fad9..0000000 --- a/foundry/lib/@gnosis.pm/safe-contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 810fad9a074837e1247ca24ac9e7f77a5dffce19 diff --git a/foundry/lib/@gnosis.pm/safe-contracts-v1.3.0 b/foundry/lib/@gnosis.pm/safe-contracts-v1.3.0 deleted file mode 160000 index 186a21a..0000000 --- a/foundry/lib/@gnosis.pm/safe-contracts-v1.3.0 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 186a21a74b327f17fc41217a927dea7064f74604 diff --git a/foundry/lib/@openzeppelin/contracts b/foundry/lib/@openzeppelin/contracts deleted file mode 160000 index 6383299..0000000 --- a/foundry/lib/@openzeppelin/contracts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6383299d715d7cd3d697ab655b42f8e61e52e197 diff --git a/foundry/lib/@openzeppelin/contracts-upgradeable b/foundry/lib/@openzeppelin/contracts-upgradeable deleted file mode 160000 index 9610f7d..0000000 --- a/foundry/lib/@openzeppelin/contracts-upgradeable +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9610f7de978f623ecf4ae5e4b917e53e17ceaff2 diff --git a/foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1 b/foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1 deleted file mode 160000 index 5e9bccb..0000000 --- a/foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5e9bccb282ee8f3c9c4abaccc74b40b9d34ccffa diff --git a/foundry/lib/@openzeppelin/contracts-v4.7.1 b/foundry/lib/@openzeppelin/contracts-v4.7.1 deleted file mode 160000 index 3b8b4ba..0000000 --- a/foundry/lib/@openzeppelin/contracts-v4.7.1 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3b8b4ba82c880c31cd3b96dd5e15741d7e26658e diff --git a/foundry/lib/@openzeppelin/contracts-v4.7.3 b/foundry/lib/@openzeppelin/contracts-v4.7.3 deleted file mode 160000 index ecd2ca2..0000000 --- a/foundry/lib/@openzeppelin/contracts-v4.7.3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ecd2ca2cd7cac116f7a37d0e474bbb3d7d5e1c4d diff --git a/foundry/lib/@uniswap/v2-core b/foundry/lib/@uniswap/v2-core deleted file mode 160000 index ee547b1..0000000 --- a/foundry/lib/@uniswap/v2-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ee547b17853e71ed4e0101ccfd52e70d5acded58 diff --git a/foundry/lib/@uniswap/v2-periphery b/foundry/lib/@uniswap/v2-periphery deleted file mode 160000 index 0335e8f..0000000 --- a/foundry/lib/@uniswap/v2-periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0335e8f7e1bd1e8d8329fd300aea2ef2f36dd19f diff --git a/foundry/lib/@uniswap/v3-core b/foundry/lib/@uniswap/v3-core deleted file mode 160000 index d8b1c63..0000000 --- a/foundry/lib/@uniswap/v3-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d8b1c635c275d2a9450bd6a78f3fa2484fef73eb diff --git a/foundry/lib/@uniswap/v3-periphery b/foundry/lib/@uniswap/v3-periphery deleted file mode 160000 index 697c247..0000000 --- a/foundry/lib/@uniswap/v3-periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 697c2474757ea89fec12a4e6db16a574fe259610 diff --git a/foundry/lib/@uniswap/v4-core b/foundry/lib/@uniswap/v4-core deleted file mode 160000 index 60de80a..0000000 --- a/foundry/lib/@uniswap/v4-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 60de80a37b26e4d36bd573430b5b4bf53d0a3d36 diff --git a/foundry/lib/@uniswap/v4-periphery b/foundry/lib/@uniswap/v4-periphery deleted file mode 160000 index 581d96d..0000000 --- a/foundry/lib/@uniswap/v4-periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 581d96dfd8b281cafe351205bf6d2d65efb4df90 diff --git a/foundry/lib/aave-v3-core b/foundry/lib/aave-v3-core deleted file mode 160000 index 6070e82..0000000 --- a/foundry/lib/aave-v3-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6070e82d962d9b12835c88e68210d0e63f08d035 diff --git a/foundry/lib/aave-v3-periphery b/foundry/lib/aave-v3-periphery deleted file mode 160000 index 72fdcca..0000000 --- a/foundry/lib/aave-v3-periphery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72fdcca18838c2f4e05ecd25bbfb44f0db5383f7 diff --git a/foundry/lib/solady b/foundry/lib/solady deleted file mode 160000 index a44f583..0000000 --- a/foundry/lib/solady +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a44f583e2f64b89d7dfcf94562d48ff54f0882d8 diff --git a/foundry/lib/solmate b/foundry/lib/solmate deleted file mode 160000 index 0384dba..0000000 --- a/foundry/lib/solmate +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0384dbaaa4fcb5715738a9254a7c0a4cb62cf458 diff --git a/foundry/script/CTF/Ethernaut/00_Ethernaut.s.sol b/foundry/script/CTF/Ethernaut/00_Ethernaut.s.sol new file mode 100644 index 0000000..fe3e338 --- /dev/null +++ b/foundry/script/CTF/Ethernaut/00_Ethernaut.s.sol @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0 <=0.9.0; + +import { Script } from "@dev/forge-std/Script.sol"; + +abstract contract EthernautScript is Script { + /// @dev Included to enable compilation of the script without a $MNEMONIC environment variable. + string internal constant TEST_MNEMONIC = "test test test test test test test test test test test junk"; + + /// @dev Needed for the deterministic deployments. + bytes32 internal constant ZERO_SALT = bytes32(0); + + /// @dev The address of the transaction broadcaster. + address internal broadcaster; + + /// @dev Used to derive the broadcaster's address if $ETH_FROM is not defined. + string internal mnemonic; + uint256 internal mnemonicAccountIndex; + + /// @dev Initializes the transaction broadcaster like this: + /// + /// - If $ETH_FROM is defined, use it. + /// - Otherwise, derive the broadcaster address from $MNEMONIC. + /// - If $MNEMONIC is not defined, default to a test mnemonic. + /// + /// The use case for $ETH_FROM is to specify the broadcaster key and its address via the command line. + constructor() { + address from = vm.envOr({ name: "ETH_FROM", defaultValue: address(0) }); + if (from != address(0)) { + broadcaster = from; + } else { + mnemonic = vm.envOr({ name: "MNEMONIC_DEV", defaultValue: TEST_MNEMONIC }); + mnemonicAccountIndex = vm.envOr({ name: "MNEMONIC_ACCOUNT_INDEX", defaultValue: uint256(0) }); + // uint256 privateKey = vm.deriveKey(mnemonic, uint32(mnemonicAccountIndex)); + broadcaster = vm.addr(vm.deriveKey(mnemonic, uint32(mnemonicAccountIndex))); + } + } + + modifier broadcast() { + vm.startBroadcast(0x7Dd8A1d5C63DB4fDF4C1A303566601158B6EbBA6); + _; + vm.stopBroadcast(); + } +} diff --git a/foundry/script/CTF/ONLYPWNER/01.TUTORIAL.s.sol b/foundry/script/CTF/ONLYPWNER/01.TUTORIAL.s.sol index cc697a9..011a81a 100644 --- a/foundry/script/CTF/ONLYPWNER/01.TUTORIAL.s.sol +++ b/foundry/script/CTF/ONLYPWNER/01.TUTORIAL.s.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import { Script } from "@dev/forge-std/src/Script.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Script } from "@dev/forge-std/Script.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { Tutorial, TutorialExploit } from "@contracts/CTF/ONLYPWNER/02.TUTORIAL.sol"; /* @@ -20,7 +20,7 @@ contract TUTORIAL_01_Exploit is Script { TutorialExploit private exploitInstance; function _localSetup() public { - victimInstance = new Tutorial{value: 10 ether}(); + victimInstance = new Tutorial{ value: 10 ether }(); // victimInstance.deposit{ value: 10 ether }(); } diff --git a/foundry/script/CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol b/foundry/script/CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol index ee66fd9..c2ded7c 100644 --- a/foundry/script/CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol +++ b/foundry/script/CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import { Script } from "@dev/forge-std/src/Script.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Script } from "@dev/forge-std/Script.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { Vault } from "@contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol"; /* diff --git a/foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol b/foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol index 2d0d910..417376d 100644 --- a/foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol +++ b/foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import { Script } from "@dev/forge-std/src/Script.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Script } from "@dev/forge-std/Script.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { Vault, IVault, VaultExploit } from "@contracts/CTF/ONLYPWNER/01.FREEBIE.sol"; /* diff --git a/foundry/script/CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol b/foundry/script/CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol index af16708..d64c2d3 100644 --- a/foundry/script/CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol +++ b/foundry/script/CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import { Script } from "@dev/forge-std/src/Script.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Script } from "@dev/forge-std/Script.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { WrappedEther, WrappedEtherExploit } from "@contracts/CTF/ONLYPWNER/05.WRAPPED-ETHER.sol"; /* diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.t.sol index 3d83df2..1969f21 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { ReceiverUnstoppable, UnstoppableVault } from "@contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.t.sol index 3de98da..97c84dd 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { FlashLoanReceiver, NaiveReceiverLenderPool, diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol index fb7126a..e1c351c 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { TrusterLenderPool } from "@contracts/CTF/Damn-Vulnerable-DeFi/03.Truster.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/04.Side-Entrance.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/04.Side-Entrance.t.sol index b345d23..58cc76b 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/04.Side-Entrance.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/04.Side-Entrance.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { SideEntranceLenderPool, SideEntranceAttack } from "@contracts/CTF/Damn-Vulnerable-DeFi/04.Side-Entrance.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/05.The-Rewarder.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/05.The-Rewarder.t.sol index 007a55e..130147a 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/05.The-Rewarder.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/05.The-Rewarder.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { FlashLoanerPool, @@ -99,8 +99,9 @@ contract Challenge_5_The_Rewarder_Test is Test { vm.startPrank(player); /* START CODE YOUR SOLUTION HERE */ - TheRewarderHack hackInst = - new TheRewarderHack(address(flashLoanPool), address(rewarderPool), address(liquidityToken), address(rewardToken)); + TheRewarderHack hackInst = new TheRewarderHack( + address(flashLoanPool), address(rewarderPool), address(liquidityToken), address(rewardToken) + ); hackInst.attack(); /* END CODE YOUR SOLUTION */ vm.stopPrank(); diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol index 3b31eb6..72d6c20 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableTokenSnapshot } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableTokenSnapshot.sol"; import { SimpleGovernance, SelfiePool, SelfieHack } from "@contracts/CTF/Damn-Vulnerable-DeFi/06.Selfie.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/07.Compromised.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/07.Compromised.t.sol index 2db1ea9..d7cbd06 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/07.Compromised.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/07.Compromised.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { Exchange, TrustfulOracle, @@ -63,7 +63,7 @@ contract Challenge_7_Compromised_Test is Test { TrustfulOracleInitializer initializer = new TrustfulOracleInitializer(sources, symbols, initialPrices); oracle = TrustfulOracle(initializer.oracle()); - exchange = new Exchange{value: EXCHANGE_INITIAL_ETH_BALANCE}(address(oracle)); + exchange = new Exchange{ value: EXCHANGE_INITIAL_ETH_BALANCE }(address(oracle)); nftToken = DamnValuableNFT(exchange.token()); } diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/08.Puppet.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/08.Puppet.t.sol index 30c8aa4..9315e43 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/08.Puppet.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/08.Puppet.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import { PRBTest } from "@prb/test/PRBTest.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.t.sol index 475ed31..3db38b3 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { PRBTest } from "@prb/test/PRBTest.sol"; import { IWETH } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/WETH9.sol"; import { DamnValuableNFT } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableNFT.sol"; @@ -125,8 +125,9 @@ contract Challenge_10_Free_Rider_Test is PRBTest { /* START CODE YOUR SOLUTION HERE */ // ... - FreeRiderHack hackInst = - new FreeRiderHack(address(uniswapPair), payable(marketplace), address(weth), address(nft), address(devsContract)); + FreeRiderHack hackInst = new FreeRiderHack( + address(uniswapPair), payable(marketplace), address(weth), address(nft), address(devsContract) + ); (bool isSuccess,) = address(hackInst).call{ value: player.balance }(""); assertEq(isSuccess, true, ""); hackInst.attack(); diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/11.Backdoor.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/11.Backdoor.t.sol index 51895fd..d1c3d12 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/11.Backdoor.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/11.Backdoor.t.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; -import { GnosisSafe } from "@gnosis.pm/safe-contracts-v1.3.0/GnosisSafe.sol"; -import { GnosisSafeProxyFactory } from "@gnosis.pm/safe-contracts-v1.3.0/proxies/GnosisSafeProxyFactory.sol"; +import { Test } from "@dev/forge-std/Test.sol"; +import { GnosisSafe } from "@gnosis.pm/safe-contracts/GnosisSafe.sol"; +import { GnosisSafeProxyFactory } from "@gnosis.pm/safe-contracts/proxies/GnosisSafeProxyFactory.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { WalletRegistry, BackdoorHack } from "@contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol"; @@ -53,7 +53,7 @@ contract Challenge_11_Backdoor_Test is Test { _initialBeneficiaries.push(david); walletRegistry = - new WalletRegistry(address(masterCopy),address(walletFactory), address(token), _initialBeneficiaries); + new WalletRegistry(address(masterCopy), address(walletFactory), address(token), _initialBeneficiaries); assertEq(walletRegistry.owner(), deployer, ""); token.transfer(address(walletRegistry), AMOUNT_TOKENS_DISTRIBUTED); diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/12.Climber.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/12.Climber.t.sol index 91f9ffd..b6ec4ad 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/12.Climber.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/12.Climber.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { ClimberVault } from "@contracts/CTF/Damn-Vulnerable-DeFi/12.Climber.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/13.Wallet-Mining.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/13.Wallet-Mining.t.sol index 48de214..a3624c0 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/13.Wallet-Mining.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/13.Wallet-Mining.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; import { WalletDeployer } from "@contracts/CTF/Damn-Vulnerable-DeFi/13.Wallet-Mining.sol"; diff --git a/foundry/test/CTF/Damn-Vulnerable-DeFi/14.Puppet-V3.t.sol b/foundry/test/CTF/Damn-Vulnerable-DeFi/14.Puppet-V3.t.sol index 649fba0..0f6bfce 100644 --- a/foundry/test/CTF/Damn-Vulnerable-DeFi/14.Puppet-V3.t.sol +++ b/foundry/test/CTF/Damn-Vulnerable-DeFi/14.Puppet-V3.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { DamnValuableToken } from "@contracts/CTF/Damn-Vulnerable-DeFi/00.Base/DamnValuableToken.sol"; /* diff --git a/foundry/test/CTF/Ethernaut/01_Fallback.t.sol b/foundry/test/CTF/Ethernaut/01_Fallback.t.sol index b3888f3..380ca88 100644 --- a/foundry/test/CTF/Ethernaut/01_Fallback.t.sol +++ b/foundry/test/CTF/Ethernaut/01_Fallback.t.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { Fallback, FallbackFactory } from "@contracts/CTF/Ethernaut/01_Fallback.sol"; import { Ethernaut } from "@contracts/CTF/Ethernaut/00_Ethernaut.sol"; -import { console } from "@dev/forge-std/src/console.sol"; +import { console } from "@dev/forge-std/console.sol"; /* forge test --match-path foundry/test/Ethernaut/01_Fallback.t.sol -vvvv */ -contract FallbackTest is Test { +contract FallbackTest is Test, Ethernaut { Ethernaut private ethernaut; // hacking attack address address private attackAddress = address(2333); diff --git a/foundry/test/CTF/Ethernaut/02_Fallout.t.sol b/foundry/test/CTF/Ethernaut/02_Fallout.t.sol index d65ab4e..793f121 100644 --- a/foundry/test/CTF/Ethernaut/02_Fallout.t.sol +++ b/foundry/test/CTF/Ethernaut/02_Fallout.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; -import { console } from "@dev/forge-std/src/console.sol"; +import { Test } from "@dev/forge-std/Test.sol"; +import { console } from "@dev/forge-std/console.sol"; import { Ethernaut } from "@contracts/CTF/Ethernaut/00_Ethernaut.sol"; import { Fallout, FalloutFactory } from "@contracts/CTF/Ethernaut/02_Fallout.sol"; diff --git a/foundry/test/CTF/ONLYPWNER/03.REVERSE-RUGPULL.t.sol b/foundry/test/CTF/ONLYPWNER/03.REVERSE-RUGPULL.t.sol index 85063c7..5b03fed 100644 --- a/foundry/test/CTF/ONLYPWNER/03.REVERSE-RUGPULL.t.sol +++ b/foundry/test/CTF/ONLYPWNER/03.REVERSE-RUGPULL.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Test } from "@dev/forge-std/Test.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { MintableERC20, Vault } from "@contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol"; /* diff --git a/foundry/test/CTF/ONLYPWNER/04.UNDER-THE-FLOW.t.sol b/foundry/test/CTF/ONLYPWNER/04.UNDER-THE-FLOW.t.sol index 0aefc01..08c06d2 100644 --- a/foundry/test/CTF/ONLYPWNER/04.UNDER-THE-FLOW.t.sol +++ b/foundry/test/CTF/ONLYPWNER/04.UNDER-THE-FLOW.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; -import { console2 } from "@dev/forge-std/src/console2.sol"; +import { Test } from "@dev/forge-std/Test.sol"; +import { console2 } from "@dev/forge-std/console2.sol"; import { ImprovedERC20 } from "@contracts/CTF/ONLYPWNER/04.UNDER-THE-FLOW.sol"; /* @@ -24,11 +24,7 @@ contract UNDER_THE_FLOW_04_Test is Test { function _before() public { // 1.SetUp the exploit - erc20 = new ImprovedERC20( - "Improved ERC20", - "IMPERC20", - 18, - 100 ether); + erc20 = new ImprovedERC20("Improved ERC20", "IMPERC20", 18, 100 ether); erc20.transfer(other, 100 ether); } diff --git a/foundry/test/CTF/ONLYPWNER/05.WRAPPED-ETHER.t.sol b/foundry/test/CTF/ONLYPWNER/05.WRAPPED-ETHER.t.sol index b89e654..57ab5ca 100644 --- a/foundry/test/CTF/ONLYPWNER/05.WRAPPED-ETHER.t.sol +++ b/foundry/test/CTF/ONLYPWNER/05.WRAPPED-ETHER.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; import { WrappedEther, WrappedEtherExploit } from "@contracts/CTF/ONLYPWNER/05.WRAPPED-ETHER.sol"; /* diff --git a/foundry/test/Hack/20231012-Platypus.t.sol b/foundry/test/Hack/20231012-Platypus.t.sol index f5f0367..aa0da99 100644 --- a/foundry/test/Hack/20231012-Platypus.t.sol +++ b/foundry/test/Hack/20231012-Platypus.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import { Test } from "@dev/forge-std/src/Test.sol"; +import { Test } from "@dev/forge-std/Test.sol"; // import { console2 } from "@dev/forge-std/src/console2.sol"; import { Hacker } from "@contracts/Hack/20231012-Platypus.sol"; diff --git a/package.json b/package.json index 1f59d01..7109490 100644 --- a/package.json +++ b/package.json @@ -13,21 +13,37 @@ "foundry", "smart-contracts", "solidity", - "ethernaut", - "hacker" + "template" ], + "dependencies": { + "@uniswap/v2-core": "^1.0.1", + "@uniswap/v2-periphery": "^1.1.0-beta.0", + "@uniswap/v3-core": "^1.0.1", + "@uniswap/v3-periphery": "^1.4.4", + "solmate": "^6.8.0", + "solady": "^0.0.278", + "@prb/test": "^0.6.4", + "@aave/core-v3": "^1.19.3", + "@openzeppelin/contracts-upgradeable": "^5.1.0", + "@gnosis.pm/safe-contracts": "^1.3.0", + "@openzeppelin/contracts": "^5.1.0", + "prettier": "^3.4.2", + "solhint": "^5.0.3", + "forge-std": "github:foundry-rs/forge-std#v1.9.4", + "@openzeppelin/contracts-v4.7.1": "github:OpenZeppelin/openzeppelin-contracts#v4.7.1", + "@openzeppelin/contracts-v4.7.3": "github:OpenZeppelin/openzeppelin-contracts#v4.7.3", + "@openzeppelin/contracts-upgradeable-v4.7.1": "github:OpenZeppelin/openzeppelin-contracts-upgradeable#v4.7.1" + }, "private": true, "scripts": { - "clean": "rm -rf foundry/cache foundry/out foundry/broadcast", - "lint": "yarn lint:sol && yarn lint:prettier", - "lint:sol": "forge fmt && yarn solhint foundry/test/**/*.sol contracts/**/*.sol --fix", - "lint:prettier": "prettier --write **/*.{json,md,yml} --ignore-path=.prettierignore", + "clean": "rm -rf cache out", + "build": "forge build", + "lint": "bun run lint:sol && bun run prettier:check", + "lint:sol": "forge fmt --check && bun solhint \"{script,src,test}/**/*.sol\"", + "prettier:check": "prettier --check \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"", + "prettier:write": "prettier --write \"**/*.{json,md,yml}\" --ignore-path \".prettierignore\"", "test": "forge test", "test:coverage": "forge coverage", - "test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir foundry/coverage" - }, - "devDependencies": { - "prettier": "^3.2.4", - "solhint": "^4.1.1" + "test:coverage:report": "forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage" } } diff --git a/remappings.txt b/remappings.txt index 696d78c..74426fa 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,17 +1,19 @@ @contracts=contracts +@dev/forge-std/=node_modules/forge-std/src -@solmate=foundry/lib/solmate/src -@solady=foundry/lib/solady/src -@prb/test=foundry/lib/@dev/prb-test/src +@solmate=node_modules/solmate/src +@solady=node_modules/solady/src +@prb/test=node_modules/@prb/test/src +@gnosis.pm/safe-contracts=node_modules/@gnosis.pm/safe-contracts/contracts +@aave/core-v3=node_modules/@aave/core-v3/contracts -@gnosis.pm/safe-contracts=foundry/lib/@gnosis.pm/safe-contracts/contracts -@gnosis.pm/safe-contracts-v1.3.0=foundry/lib/@gnosis.pm/safe-contracts-v1.3.0/contracts +@openzeppelin/contracts=node_modules/@openzeppelin/contracts +@openzeppelin/contracts-v4.7.3=node_modules/@openzeppelin/contracts-v4.7.3/contracts +@openzeppelin/contracts-upgradeable=node_modules/@openzeppelin/contracts-upgradeable/contracts +@openzeppelin/contracts-v4.7.1=node_modules/@openzeppelin/contracts-v4.7.1/contracts +@openzeppelin/contracts-upgradeable-v4.7.1=node_modules/@openzeppelin/contracts-upgradeable-v4.7.1/contracts -@openzeppelin/contracts=foundry/lib/@openzeppelin/contracts/contracts -@openzeppelin/contracts-upgradeable=foundry/lib/@openzeppelin/contracts-upgradeable/contracts -@openzeppelin/contracts-v4.7.1=foundry/lib/@openzeppelin/contracts-v4.7.1/contracts -@openzeppelin/contracts-v4.7.3=foundry/lib/@openzeppelin/contracts-v4.7.3/contracts -@openzeppelin/contracts-upgradeable-v4.7.1=foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1/contracts - -@aave/v3-core=foundry/lib/aave-v3-core/contracts -@aave/v3-periphery=foundry/lib/aave-v3-periphery/contracts +@uniswap/v2-core=node_modules/@uniswap/v2-core +@uniswap/v2-periphery=node_modules/@uniswap/v2-periphery +@uniswap/v3-core=node_modules/@uniswap/v3-core +@uniswap/v3-periphery=node_modules/@uniswap/v3-periphery