Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions contracts/src/attacks/DetectionBot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ interface IForta {

contract DetectionBot is IDetectionBot {
IForta public fortaContract;
address public cryptoVaultContract;

constructor(address forta) {
constructor(address forta, address cryptoVault) {
fortaContract = IForta(forta);
cryptoVaultContract = cryptoVault;
}

function handleTransaction(address user, bytes calldata msgData) public override {
// Only the Forta contract can call this method
require(msg.sender == address(fortaContract), "Unauthorized");
fortaContract.raiseAlert(user);
msgData;

// Decode the parameters of the delegateTransfer method
(, , address origSender) = abi.decode(
msgData[4:],
(address, uint256, address)
);

// The origSender mustn't be the CryptoVault
// because DoubleEntryPoint is an underlying token,
// if so raise an alert
if (origSender == cryptoVaultContract)
fortaContract.raiseAlert(user);
}
}
7 changes: 7 additions & 0 deletions contracts/src/levels/DoubleEntryPointFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ contract DoubleEntryPointFactory is Level {
}

function __trySweep(CryptoVault cryptoVault, DoubleEntryPoint instance) external returns (bool, bytes memory) {
// emulate a lambda transfer of a user
try LegacyToken(instance.delegatedFrom()).transfer(address(cryptoVault), 0) {
} catch {
// It mustn't revert, if so return true on failure
return (true, abi.encode(false));
}

try cryptoVault.sweepToken(IERC20(instance.delegatedFrom())) {
return (true, abi.encode(false));
} catch {
Expand Down
3 changes: 2 additions & 1 deletion contracts/test/levels/DoubleEntryPoint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ contract TestDoubleEntryPoint is Test, Utils {
vm.startPrank(player);

Forta forta = instance.forta();
DetectionBot bot = new DetectionBot(address(forta));
address cryptoVault = instance.cryptoVault();
DetectionBot bot = new DetectionBot(address(forta), cryptoVault);

forta.setDetectionBot(address(bot));

Expand Down