Skip to content

Commit e65dcb4

Browse files
committed
feat test block 260
1 parent 8898628 commit e65dcb4

File tree

8 files changed

+66
-47
lines changed

8 files changed

+66
-47
lines changed

Cargo.lock

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ version = "0.1.0"
66
[dependencies]
77
strata-proofimpl-evm-ee-stf.workspace = true
88
strata-reth-db.workspace = true
9-
strata-reth-evm.workspace = true
109
strata-reth-node.workspace = true
1110

1211
alloy-consensus.workspace = true

crates/reth/exex/src/cache_db_provider.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@ 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 {
26-
pub accessed_accounts: HashMap<Address, Vec<Uint<256, 4>>>,
27-
pub accessed_contracts: Vec<Bytes>,
27+
accessed_accounts: HashMap<Address, Vec<Uint<256, 4>>>,
28+
accessed_contracts: Vec<Bytes>,
29+
accessed_block_idxs: HashSet<u64>,
30+
}
31+
32+
impl AccessedState {
33+
pub fn accessed_block_idxs(&self) -> &HashSet<u64> {
34+
&self.accessed_block_idxs
35+
}
36+
37+
pub fn accessed_accounts(&self) -> &HashMap<Address, Vec<Uint<256, 4>>> {
38+
&self.accessed_accounts
39+
}
40+
41+
pub fn accessed_contracts(&self) -> &Vec<Bytes> {
42+
&self.accessed_contracts
43+
}
2844
}
2945

3046
impl CacheDBProvider {
@@ -34,6 +50,7 @@ impl CacheDBProvider {
3450
accounts: Default::default(),
3551
storage: Default::default(),
3652
bytecodes: Default::default(),
53+
accessed_blkd_ids: Default::default(),
3754
}
3855
}
3956

@@ -44,6 +61,7 @@ impl CacheDBProvider {
4461
AccessedState {
4562
accessed_accounts,
4663
accessed_contracts,
64+
accessed_block_idxs: self.accessed_blkd_ids.borrow().clone(),
4765
}
4866
}
4967

@@ -130,8 +148,13 @@ impl DatabaseRef for CacheDBProvider {
130148

131149
/// Get block hash by block number.
132150
fn block_hash_ref(&self, number: u64) -> Result<B256, Self::Error> {
133-
self.provider
151+
let blk_id = self
152+
.provider
134153
.block_hash(number)?
135-
.ok_or(ProviderError::BlockBodyIndicesNotFound(number))
154+
.ok_or(ProviderError::BlockBodyIndicesNotFound(number))?;
155+
156+
self.accessed_blkd_ids.borrow_mut().insert(number);
157+
158+
Ok(blk_id)
136159
}
137160
}

crates/reth/exex/src/prover_exex.rs

+34-26
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,10 +142,10 @@ 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
146-
for (accessed_address, accessed_slots) in accessed_states.accessed_accounts.iter() {
148+
for (accessed_address, accessed_slots) in accessed_states.accessed_accounts().iter() {
147149
let slots: Vec<B256> = accessed_slots
148150
.iter()
149151
.map(|el| B256::from_slice(&el.to_be_bytes::<32>()))
@@ -162,7 +164,7 @@ fn extract_zkvm_input<Node: FullNodeComponents<Types: NodeTypes<Primitives = Eth
162164
}
163165

164166
// Accumulate account proof of account in current block
165-
for (accessed_address, accessed_slots) in accessed_states.accessed_accounts.iter() {
167+
for (accessed_address, accessed_slots) in accessed_states.accessed_accounts().iter() {
166168
let slots: Vec<B256> = accessed_slots
167169
.iter()
168170
.map(|el| B256::from_slice(&el.to_be_bytes::<32>()))
@@ -186,14 +188,11 @@ 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 = get_ancestor_headers(
192+
ctx,
193+
current_block_idx,
194+
accessed_states.accessed_block_idxs(),
195+
)?;
197196

198197
let input = EvmBlockStfInput {
199198
beneficiary: current_block.header.beneficiary,
@@ -213,21 +212,30 @@ fn extract_zkvm_input<Node: FullNodeComponents<Types: NodeTypes<Primitives = Eth
213212
Ok(input)
214213
}
215214

216-
fn get_ancestor_headers<Node: FullNodeComponents<Types: NodeTypes<Primitives = EthPrimitives>>>(
215+
fn get_ancestor_headers<Node>(
217216
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);
217+
current_blk_idx: u64,
218+
accessed_block_idxs: &HashSet<u64>,
219+
) -> eyre::Result<Vec<Header>>
220+
where
221+
Node: FullNodeComponents,
222+
Node::Types: NodeTypes<Primitives = EthPrimitives>,
223+
{
224+
let Some(oldest_parent_idx) = accessed_block_idxs.iter().copied().min_by(|a, b| a.cmp(b))
225+
else {
226+
return Ok(Vec::new());
227+
};
224228

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-
}
229+
let provider = ctx.provider();
230+
let headers = (oldest_parent_idx..current_blk_idx.saturating_sub(1))
231+
.rev()
232+
.map(|block_num| {
233+
provider
234+
.block_by_number(block_num)?
235+
.map(|block| block.header)
236+
.ok_or_else(|| eyre!("Block not found for block number {block_num}"))
237+
})
238+
.collect::<eyre::Result<Vec<_>>>()?;
231239

232240
Ok(headers)
233241
}

functional-tests/tests/prover/prover_el_blockhash_opcode.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from web3 import Web3
44

55
from envs import testenv
6-
from load.reth.transaction import SmartContracts
76
from utils import (
87
el_slot_to_block_commitment,
98
wait_for_proof_with_time_out,
109
wait_until_with_value,
1110
)
11+
from utils.transaction import SmartContracts
1212

1313

1414
@flexitest.register
15-
class ElShaPrecompileTest(testenv.StrataTester):
15+
class ElBlockhashOpcodeTest(testenv.StrataTester):
1616
def __init__(self, ctx: flexitest.InitContext):
1717
install_solc(version="0.8.16")
1818
set_solc_version("0.8.16")

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

functional-tests/tests/prover/prover_el_precompiles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
@flexitest.register
15-
class ElShaPrecompileTest(testenv.StrataTester):
15+
class ElPrecompileTest(testenv.StrataTester):
1616
def __init__(self, ctx: flexitest.InitContext):
1717
install_solc(version="0.8.16")
1818
set_solc_version("0.8.16")

0 commit comments

Comments
 (0)