mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-06 07:43:10 +00:00
Initialize blockhashes (#1370)
* Initialize blockhashes * Update comment
This commit is contained in:
parent
06933b1da4
commit
98b5e5be51
@ -1033,9 +1033,10 @@ where
|
||||
block_inputs
|
||||
.set_proof_with_pis_target(&self.block.parent_block_proof, parent_block_proof);
|
||||
} else {
|
||||
// Initialize genesis_state_trie, state_root_after and the block number for correct connection between blocks.
|
||||
// Initialize genesis_state_trie, state_root_after, block hashes and the block number for correct connection between blocks.
|
||||
// Initialize `state_root_after`.
|
||||
let state_trie_root_after_keys = 24..32;
|
||||
let state_trie_root_after_keys =
|
||||
TrieRootsTarget::SIZE..TrieRootsTarget::SIZE + TrieRootsTarget::HASH_SIZE;
|
||||
let mut nonzero_pis = HashMap::new();
|
||||
for (key, &value) in state_trie_root_after_keys
|
||||
.zip_eq(&h256_limbs::<F>(public_values.trie_roots_before.state_root))
|
||||
@ -1057,6 +1058,24 @@ where
|
||||
nonzero_pis.insert(key, value);
|
||||
}
|
||||
|
||||
// Initialize block hashes.
|
||||
let block_hashes_keys = TrieRootsTarget::SIZE * 2 + BlockMetadataTarget::SIZE
|
||||
..TrieRootsTarget::SIZE * 2
|
||||
+ BlockMetadataTarget::SIZE
|
||||
+ BlockHashesTarget::BLOCK_HASHES_SIZE
|
||||
- 8;
|
||||
|
||||
for i in 0..public_values.block_hashes.prev_hashes.len() - 1 {
|
||||
let targets = h256_limbs::<F>(public_values.block_hashes.prev_hashes[i]);
|
||||
for j in 0..8 {
|
||||
nonzero_pis.insert(block_hashes_keys.start + 8 * (i + 1) + j, targets[j]);
|
||||
}
|
||||
}
|
||||
let cur_targets = h256_limbs::<F>(public_values.block_hashes.prev_hashes[255]);
|
||||
for i in 0..8 {
|
||||
nonzero_pis.insert(block_hashes_keys.end + i, cur_targets[i]);
|
||||
}
|
||||
|
||||
// Initialize the block number.
|
||||
let block_number_key = TrieRootsTarget::SIZE * 2 + 6;
|
||||
nonzero_pis.insert(block_number_key, F::NEG_ONE);
|
||||
|
||||
@ -385,7 +385,8 @@ pub(crate) struct TrieRootsTarget {
|
||||
|
||||
impl TrieRootsTarget {
|
||||
/// Number of `Target`s required for all trie hashes.
|
||||
pub(crate) const SIZE: usize = 24;
|
||||
pub(crate) const HASH_SIZE: usize = 8;
|
||||
pub(crate) const SIZE: usize = Self::HASH_SIZE * 3;
|
||||
|
||||
/// Extracts trie hash `Target`s for all tries from the provided public input `Target`s.
|
||||
/// The provided `pis` should start with the trie hashes.
|
||||
|
||||
@ -4,7 +4,7 @@ use std::time::Duration;
|
||||
|
||||
use env_logger::{try_init_from_env, Env, DEFAULT_FILTER_ENV};
|
||||
use eth_trie_utils::partial_trie::{HashedPartialTrie, PartialTrie};
|
||||
use ethereum_types::H256;
|
||||
use ethereum_types::{BigEndianHash, H256};
|
||||
use keccak_hash::keccak;
|
||||
use log::info;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
@ -47,6 +47,8 @@ fn test_empty_txn_list() -> anyhow::Result<()> {
|
||||
transactions_root: transactions_trie.hash(),
|
||||
receipts_root: receipts_trie.hash(),
|
||||
};
|
||||
let mut initial_block_hashes = vec![H256::default(); 256];
|
||||
initial_block_hashes[255] = H256::from_uint(&0x200.into());
|
||||
let inputs = GenerationInputs {
|
||||
signed_txn: None,
|
||||
withdrawals: vec![],
|
||||
@ -66,7 +68,7 @@ fn test_empty_txn_list() -> anyhow::Result<()> {
|
||||
block_bloom_before: [0.into(); 8],
|
||||
block_bloom_after: [0.into(); 8],
|
||||
block_hashes: BlockHashes {
|
||||
prev_hashes: vec![H256::default(); 256],
|
||||
prev_hashes: initial_block_hashes,
|
||||
cur_hash: H256::default(),
|
||||
},
|
||||
addresses: vec![],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user