Skip to content

Commit c395ecd

Browse files
committed
feat test block 260
1 parent 1cb0488 commit c395ecd

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

crates/reth/evm/src/constants.rs

-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ pub const BASEFEE_ADDRESS: Address = address!("540000000000000000000000000000000
1616

1717
/// The address to send transaction priority fees to.
1818
pub const COINBASE_ADDRESS: Address = address!("5400000000000000000000000000000000000011");
19-
20-
/// The maximum depth of the ancestor chain that can be accessed by BLOCKHASH opcode.
21-
pub const MAX_ANCESTOR_DEPTH: u64 = 256;

crates/reth/exex/src/cache_db_provider.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ pub struct CacheDBProvider {
1919
accounts: RefCell<HashMap<Address, AccountInfo>>,
2020
storage: RefCell<HashMap<Address, HashMap<U256, U256>>>,
2121
bytecodes: RefCell<HashSet<Bytes>>,
22+
accessed_blkd_ids: RefCell<HashSet<u64>>,
2223
}
2324

2425
#[derive(Debug)]
2526
pub struct AccessedState {
2627
pub accessed_accounts: HashMap<Address, Vec<Uint<256, 4>>>,
2728
pub accessed_contracts: Vec<Bytes>,
29+
accessed_block_ids: HashSet<u64>,
30+
}
31+
32+
impl AccessedState {
33+
pub fn accessed_block_ids(&self) -> &HashSet<u64> {
34+
&self.accessed_block_ids
35+
}
2836
}
2937

3038
impl CacheDBProvider {
@@ -34,6 +42,7 @@ impl CacheDBProvider {
3442
accounts: Default::default(),
3543
storage: Default::default(),
3644
bytecodes: Default::default(),
45+
accessed_blkd_ids: Default::default(),
3746
}
3847
}
3948

@@ -44,6 +53,7 @@ impl CacheDBProvider {
4453
AccessedState {
4554
accessed_accounts,
4655
accessed_contracts,
56+
accessed_block_ids: self.accessed_blkd_ids.borrow().clone(),
4757
}
4858
}
4959

@@ -130,8 +140,13 @@ impl DatabaseRef for CacheDBProvider {
130140

131141
/// Get block hash by block number.
132142
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
133-
self.provider
143+
let blk_id = self
144+
.provider
134145
.block_hash(number)?
135-
.ok_or(ProviderError::BlockBodyIndicesNotFound(number))
146+
.ok_or(ProviderError::BlockBodyIndicesNotFound(number))?;
147+
148+
self.accessed_blkd_ids.borrow_mut().insert(number);
149+
150+
Ok(blk_id)
136151
}
137152
}

crates/reth/exex/src/prover_exex.rs

+29-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{collections::HashMap, sync::Arc};
1+
use std::{
2+
collections::{HashMap, HashSet},
3+
sync::Arc,
4+
};
25

36
use alloy_consensus::Header;
47
use alloy_rpc_types::{serde_helpers::JsonStorageKey, BlockNumHash, EIP1186AccountProofResponse};
@@ -15,7 +18,6 @@ use reth_trie_common::KeccakKeyHasher;
1518
use revm_primitives::alloy_primitives::{Address, B256};
1619
use strata_proofimpl_evm_ee_stf::{mpt::proofs_to_tries, EvmBlockStfInput};
1720
use strata_reth_db::WitnessStore;
18-
use strata_reth_evm::constants::MAX_ANCESTOR_DEPTH;
1921
use tracing::{debug, error};
2022

