We sent ETH to the wrong address and were able to return them

Original author: Anton Bukov
  • Transfer

It all started with the problem that we encountered in BitClave : during the preparation of our ICO, a certain amount of ETH cryptocurrency (ether) was sent to the address of the smart contract, which had previously been sunk into the Ethereum test network. Money was sent on the main network to an address that does not belong to any private key, nor to a single smart contract in this network. At first it seemed to us that we simply threw out $ 2000 without a single opportunity to return our funds

The story began when my colleague asked me for a private key to the address 0x9c86825280b1d6c7dB043D4CC86E1549990149f9 . I sent him a private key to the address 0x231A3925A014EF0a11a0DC5c33bF7cdB3bd9919f , from which the smart contract was downloaded at the first address. We discussed the problem and came to the conclusion that there is no way to return the money sent.

Each smart contract uploaded to the Ethereum network has a unique address, which at first glance looks like a random one, but I found out exactly how the address is generated when uploading to the network: ethereum. stackexchange.com/a/761/3032 . Simply put, the download address is the hash of the sender of the transaction and the nonce value (equal to the number of outgoing transactions from this address):

deployed_address = sha3(rlp.encode([sender, nonce]))

This prompted me to use the same wallet (the one that I used in the test network) to upload a new smart contract to the main network. I developed a smart contract for a simple wallet, which allows you to only display the balance and transfer the lost funds:

contract SimpleWallet is Ownable {
    function () publicpayable{
    functionweiBalance() publicconstantreturns(uint256) {
    functionclaim(address destination) publiconlyOwner{

Then I found a transaction in the test network with which the original contract was downloaded: 0xc4c32a3d97dbd691eb3646e4c0c404e899a632010bc48d7182d75bef6803b7bc and found that the nonce field was 13. I replenished my wallet by 0.03 ETH and cleared the main contract with the main network again until nonce grew from 0 to 13. And that's it, I got a smart contract loaded at the desired address! Here we can observe 2 transactions with the same nonce equal to 13, which were downloaded by 2 different smart contracts in 2 different networks at identical addresses with a difference of 5 days:

Funds were successfully received by us after calling the method claim, a freshly filled smart contract.

Also note that the smart contract was uploaded to the network 2 days after the funds arrived at it:

Briefly. We sent money to the Ethereum core network to the address of the smart contract that was uploaded to the Ethereum test network. We used the same wallet to upload a completely different smart contract to the main Ethereum network several times until the transaction nonce field reached the value 13, which was just used to download the smart contract to the testnetwork. Then we called up a special method of a new smart contract, which allowed us to withdraw funds to our wallet. It turned out that we uploaded a smart contract to the address where funds were already waiting for it.

PS Vote upvote for the possibility of adding Emoji to articles on Habr

Also popular now: