Level 1
Noob Hacker
Ethernaut 27
Double Entry Point
0 / 100 EXP
100 EXP to Junior Hacker
0%
Unlocked hints
Double Entry Point
0/3
Unlock a hint to view it here.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IDetectionBot {
function handleTransaction(address user, bytes calldata msgData) external;
}
contract Forta {
mapping(address => IDetectionBot) public usersDetectionBots;
mapping(address => uint256) public botRaisedAlerts;
function setDetectionBot(address bot) external {
usersDetectionBots[msg.sender] = IDetectionBot(bot);
}
function notify(address user, bytes calldata data) external {
if (address(usersDetectionBots[user]) != address(0)) {
try usersDetectionBots[user].handleTransaction(user, data) {} catch {}
}
}
function raiseAlert(address user) external {
if (address(usersDetectionBots[user]) == msg.sender) botRaisedAlerts[msg.sender]++;
}
}
contract LegacyToken {
mapping(address => uint256) public balanceOf;
address public delegate;
function mint(address to, uint256 amount) external {
balanceOf[to] += amount;
}
function delegateToNewContract(address next) external {
delegate = next;
}
function transfer(address to, uint256 amount) external returns (bool) {
if (delegate != address(0)) return DoubleEntryPoint(delegate).delegateTransfer(to, amount, msg.sender);
balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;
return true;
}
}
contract CryptoVault {
address public sweptTokensRecipient;
address public underlying;
constructor(address recipient) {
sweptTokensRecipient = recipient;
}
function setUnderlying(address token) external {
require(underlying == address(0), "Already set");
underlying = token;
}
function sweepToken(address token) external {
require(token != underlying, "Can't transfer underlying token");
LegacyToken(token).transfer(sweptTokensRecipient, LegacyToken(token).balanceOf(address(this)));
}
}
contract DoubleEntryPoint {
mapping(address => uint256) public balanceOf;
address public cryptoVault;
address public player;
address public delegatedFrom;
Forta public forta;
constructor(address legacy, address vault, address forta_, address player_) {
delegatedFrom = legacy;
cryptoVault = vault;
forta = Forta(forta_);
player = player_;
balanceOf[vault] = 100 ether;
}
function delegateTransfer(address to, uint256 amount, address sender) external returns (bool) {
require(msg.sender == delegatedFrom, "Not legacy contract");
address bot = address(forta.usersDetectionBots(player));
uint256 previous = forta.botRaisedAlerts(bot);
forta.notify(player, msg.data);
balanceOf[sender] -= amount;
balanceOf[to] += amount;
require(forta.botRaisedAlerts(bot) == previous, "Alert has been triggered, reverting");
return true;
}
}
Starter exploit
Exploit.s.sol
// TODO: implement the exploit.
contract DetectionBot { }
function run() external { vm.startBroadcast(PLAYER_PRIVATE_KEY); vm.stopBroadcast(); }
Ready to test your exploit?
The starter code is yours to inspect. Sign in to edit it, run Foundry, and keep every clear.
Contract line
Add audit note
0 / 300
CTF tour
Exploit Challenge
This is your guided Solidity CTF workspace.
Keep your audit trail
Sign in to save private notes on contract lines and continue your review later.
Delete this audit note?
This removes it permanently from your private workspace.
