forked from ethereum/research
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
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
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() |