From b0c163521d8881c3104e7da1eacf5d2f3d7de86d Mon Sep 17 00:00:00 2001 From: vub Date: Wed, 26 Apr 2017 02:36:26 -0400 Subject: [PATCH] Added EIP 96 blockhash getter --- eip_96_blockhash_getter.se | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 eip_96_blockhash_getter.se diff --git a/eip_96_blockhash_getter.se b/eip_96_blockhash_getter.se new file mode 100644 index 0000000..adf0e71 --- /dev/null +++ b/eip_96_blockhash_getter.se @@ -0,0 +1,23 @@ +# Setting the block hash +if msg.sender == 2**160 - 2: + with prev_block_number = block.number - 1: + # Use storage fields 0..255 to store the last 256 hashes + ~sstore(prev_block_number % 256, ~calldataload(0)) + # Use storage fields 256..511 to store the hashes of the last 256 + # blocks with block.number % 256 == 0 + if not prev_block_number % 256: + ~sstore(256 + (prev_block_number / 256) % 256, ~calldataload(0)) + # Use storage fields 512..767 to store the hashes of the last 256 + # blocks with block.number % 65536 == 0 + if not prev_block_number % 65536: + ~sstore(512 + (prev_block_number / 65536) % 256, ~calldataload(0)) +# Getting the block hash +else: + if block.number - ~calldataload(0) <= 256: + return(~sload(~calldataload(0) % 256)) + elif not block.number % 256 and block.number - ~calldataload(0) <= 65536: + return(~sload(256 + (~calldataload(0) / 256) % 256)) + elif not block.number % 65536 and block.number - ~calldataload(0) <= 16777216: + return(~sload(512 + (~calldataload(0) / 65536) % 256)) + else: + ~invalid()