You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Report: Inconsistent Historical Block Hash Retrieval On Smart Contracts
Summary
The blockhash() function is only returning the hash for the immediate parent of the current block, while returning 0x0000000000000000000000000000000000000000000000000000000000000000 for other recent block numbers within the expected range of 256 blocks. The issue was identified when attempting to retrieve the previous 10 block hashes via a smart contract.
Deploy a smart contract on the Sei Network that attempts to retrieve the previous 10 block hashes using the blockhash() function.
Call the contract's function to retrieve and display the block hashes.
Observe the returned values for block hashes.
Expected Behavior
The blockhash() function should correctly return the hashes for the previous 10 blocks, including the immediate parent and preceding blocks within the last 256 blocks.
Actual Behavior
The blockhash() function correctly returns the hash for the immediate parent of the current block (i.e., block.number - 1), but returns 0x0000000000000000000000000000000000000000000000000000000000000000 for other recent blocks within the last 10 blocks.
This behavior indicates that only the parent block's hash is accessible, while the hashes of other recent blocks within the expected range are not being returned correctly.
Impact
This issue limits the functionality of applications that rely on retrieving multiple recent block hashes, such as those used in randomness generation, historical data verification, and other decentralized applications (dApps) that require accurate and consistent block state information.
Recommendation
Investigate the configuration and state management of the Sei Network’s EVM implementation to ensure that the blockhash() function is fully compliant with the expected behavior on EVM-compatible chains, allowing retrieval of block hashes for the last 256 blocks.
Example Code
// SPDX-License-Identifier: MITpragma solidity^0.8.0;
contractBlockInfo {
function getBlockInfo()
publicviewreturns (
uint256currentBlockNumber,
bytes32currentBlockHash,
uint256previousBlockNumber,
bytes32previousBlockHash,
bytes32[10] memorylastTenBlockHashes
)
{
currentBlockNumber =block.number;
currentBlockHash =blockhash(block.number);
previousBlockNumber =block.number-1;
previousBlockHash =blockhash(block.number-1);
for (uint i =0; i <10; i++) {
if (block.number> i) {
lastTenBlockHashes[i] =blockhash(block.number- i);
} else {
lastTenBlockHashes[i] =bytes32(0); // Fill with zeroes if block number is out of range
}
}
}
}
const{ ethers }=require('ethers');asyncfunctionmain(){// Initialize the JSON-RPC providerconstjsonRpcProvider=newethers.providers.JsonRpcProvider("https://evm-rpc.sei-apis.com");// Contract address where the BlockInfo contract is deployedconstcontractAddress="0xFF720A74656ce29A07ADF1c249e1Ca3978f8A251";// Replace with your contract's address// ABI for the BlockInfo contractconstblockInfoAbi=["function getBlockInfo() view returns (uint256, bytes32, uint256, bytes32, bytes32[10])"];// Initialize the contractconstblockInfoContract=newethers.Contract(contractAddress,blockInfoAbi,jsonRpcProvider);// Call the getBlockInfo functionconsole.log("Fetching block information...");constblockInfo=awaitblockInfoContract.getBlockInfo();// Destructure the returned valuesconst[currentBlockNumber,currentBlockHash,previousBlockNumber,previousBlockHash,lastTenBlockHashes]=blockInfo;// Display the fetched block informationconsole.log("Last 10 Block Hashes:");lastTenBlockHashes.forEach((hash,index)=>{console.log(`Block ${currentBlockNumber-index}: ${hash}`);});}main().catch(console.error);
Bug Report: Inconsistent Historical Block Hash Retrieval On Smart Contracts
Summary
The
blockhash()
function is only returning the hash for the immediate parent of the current block, while returning0x0000000000000000000000000000000000000000000000000000000000000000
for other recent block numbers within the expected range of 256 blocks. The issue was identified when attempting to retrieve the previous 10 block hashes via a smart contract.Environment
v22.4.1
5.7.2
https://evm-rpc.sei-apis.com
0xFF720A74656ce29A07ADF1c249e1Ca3978f8A251
blockhash()
Steps to Reproduce
blockhash()
function.Expected Behavior
blockhash()
function should correctly return the hashes for the previous 10 blocks, including the immediate parent and preceding blocks within the last 256 blocks.Actual Behavior
blockhash()
function correctly returns the hash for the immediate parent of the current block (i.e.,block.number - 1
), but returns0x0000000000000000000000000000000000000000000000000000000000000000
for other recent blocks within the last 10 blocks.Impact
Recommendation
blockhash()
function is fully compliant with the expected behavior on EVM-compatible chains, allowing retrieval of block hashes for the last 256 blocks.Example Code
The text was updated successfully, but these errors were encountered: