Skip to content

Commit

Permalink
Added EIP 96 blockhash getter
Browse files Browse the repository at this point in the history
  • Loading branch information
vub authored and vub committed Apr 26, 2017
1 parent 40a2df9 commit b0c1635
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions eip_96_blockhash_getter.se
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b0c1635

Please sign in to comment.