Ethereum
Ethereum copied to clipboard
Is it safe to rely on blockhash() in EventStorage.sol
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?
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
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?
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.