Skip to content

Commit

Permalink
feat: add wip solution 26 ethernaut
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Oct 7, 2024
1 parent 37c2cee commit 4b4b333
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/EthernautCTF/DoubleEntryExploit.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

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

contract DoubleEntryExploit is Test {
CryptoVault target;
DoubleEntryPoint doubleEntryToken;
LegacyToken legacyToken;
Forta forta;

address deployerAddress = makeAddr('deployer');
address sweptTokenRecipientAddress = makeAddr('sweptTokenRecipient');
address exploiterAddress = makeAddr('exploiter');

function setUp() public {
vm.startPrank(deployerAddress);
target = new CryptoVault(sweptTokenRecipientAddress);
console.log('Target contract deployed');

legacyToken = new LegacyToken();
legacyToken.mint(address(target), 100 ether);
console.log('Legacy token contract deployed');

forta = new Forta();
console.log('Forta contract deployed');

doubleEntryToken = new DoubleEntryPoint(
address(legacyToken),
address(target),
address(forta),
exploiterAddress
);
console.log('DoubleEntry token contract deployed');

legacyToken.delegateToNewContract(doubleEntryToken);
console.log('Legacy token delegate to DoubleEntry token');

target.setUnderlying(address(doubleEntryToken));
console.log('CryptoVault underlying token set to the DoubleEntry token');

vm.stopPrank();
}

function testExploit() public {
console.log(); // break line

uint256 vaultDoubleEntryTokenBalance = doubleEntryToken.balanceOf(
address(target)
);
console.log(
'Vault DoubleEntryToken balance: %d units',
vaultDoubleEntryTokenBalance / 1 ether
);
assertEq(vaultDoubleEntryTokenBalance, 100 ether);

uint256 vaultLegacyTokenBalance = legacyToken.balanceOf(address(target));
console.log(
'Vault LegacyToken balance: %d units',
vaultLegacyTokenBalance / 1 ether
);
assertEq(vaultLegacyTokenBalance, 100 ether);

vm.startPrank(exploiterAddress);

// CryptoVault contract
// - Anyone can transfer any token T balance of the vault to the sweptTokenRecipient address.

vm.stopPrank();
}
}

0 comments on commit 4b4b333

Please sign in to comment.