Skip to content

Commit

Permalink
OPT forge lib to yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
6boris committed Dec 5, 2024
1 parent 3afa0ed commit 931970b
Show file tree
Hide file tree
Showing 56 changed files with 187 additions and 110 deletions.
3 changes: 1 addition & 2 deletions contracts/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion contracts/CTF/Damn-Vulnerable-DeFi/02.Naive-Receiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions contracts/CTF/Damn-Vulnerable-DeFi/08.Puppet.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -212,7 +212,6 @@ interface IUniswapV1Factory {
* @title PuppetPool
* @author Damn Vulnerable DeFi (https://damnvulnerabledefi.xyz)
*/

contract PuppetPool is ReentrancyGuard {
using Address for address payable;

Expand Down
6 changes: 3 additions & 3 deletions contracts/CTF/Damn-Vulnerable-DeFi/09.Puppet-V2.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion contracts/CTF/Damn-Vulnerable-DeFi/10.Free-Rider.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
7 changes: 2 additions & 5 deletions contracts/CTF/Damn-Vulnerable-DeFi/11.Backdoor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions contracts/CTF/Ethernaut/00_Ethernaut.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
2 changes: 1 addition & 1 deletion contracts/CTF/ONLYPWNER/03.REVERSE-RUGPULL.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
6 changes: 3 additions & 3 deletions contracts/Hack/20231012-Platypus.sol
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion foundry/lib/@chainlink/contracts-ccip
Submodule contracts-ccip deleted from 8f6b61
1 change: 0 additions & 1 deletion foundry/lib/@dev/forge-std
Submodule forge-std deleted from f73c73
1 change: 0 additions & 1 deletion foundry/lib/@dev/prb-test
Submodule prb-test deleted from 2ece87
1 change: 0 additions & 1 deletion foundry/lib/@gnosis.pm/safe-contracts
Submodule safe-contracts deleted from 810fad
1 change: 0 additions & 1 deletion foundry/lib/@gnosis.pm/safe-contracts-v1.3.0
Submodule safe-contracts-v1.3.0 deleted from 186a21
1 change: 0 additions & 1 deletion foundry/lib/@openzeppelin/contracts
Submodule contracts deleted from 638329
1 change: 0 additions & 1 deletion foundry/lib/@openzeppelin/contracts-upgradeable
Submodule contracts-upgradeable deleted from 9610f7
1 change: 0 additions & 1 deletion foundry/lib/@openzeppelin/contracts-upgradeable-v4.7.1
Submodule contracts-upgradeable-v4.7.1 deleted from 5e9bcc
1 change: 0 additions & 1 deletion foundry/lib/@openzeppelin/contracts-v4.7.1
Submodule contracts-v4.7.1 deleted from 3b8b4b
1 change: 0 additions & 1 deletion foundry/lib/@openzeppelin/contracts-v4.7.3
Submodule contracts-v4.7.3 deleted from ecd2ca
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v2-core
Submodule v2-core deleted from ee547b
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v2-periphery
Submodule v2-periphery deleted from 0335e8
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v3-core
Submodule v3-core deleted from d8b1c6
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v3-periphery
Submodule v3-periphery deleted from 697c24
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v4-core
Submodule v4-core deleted from 60de80
1 change: 0 additions & 1 deletion foundry/lib/@uniswap/v4-periphery
Submodule v4-periphery deleted from 581d96
1 change: 0 additions & 1 deletion foundry/lib/aave-v3-core
Submodule aave-v3-core deleted from 6070e8
1 change: 0 additions & 1 deletion foundry/lib/aave-v3-periphery
Submodule aave-v3-periphery deleted from 72fdcc
1 change: 0 additions & 1 deletion foundry/lib/solady
Submodule solady deleted from a44f58
1 change: 0 additions & 1 deletion foundry/lib/solmate
Submodule solmate deleted from 0384db
44 changes: 44 additions & 0 deletions foundry/script/CTF/Ethernaut/00_Ethernaut.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
6 changes: 3 additions & 3 deletions foundry/script/CTF/ONLYPWNER/01.TUTORIAL.s.sol
Original file line number Diff line number Diff line change
@@ -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";

/*
Expand All @@ -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 }();
}

Expand Down
4 changes: 2 additions & 2 deletions foundry/script/CTF/ONLYPWNER/03.REVERSE-RUGPULL.s.sol
Original file line number Diff line number Diff line change
@@ -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";

/*
Expand Down
4 changes: 2 additions & 2 deletions foundry/script/CTF/ONLYPWNER/05.FREEBIE.s.sol
Original file line number Diff line number Diff line change
@@ -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";

/*
Expand Down
4 changes: 2 additions & 2 deletions foundry/script/CTF/ONLYPWNER/05.WRAPPED-ETHER.s.sol
Original file line number Diff line number Diff line change
@@ -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";

/*
Expand Down
2 changes: 1 addition & 1 deletion foundry/test/CTF/Damn-Vulnerable-DeFi/01.Unstoppable.t.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion foundry/test/CTF/Damn-Vulnerable-DeFi/03.Truster.t.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
7 changes: 4 additions & 3 deletions foundry/test/CTF/Damn-Vulnerable-DeFi/05.The-Rewarder.t.sol
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion foundry/test/CTF/Damn-Vulnerable-DeFi/06.Selfie.t.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
4 changes: 2 additions & 2 deletions foundry/test/CTF/Damn-Vulnerable-DeFi/07.Compromised.t.sol
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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());
}

Expand Down
Loading

0 comments on commit 931970b

Please sign in to comment.