-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreentrancy-eth.sol
More file actions
35 lines (29 loc) · 948 Bytes
/
Copy pathreentrancy-eth.sol
File metadata and controls
35 lines (29 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract Reentrancy {
address public owner;
mapping(address => uint256) public balances;
uint256 public amount;
event Withdrawal(address indexed from, uint256 amount);
constructor() {
owner = msg.sender;
}
function deposit() public {
require(msg.sender == owner, "Only the owner can deposit");
balances[msg.sender] += 1 ether;
}
//rule-id: ok
function withdraw() public {
require(msg.sender == owner, "Only the owner can withdraw");
uint256 amount = balances[msg.sender];
balances[msg.sender] = 0;
msg.sender.call{value: amount}("");
emit Withdrawal(msg.sender, amount);
}
//rule-id: reentrancy-eth
function arbitraryWithdraw() public {
uint256 amount = balances[msg.sender];
msg.sender.call{value: amount}("");
balances[msg.sender] = 0;
}
}