4

I am trying to write a smart contract for Crowdsale. What extra measures should one keep in mind during smart contract development to avoid replay attacks (after the hard fork of block 1,920,000)?

  • What contract are you writing and what's your concern? – eth Aug 3 '16 at 23:16
  • I have added in my question. – Aniket Aug 10 '16 at 6:32
  • It's probably still too broad but I'll reopen (you can also click "reopen" in the future). Remember, the better the question, the better the answers you'll probably get. – eth Aug 10 '16 at 9:08
  • Thanks. Actually i am new to this technology and i am working using testnet, so asking question is the only way to be fully prepared before going on livenet. – Aniket Aug 10 '16 at 10:18
2

When a user sends a transaction to your contract using Ethereum (ETH), if that user also has ETC in the same account in the Ethereum Classic Blockchain (ETC), then that transaction could be replayed in the Ethereum Classic Blockchain (ETC) with unexpected results.

To avoid this, you can upload your contract to both Blockchains with a modifier in your functions that throws an exception when it is executed in the Ethereum Classic Blockchain (ETC).

Example:

contract AmIOnTheFork {
    function forked() constant returns(bool);
}

contract YOUR_CONTRACT{
    // Fork oracle to use
    AmIOnTheFork amIOnTheFork = AmIOnTheFork(0x2bd2326c993dfaef84f696526064ff22eba5b362);

    // Only allows execution in the forked chain (ETH)
    modifier only_eth_chain() {
        if (!amIOnTheFork.forked()) throw;
        _
    }

    function your_function()
        only_eth_chain()
    {
      // YOUR_FUNCTION_CODE
    }
}

This way, if your user wants to execute the your_function function, he will send a transaction in the Ethereum Blockchain (ETH). That transaction will be executed as usual, but if the transaction is replayed in the Ethereum Classic Blockchain (ETC), the transaction replayed will not be accepted and the ETC sent will be given back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.