2123
use crate::{
@@ -140,7 +142,7 @@ fn extract_zkvm_input<Node: FullNodeComponents<Types: NodeTypes<Primitives = Eth
140142

141143
let mut parent_proofs: HashMap<Address, EIP1186AccountProofResponse> = HashMap::new();
142144
let mut current_proofs: HashMap<Address, EIP1186AccountProofResponse> = HashMap::new();
143-
let contracts = accessed_states.accessed_contracts;
145+
let contracts = accessed_states.accessed_contracts.clone();
144146

145147
// Accumulate account proof of account in previous block
146148
for (accessed_address, accessed_slots) in accessed_states.accessed_accounts.iter() {
@@ -186,14 +188,8 @@ fn extract_zkvm_input<Node: FullNodeComponents<Types: NodeTypes<Primitives = Eth
186188
)
187189
.expect("Proof to tries infallible");
188190

189-
// Get ancestor headers
190-
let ancestor_headers = get_ancestor_headers(ctx, current_block_idx)?;
191-
192-
println!(
193-
"Abishek got ancestor_headers: num {:?} {:?}",
194-
ancestor_headers.len(),
195-
ancestor_headers
196-
);
191+
let ancestor_headers =
192+
get_ancestor_headers(ctx, current_block_idx, accessed_states.accessed_block_ids())?;
197193

198194
let input = EvmBlockStfInput {
199195
beneficiary: current_block.header.beneficiary,
@@ -213,21 +209,30 @@ fn extract_zkvm_input<Node: FullNodeComponents<Types: NodeTypes<Primitives = Eth
213209
Ok(input)
214210
}
215211

216-
fn get_ancestor_headers<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>>(
212+
fn get_ancestor_headers<Node>(
217213
ctx: &ExExContext<Node>,
218-
block_idx: u64,
219-
) -> eyre::Result<Vec<Header>> {
220-
let oldest_parent = block_idx.saturating_sub(MAX_ANCESTOR_DEPTH);
221-
let prev_block_idx = block_idx.saturating_sub(1);
222-
let provider = ctx.provider();
223-
let mut headers = Vec::with_capacity((block_idx - oldest_parent) as usize);
214+
current_blk_idx: u64,
215+
accessed_block_idxs: &HashSet<u64>,
216+
) -> eyre::Result<Vec<Header>>
217+
where
218+
Node: FullNodeComponents,
219+
Node::Types: NodeTypes<Primitives = EthPrimitives>,
220+
{
221+
let Some(oldest_parent_idx) = accessed_block_idxs.iter().copied().min_by(|a, b| a.cmp(b))
222+
else {
223+
return Ok(Vec::new());
224+
};
224225

225-
for block_num in (oldest_parent..prev_block_idx).rev() {
226-
let block = provider
227-
.block_by_number(block_num)?
228-
.ok_or_else(|| eyre!("Block not found for block number {block_num}"))?;
229-
headers.push(block.header);
230-
}
226+
let provider = ctx.provider();
227+
let headers = (oldest_parent_idx..current_blk_idx.saturating_sub(1))
228+
.rev()
229+
.map(|block_num| {
230+
provider
231+
.block_by_number(block_num)?
232+
.map(|block| block.header)
233+
.ok_or_else(|| eyre!("Block not found for block number {block_num}"))
234+
})
235+
.collect::<eyre::Result<Vec<_>>>()?;
231236

232237
Ok(headers)
233238
}

functional-tests/load/reth/contracts/BlockhashOpCode.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ contract BlockhashOpCode {
55
bytes32 public lastBlockHash;
66

77
function updateBlockHash() external {
8-
bytes32 lastBlockHash1 = blockhash(block.number - 1);
9-
bytes32 lastBlockHash2 = blockhash(block.number - 2);
8+
bytes32 lastBlockHash1 = blockhash(block.number - 10);
9+
bytes32 lastBlockHash2 = blockhash(block.number - 50);
1010
lastBlockHash = lastBlockHash1 ^ lastBlockHash2;
1111
}
1212
}

functional-tests/tests/prover/prover_el_dispatch.py

-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from utils import (
66
el_slot_to_block_commitment,
77
wait_for_proof_with_time_out,
8-
wait_until,
98
wait_until_with_value,
109
)
1110
from utils.eth import make_native_token_transfer
@@ -56,12 +55,6 @@ def main(self, ctx: flexitest.RunContext):
5655
start_block = el_slot_to_block_commitment(reth_rpc, ee_prover_params["start_block"])
5756
end_block = el_slot_to_block_commitment(reth_rpc, ee_prover_params["end_block"])
5857

59-
# Wait until the prover client reports readiness
60-
wait_until(
61-
lambda: prover_client_rpc.dev_strata_getReport() is not None,
62-
error_with="Prover did not start on time",
63-
)
64-
6558
task_ids = prover_client_rpc.dev_strata_proveElBlocks((start_block, end_block))
6659
self.debug(f"Prover task IDs received: {task_ids}")
6760

0 commit comments

Comments
 (0)