Last active
October 18, 2016 14:07
-
-
Save etscrivner/10e09dc884f398f0077d0f3cc1072100 to your computer and use it in GitHub Desktop.
EIP-150 fork oracle.
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
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah - prior to the fork point, it is reasonable to declare it unforked.