-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsuicide_sender.sol
33 lines (32 loc) · 1.35 KB
/
suicide_sender.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
pragma solidity ^0.4.16;
/* A small utility contract that sends ether to other addresses by means of
* SUICIDE/SELFDESTRUCT. Unlike for a normal send/call, if the receiving address
* belongs to a contract, the contract's code is never called; one can
* forcibly increase a contract's balance!
*
* To send $x to y using this technique, simply call `suicideSend(y)` with a
* value of $x.
*
*
* If you're interested in the implications of this trick, I recommend
* looking at João Carvalho's and Richard Moore's entries to the first
* Underhanded Solidity Contest [1]. Anybody writing smart ontracts should be
* aware of forced balance increases lest their contracts be vulnerable.
*
* [1] https://medium.com/@weka/announcing-the-winners-of-the-first-underhanded-solidity-coding-contest-282563a87079
*/
contract SuicideSender {
function suicideSend(address to) payable {
address temp_addr;
assembly {
let free_ptr := mload(0x40)
/* Prepare initcode that immediately forwards any funds to address
* `to` by running [PUSH20 to, SUICIDE].
*/
mstore(free_ptr, or(0x730000000000000000000000000000000000000000ff, mul(to, 0x100)))
// Run initcode we just prepared.
temp_addr := create(callvalue, add(free_ptr, 10), 22)
}
require(temp_addr != 0);
}
}