Ethereum icon indicating copy to clipboard operation
Ethereum copied to clipboard

Is it safe to rely on blockhash() in EventStorage.sol

Open akolotov opened this issue 7 years ago • 3 comments
trafficstars

I have gone through your idea implemented in EventStorage.sol and found that you rely on blockhash()

https://github.com/figs999/Ethereum/blob/e04501d3aa9d90f209255bb65bcb0cb37975251d/EventStorage.sol#L166

In other words you assume that blockhash() will always return a correct value for any correct block number. But at the same moment I can read in Solidity documentation that

The block hashes are not available for all blocks for scalability reasons.
You can only access the hashes of the most recent 256 blocks, all other values will be zero.

(https://solidity.readthedocs.io/en/v0.4.24/units-and-global-variables.html#block-and-transaction-properties)

So, judging on this your code will work only if the block we are referring has the number greater than (N-256) where N is the current block number. Is it known limitation or Solidity documentation is obsoleted?

akolotov avatar May 20 '18 13:05 akolotov

This is a known limitation of the Solidity language, so you would only be able to process the most recent 256 block headers. What you could do though is create a contract that acts as a store of block headers and their contents allowing you to verify block hashes against blocks outside of the 256 limit

bonedaddy avatar Jun 28 '18 22:06 bonedaddy

Thanks! Does it mean that we need to have an oracle to invoke contract every time when new block appeared as so the new block header could be stored?

akolotov avatar Jun 28 '18 22:06 akolotov

I believe that would be required if you want to analyze blocks outside of the 256 block window. However I imagine that would be expensive as hell.

bonedaddy avatar Jun 28 '18 22:06 bonedaddy