-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW4day4n5.sol
More file actions
31 lines (22 loc) · 779 Bytes
/
W4day4n5.sol
File metadata and controls
31 lines (22 loc) · 779 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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract WithdrawalPattern{
receive() external payable { }
fallback() external payable { }
address public owner;
mapping(address => uint256) public balances;
constructor() {
owner = msg.sender;
}
error InsufficientFund();
error WithdrawalFail();
function Push() public{
//Dangerous, fund can stuck, reentrancy attack as control temp leaves the contract
}
function Pull(uint256 amount) public payable{
require(msg.value > 0, InsufficientFund());
balances[msg.sender] -= msg.value;
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, WithdrawalFail());
}
}