📜 ⬆️ ⬇️

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



It all started with the problem we encountered in BitClave : during the preparation of our ICO, a certain amount of cryptocurrency ETH (broadcast) was sent to the address of the smart contract, which had previously been transferred to the Ethereum test network. The money was sent in the main network to an address that is not related to a single 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 with the fact that my colleague asked me a private key to the address 0x9c86825280b1d6c7dB043D4CC86E1549990149f9 . I sent him a private key to the address 0x231A3925A014EF0a11a0DC5c33bF7cdB3bd9919f , from which the smart contract was loaded 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 loaded into the Ethereum network has a unique address, which at first glance looks like random, but I found out exactly how the address is generated when it is downloaded to the network: ethereum.stackexchange.com/a/761/3032 . Simply put, the load address is the hash of the sender address of the transaction and the value of nonce (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 on the test network) to load a new smart contract into the main network. I have developed a smart contract of the simplest wallet, which allows only to display the balance and transfer the lost funds:

 contract SimpleWallet is Ownable { function () public payable { } function weiBalance() public constant returns(uint256) { return this.balance; } function claim(address destination) public onlyOwner { destination.transfer(this.balance); } } 

Then I found a transaction in the test network, through which loading of the original contract was made: 0xc4c32a3d97dbd691eb3646e4c0c404e899a632010bc48d7182d75bef6803b7bc and found that the nonce field is equal to 13. I joined the purse at 0.03 ETH on the main network and began to fill in the new smart contract over and over again, until 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 loaded 2 different smart contracts into 2 different networks at identical addresses with a difference of 5 days:


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

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



Briefly. We sent money in the main Ethereum network to the address of a smart contract that was uploaded to the Ethereum test network. We used the same wallet to load a completely different smart contract into the main Ethereum network several times, until the transaction had a nonce field that reached 13, which was just used to load the smart contract into the test network. Then we called a special method of the 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 the funds were waiting for him

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

Source: https://habr.com/ru/post/341518/


All Articles