-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathFixedDonation.sol
33 lines (24 loc) · 1.24 KB
/
FixedDonation.sol
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
// SPDX-License-Identifier: BSL-1.0 (Boost Software License 1.0)
//-------------------------------------------------------------------------------------//
// Copyright (c) 2022 - 2023 serial-coder: Phuwanai Thummavet ([email protected]) //
//-------------------------------------------------------------------------------------//
// For more info, please refer to my article:
// - On Medium: https://medium.com/valixconsulting/solidity-smart-contract-security-by-example-07-phishing-with-improper-authorization-232dacf307e3
// - On serial-coder.com: https://www.serial-coder.com/post/solidity-smart-contract-security-by-example-07-phishing-with-improper-authorization/
pragma solidity 0.8.17;
contract FixedDonation {
address public immutable owner;
constructor() {
owner = msg.sender;
}
function buyMeACoffee() external payable {
}
function getBalance() external view returns (uint256) {
return address(this).balance;
}
function collectEthers(address payable _to, uint256 _amount) external {
require(msg.sender == owner, "Not owner"); // FIX: Use msg.sender instead of tx.origin
(bool success, ) = _to.call{value: _amount}("");
require(success, "Failed to send Ether");
}
}