mirror of
https://github.com/zkoranges/zkPoEX.git
synced 2026-01-14 15:07:59 -05:00
34 lines
767 B
Solidity
34 lines
767 B
Solidity
// SPDX-License-Identifier: MIT
|
|
// DO NOT USE IN PRODUCTION
|
|
// Ethernaut Lvl. 10 - Reentrance
|
|
pragma solidity 0.8.19;
|
|
|
|
contract Target {
|
|
|
|
mapping(address => uint) public balances;
|
|
|
|
function deposit(address _to) public payable {
|
|
balances[_to] = balances[_to] + msg.value;
|
|
}
|
|
|
|
function balanceOf(address _who) public view returns (uint balance) {
|
|
return balances[_who];
|
|
}
|
|
|
|
// This function has a reentrancy vulnerability
|
|
function withdraw(uint _amount) public {
|
|
if(balances[msg.sender] >= _amount) {
|
|
(bool result,) = msg.sender.call{value:_amount}("");
|
|
if(result) {
|
|
_amount;
|
|
}
|
|
unchecked {
|
|
balances[msg.sender] -= _amount;
|
|
}
|
|
}
|
|
}
|
|
|
|
constructor() payable {}
|
|
|
|
receive() external payable {}
|
|
} |