Skip to content

Instantly share code, notes, and snippets.

@etscrivner
Last active October 18, 2016 14:07
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 etscrivner/10e09dc884f398f0077d0f3cc1072100 to your computer and use it in GitHub Desktop.
Save etscrivner/10e09dc884f398f0077d0f3cc1072100 to your computer and use it in GitHub Desktop.
EIP-150 fork oracle.
pragma solidity ^0.4.2;
contract AmIOnEIP150Fork {
// Tracks whether or not hard fork is effective on this chain.
bool public forked = false;
// Event emitted on updates during fork window to indicate status.
event ForkedStatus(bool forked);
// This function should be called between block X and Y.
function update() {
if (block.number >= 2463000 && block.number <= 2464200) {
uint beforeGas = 0;
uint afterGas = 0;
assembly {
beforeGas := gas
balance
afterGas := gas
}
// Check if gas cost of sequence of instructions above has changed
// from pre-fork constant amount. The constant 27 results from the
// following sequence of instructions encoded in assembly block
// after the first GAS opcode call:
//
// 1 SWAP2 + 1 POP + 1 BALANCE + 1 GAS
// = 3 gas (SWAP2) + 2 gas (POP) + 20 gas (BALANCE) + 2 gas (GAS)
// = 3 gas + 2 gas + 20 gas + 2 gas
// = 27 gas
//
forked = ((beforeGas - afterGas) != 27);
ForkedStatus(forked);
}
}
}
@jimpo
Copy link

jimpo commented Oct 15, 2016

I think the forked variable should have 3 states: not yet determined, forked, or unforked.

The fallback function is throw by default now I think in Solidity >= 4.0.

Maybe put a log in when update determines the fork?

@etscrivner
Copy link
Author

@jimpo The tri-partite forked state doesn't make sense to me, but I may be missing something. To my mind it is a boolean, either the chain you are on is the forked chain or it is not.

@gavofyork
Copy link

yeah - prior to the fork point, it is reasonable to declare it unforked.

@ewiner
Copy link

ewiner commented Oct 18, 2016

@etscrivner did you end up deploying this contract?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment