51 large

如何避免以太坊重放攻击

rubyu2 · 于 发布 · 817 次阅读

对于这次硬分叉,可以通过以下合约来判断自己是否是在正确的分叉上:

contract AmIOnTheFork {
    // Tracks whether hard fork is effective on this chain. True means the fork is passed, false it hasn't.
    bool public forked = false;

    // Dark DAO address
    address constant darkDAO = 0x304a554a310c7e546dfe434669c62820b7d83490;

    // Check the fork condition during creation of the contract.
    // This function should be called between block 1920000 and 1921200.
    // Approximately between 2016-07-20 12:00:00 UTC and 2016-07-20 17:00:00 UTC.
    // After that the status will be locked in.
    function update() {
        if (block.number >= 1920000 && block.number <= 1921200) {
            forked = darkDAO.balance < 3600000 ether;
        }
    }

    // don't accept value transfers
    function() {
        throw;
    }
}

防止重放攻击的合约:

contract ReplaySafeProxy {
    // Tracks if the contract should work on this chain or not.
    bool enabled = false;
    // Fork oracle to use
    AmIOnTheFork amIOnTheFork = AmIOnTheFork(0xe0b8fce1183e31c995b40460e6cb6712fa929f59);
    address target;

    // _target is the address this contract will forward all funds to.
    // forked specifies if it should work on ETH (true) or ETHC (false)
    // Any value transfer to this contract will fail on the other network.
    function ReplaySafeProxy (address _target, bool forked) {
        if (amIOnTheFork.forked() == forked) {
            enabled = true;
        }
        target = _target;
    }

    // Forward value transfers.
    function() {
        if (enabled == false || msg.value == 0 || !target.send(msg.value)) {
            throw;
        }
    }
}

https://medium.com/@timonrapp/how-to-deal-with-the-ethereum-replay-attack-3fd44074a6d8#.lhvrzarzi

  • 暂无回复。