-
Notifications
You must be signed in to change notification settings - Fork 4
07. Force
r1oga edited this page Oct 28, 2022
·
1 revision
Make the balance of the contract greater than zero.
3 methods exist to receive Ethers:
- Message calls and payable functions
-
addr.call{value: x}('')
: returns success condition and return data, forwards all available gas, adjustable -
<address payable>.transfer(uint256 amount)
: reverts on failure, forwards 2300 gas stipend, not adjustable -
<address payable>.send(uint256 amount) returns (bool)
: returns false on failure, forwards 2300 gas stipend, not adjustable
function receive() payable external {}
- contract designated as recipient for mining rewards
-
selfdestruct(address payable recipient)
: destroy the current contract, sending its funds to the given Address and end execution.
As the contract to hack has no payable function to receive ether, we send ether to it by selfdestructing another contract, designating the victim contract as the recipient.
By selfdestructing a contract, it is possible to send ether to another contract even if it doesn't have any payable functions. This is dangerous as it can result in losing ether: e.g. if sending ETH to a contract without withdraw function, or to a removed contract.