-
Notifications
You must be signed in to change notification settings - Fork 125
Calculate and check previous 256 block hashes #107
Comments
@Brechtpd The initial calculation of total number of rows needed (assuming no implications arise) is ~170k. Is that acceptable? |
Yep, fits in a 2**18 circuit which is very reasonable. |
Asynchronous hash calculation: If there's a possibility to parallelize the hash calculation process, considering an asynchronous approach to this task can be beneficial. For instance, initiating hash computations for multiple blocks simultaneously can expedite the process. import threading Function to calculate the hash of a blockdef calculate_block_hash(block_header): Function for asynchronously calculating block hashesdef async_calculate_block_hashes(block_headers):
Function to calculate the hash of a block and store it in a dictionarydef calculate_and_store_block_hash(block_hashes, block_number, block_header): Example usageblock_headers = { block_hashes = async_calculate_block_hashes(block_headers) |
ORRRRRRR Parallel computations: If possible, parallel computations can be utilized for calculating block hashes. For instance, the process can be divided into multiple parts and distributed among several processor cores or even across multiple computers. import concurrent.futures Function to calculate the hash of a blockdef calculate_block_hash(block_header): Function for parallel hash calculations of blocksdef parallel_calculate_block_hashes(block_headers): Example usageblock_headers = { block_hashes = parallel_calculate_block_hashes(block_headers) |
Describe the feature you would like
Calculate all previous 256 block hashes. We need that because these last 256 blockhashes are exposed directly to the smart contracts using an opcode, and so we of course need to make sure the correct data is returned when that opcode is called.
In the circuits we only have access to 2 blockhashes: the previous one and the current one. The calculation for the current blockhash is developed in #79.
Since the previous blockhash encapsulates the previous block header, we don't need to check the correctness of the previous block header values. We only need to check the consistency of the block hash chain, that is for the block
i
block_hash[i]
=HASH(block_header[i])
prev_block_hash[i+1]
=block_hash[i]
All the previous block hashes will be stored in the block table with the format:
(
BlockContextFieldTag::BlockHash
,block_number
,block_hash.expr()
).Additional context
No response
The text was updated successfully, but these errors were encountered: