Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2015 20:08
Show Gist options
  • Select an option

  • Save anonymous/236177b10dcb53e4e14f to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/236177b10dcb53e4e14f to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Oct 9, 2015.
    38 changes: 38 additions & 0 deletions RevokableOwned
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@

    import "owned";

    contract RevokableOwned is owned {
    address previousOwner;
    uint8 revokableV;
    bytes32 revokableR;
    bytes32 revokableS;

    // In order to make a contracts ownership revokeable you must
    // provide a signature VRS of a master passphrase which has been
    // hashed using SHA3 twice. This can only be done by the current owner.
    function makeRevokable(uint8 _v, bytes32 _r, bytes32 _s) onlyowner {
    revokableV = _v;
    revokableR = _r;
    revokableS = _s;
    }

    // All that is needed to revoke ownership of the contract is the twice
    // hashed passphrase, which can be submitted by any sender.
    function revoke(bytes32 twiceHashedPassphrase) returns (bool success) {
    if (revokableV != uint8(0)
    && owner != address(0)
    && ecrecover(twiceHashedPassphrase, revokableV, revokableR, revokableS) == owner) {
    previousOwner = owner;
    owner = address(0);
    return true;
    }
    }

    // In order to reclaim ownership of a contract who's ownership has been revoked
    // You need to be able to provide a once hashed version of the passphrase.
    function reclaim(bytes32 onceHashedPassphrase) {
    bytes32 data = sha3(onceHashedPassphrase);
    address signer = ecrecover(data, revokableV, revokableR, revokableS);
    if (signer == previousOwner) owner = msg.sender;
    }
    }