Skip to content

Commit b0cdf7d

Browse files
authored
refactor(l1): rename ExecutionDB to ProverDB. (#2770)
**Motivation** To have a clearer name.
1 parent 20262db commit b0cdf7d

File tree

21 files changed

+190
-194
lines changed

21 files changed

+190
-194
lines changed

crates/l2/docs/prover.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ These inputs are required for proof generation, but not all of them are committe
258258
#### Execution witness
259259
The purpose of the execution witness is to allow executing the blocks without having access to the whole Ethereum state, as it wouldn't fit in a zkVM program. It contains only the state values needed during the execution.
260260

261-
An execution witness (represented by the `ExecutionDB` type) contains:
261+
An execution witness (represented by the `ProverDB` type) contains:
262262
1. all the initial state values (accounts, code, storage, block hashes) that will be read or written to during the blocks' execution.
263263
2. Merkle Patricia Trie (MPT) proofs that prove the inclusion or exclusion of each initial value in the initial world state trie.
264264

265265
An execution witness is created from a prior execution of the blocks. Before proving, we need to:
266266
1. execute the blocks (also called "pre-execution").
267267
2. log every initial state value accessed or updated during this execution.
268-
3. store each logged value in an in-memory key-value database (`ExecutionDB`, implemented just using hash maps).
268+
3. store each logged value in an in-memory key-value database (`ProverDB`, implemented just using hash maps).
269269
4. retrieve an MPT proof for each value, linking it (or its non-existence) to the initial state root hash.
270270

271271
Steps 1-3 are straightforward. Step 4 involves more complex logic due to potential issues when restructuring the pruned state trie after value removals. In sections [initial state validation](#step-1-initial-state-validation) and [final state validation](#step-3-final-state-validation) we explain what are pruned tries and in which case they get restructured.
@@ -319,7 +319,7 @@ These three components are specific additions for ethrex's L2 protocol, layered
319319
For more details, refer to [Overview](overview.md), [Withdrawals](withdrawals.md), and [State diffs](state_diffs.md).
320320

321321
#### Step 1: initial state validation
322-
The program validates the `ExecutionDB` by iterating over each provided state value (stored in hash maps) and verifying its MPT proof against the initial state hash (obtained from the first block's parent block header input). This is the role of the `verify_db()` function (to link the values with the proofs). We could instead directly decode the data from the MPT proofs on each EVM read/write, although this would incur performance costs.
322+
The program validates the `ProverDB` by iterating over each provided state value (stored in hash maps) and verifying its MPT proof against the initial state hash (obtained from the first block's parent block header input). This is the role of the `verify_db()` function (to link the values with the proofs). We could instead directly decode the data from the MPT proofs on each EVM read/write, although this would incur performance costs.
323323

324324
Having the initial state proofs (paths from the root to each relevant leaf) is equivalent to having a relevant subset of the world state trie and storage tries – a set of "pruned tries". This allows operating directly on these pruned tries (adding, removing, modifying values) during execution.
325325

crates/l2/prover/bench/src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use std::{
44
};
55

66
use ethrex_common::types::{Block, BlockHeader};
7-
use ethrex_vm::ExecutionDB;
7+
use ethrex_vm::ProverDB;
88

99
use serde::{Deserialize, Serialize};
1010

1111
#[derive(Serialize, Deserialize)]
1212
pub struct Cache {
1313
pub block: Block,
1414
pub parent_block_header: BlockHeader,
15-
pub db: ExecutionDB,
15+
pub db: ProverDB,
1616
}
1717

1818
pub fn load_cache(block_number: usize) -> Result<Cache, String> {

crates/l2/prover/bench/src/rpc/db.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ethrex_levm::db::Database as LevmDatabase;
1313
use ethrex_storage::{hash_address, hash_key};
1414
use ethrex_trie::{Node, PathRLP, Trie};
1515
use ethrex_vm::backends::levm::{CacheDB, LEVM};
16-
use ethrex_vm::{ExecutionDB, ExecutionDBError};
16+
use ethrex_vm::{ProverDB, ProverDBError};
1717
use futures_util::future::join_all;
1818
use tokio_utils::RateLimiter;
1919

@@ -234,7 +234,7 @@ impl RpcDB {
234234
})
235235
}
236236

237-
pub fn to_exec_db(&self, block: &Block) -> Result<ethrex_vm::ExecutionDB, ExecutionDBError> {
237+
pub fn to_exec_db(&self, block: &Block) -> Result<ethrex_vm::ProverDB, ProverDBError> {
238238
// TODO: Simplify this function and potentially merge with the implementation for
239239
// StoreWrapper.
240240

@@ -409,7 +409,7 @@ impl RpcDB {
409409
})
410410
.collect();
411411

412-
Ok(ExecutionDB {
412+
Ok(ProverDB {
413413
accounts,
414414
code,
415415
storage,

crates/l2/prover/src/backends/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn execution_program(input: ProgramInput) -> Result<ProgramOutput, Box<dyn std::
8181
)?;
8282

8383
// Execute block
84-
let mut vm = Evm::from_execution_db(db.clone());
84+
let mut vm = Evm::from_prover_db(db.clone());
8585
let result = vm.execute_block(&block)?;
8686
let receipts = result.receipts;
8787
let account_updates = vm.get_state_transitions()?;

crates/l2/prover/tests/perf_zkvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async fn setup() -> (ProgramInput, Block) {
6464
.unwrap()
6565
.unwrap();
6666

67-
let db = Evm::to_execution_db(&store.clone(), &vec![block_to_prove.clone()])
67+
let db = Evm::to_prover_db(&store.clone(), &vec![block_to_prove.clone()])
6868
.await
6969
.unwrap();
7070

crates/l2/prover/zkvm/interface/pico/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn main() {
6161
.expect("invalid block");
6262

6363
// Execute block
64-
let mut vm = Evm::from_execution_db(db.clone());
64+
let mut vm = Evm::from_prover_db(db.clone());
6565
let result = vm.execute_block(&block).expect("failed to execute block");
6666
let receipts = result.receipts;
6767
let account_updates = vm.get_state_transitions()?;

crates/l2/prover/zkvm/interface/risc0/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn main() {
5353
validate_block(&block, &parent_header, &db.chain_config).expect("invalid block");
5454

5555
// Execute block
56-
let mut vm = Evm::from_execution_db(db.clone());
56+
let mut vm = Evm::from_prover_db(db.clone());
5757
let result = vm.execute_block(&block).expect("failed to execute block");
5858
let receipts = result.receipts;
5959
let account_updates = vm

crates/l2/prover/zkvm/interface/sp1/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn main() {
6060
.expect("invalid block");
6161

6262
// Execute block
63-
let mut vm = Evm::from_execution_db(db.clone());
63+
let mut vm = Evm::from_prover_db(db.clone());
6464
let result = vm.execute_block(&block).expect("failed to execute block");
6565
let receipts = result.receipts;
6666
let account_updates = vm

crates/l2/prover/zkvm/interface/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub mod io {
2424
types::{Block, BlockHeader},
2525
H256,
2626
};
27-
use ethrex_vm::ExecutionDB;
27+
use ethrex_vm::ProverDB;
2828
use serde::{de::DeserializeOwned, Deserialize, Serialize};
2929
use serde_with::{serde_as, DeserializeAs, SerializeAs};
3030

@@ -39,7 +39,7 @@ pub mod io {
3939
#[serde_as(as = "SerdeJSON")]
4040
pub parent_block_header: BlockHeader,
4141
/// database containing only the data necessary to execute
42-
pub db: ExecutionDB,
42+
pub db: ProverDB,
4343
/// value used to calculate base fee
4444
pub elasticity_multiplier: u64,
4545
}
@@ -110,7 +110,7 @@ pub mod trie {
110110
use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, error::RLPDecodeError};
111111
use ethrex_storage::{hash_address, hash_key, AccountUpdate};
112112
use ethrex_trie::{Trie, TrieError};
113-
use ethrex_vm::ExecutionDB;
113+
use ethrex_vm::ProverDB;
114114
use thiserror::Error;
115115

116116
#[derive(Debug, Error)]
@@ -126,7 +126,7 @@ pub mod trie {
126126
}
127127

128128
pub fn verify_db(
129-
db: &ExecutionDB,
129+
db: &ProverDB,
130130
state_trie: &Trie,
131131
storage_tries: &HashMap<H160, Trie>,
132132
) -> Result<bool, Error> {

crates/l2/sequencer/proof_coordinator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ethrex_common::{
1313
use ethrex_rpc::clients::eth::EthClient;
1414
use ethrex_storage::Store;
1515
use ethrex_storage_rollup::StoreRollup;
16-
use ethrex_vm::{Evm, EvmError, ExecutionDB};
16+
use ethrex_vm::{Evm, EvmError, ProverDB};
1717
use serde::{Deserialize, Serialize};
1818
use std::{fmt::Debug, net::IpAddr};
1919
use tokio::{
@@ -30,7 +30,7 @@ use super::utils::sleep_random;
3030
pub struct ProverInputData {
3131
pub blocks: Vec<Block>,
3232
pub parent_block_header: BlockHeader,
33-
pub db: ExecutionDB,
33+
pub db: ProverDB,
3434
pub elasticity_multiplier: u64,
3535
}
3636

@@ -321,10 +321,10 @@ impl ProofCoordinator {
321321

322322
let blocks = self.fetch_blocks(block_numbers).await?;
323323

324-
// Create execution_db
325-
let db = Evm::to_execution_db(&self.store.clone(), &blocks)
324+
// Create prover_db
325+
let db = Evm::to_prover_db(&self.store.clone(), &blocks)
326326
.await
327-
.map_err(EvmError::ExecutionDB)?;
327+
.map_err(EvmError::ProverDB)?;
328328

329329
// Get the block_header of the parent of the first block
330330
let parent_hash = blocks

crates/l2/utils/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use ethrex_blockchain::error::ChainError;
22
use ethrex_storage::error::StoreError;
3-
use ethrex_vm::ExecutionDBError;
3+
use ethrex_vm::ProverDBError;
44
use keccak_hash::H256;
55

66
use super::config::errors::ConfigError;
@@ -15,8 +15,8 @@ pub enum ProverInputError {
1515
StoreError(#[from] StoreError),
1616
#[error("Chain error: {0}")]
1717
ChainError(#[from] ChainError),
18-
#[error("ExecutionDB error: {0}")]
19-
ExecutionDBError(#[from] ExecutionDBError),
18+
#[error("ProverDB error: {0}")]
19+
ProverDBError(#[from] ProverDBError),
2020
#[error("Invalid Environment variable: {0}")]
2121
InvalidEnvVar(#[from] ConfigError),
2222
}

crates/l2/utils/test_data_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub async fn generate_program_input(
8787
read_env_file_by_config().map_err(ProverInputError::InvalidEnvVar)?;
8888
let elasticity_multiplier = ELASTICITY_MULTIPLIER;
8989
let blocks = vec![block];
90-
let db = Evm::to_execution_db(&store, &blocks).await?;
90+
let db = Evm::to_prover_db(&store, &blocks).await?;
9191

9292
Ok(ProgramInput {
9393
db,

crates/vm/backends/levm/db.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use ethrex_common::{Address as CoreAddress, H256 as CoreH256};
44
use ethrex_levm::constants::EMPTY_CODE_HASH;
55
use ethrex_levm::db::Database as LevmDatabase;
66

7-
use crate::db::{ExecutionDB, StoreWrapper};
7+
use crate::db::StoreWrapper;
8+
use crate::ProverDB;
89
use ethrex_levm::db::error::DatabaseError;
910
use std::collections::HashMap;
1011
use std::result::Result;
@@ -160,7 +161,7 @@ impl LevmDatabase for StoreWrapper {
160161
}
161162
}
162163

163-
impl LevmDatabase for ExecutionDB {
164+
impl LevmDatabase for ProverDB {
164165
fn get_account(&self, address: CoreAddress) -> Result<Account, DatabaseError> {
165166
let Some(acc_info) = self.accounts.get(&address) else {
166167
return Ok(Account::default());

crates/vm/backends/levm/mod.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::constants::{
77
BEACON_ROOTS_ADDRESS, CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS, HISTORY_STORAGE_ADDRESS,
88
SYSTEM_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS,
99
};
10-
use crate::{EvmError, ExecutionDB, ExecutionDBError, ExecutionResult, StoreWrapper};
10+
use crate::{EvmError, ExecutionResult, ProverDB, ProverDBError, StoreWrapper};
1111
use bytes::Bytes;
1212
use ethrex_common::{
1313
types::{
@@ -320,7 +320,7 @@ impl LEVM {
320320
TxResult::Success => Ok(report),
321321
// EIP-7002 specifies that a failed system call invalidates the entire block.
322322
TxResult::Revert(vm_error) => Err(EvmError::Custom(format!(
323-
"REVERT when reading withdrawal requests with error: {:?}. According to EIP-7002, the revert of this system call invalidates the block.",
323+
"REVERT when reading withdrawal requests with error: {:?}. According to EIP-7002, the revert of this system call invalidates the block.",
324324
vm_error
325325
))),
326326
}
@@ -349,7 +349,7 @@ impl LEVM {
349349
TxResult::Success => Ok(report),
350350
// EIP-7251 specifies that a failed system call invalidates the entire block.
351351
TxResult::Revert(vm_error) => Err(EvmError::Custom(format!(
352-
"REVERT when dequeuing consolidation requests with error: {:?}. According to EIP-7251, the revert of this system call invalidates the block.",
352+
"REVERT when dequeuing consolidation requests with error: {:?}. According to EIP-7251, the revert of this system call invalidates the block.",
353353
vm_error
354354
))),
355355
}
@@ -378,16 +378,13 @@ impl LEVM {
378378
Ok((report.into(), access_list))
379379
}
380380

381-
pub async fn to_execution_db(
382-
blocks: &[Block],
383-
store: &Store,
384-
) -> Result<ExecutionDB, ExecutionDBError> {
381+
pub async fn to_prover_db(blocks: &[Block], store: &Store) -> Result<ProverDB, ProverDBError> {
385382
let chain_config = store.get_chain_config()?;
386383
let Some(first_block_parent_hash) = blocks.first().map(|e| e.header.parent_hash) else {
387-
return Err(ExecutionDBError::Custom("Unable to get first block".into()));
384+
return Err(ProverDBError::Custom("Unable to get first block".into()));
388385
};
389386
let Some(last_block) = blocks.last() else {
390-
return Err(ExecutionDBError::Custom("Unable to get last block".into()));
387+
return Err(ProverDBError::Custom("Unable to get last block".into()));
391388
};
392389

393390
let logger = Arc::new(DatabaseLogger::new(Arc::new(Mutex::new(Box::new(
@@ -425,7 +422,7 @@ impl LEVM {
425422
.state_accessed
426423
.lock()
427424
.map_err(|_| {
428-
ExecutionDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
425+
ProverDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
429426
})?
430427
.clone();
431428

@@ -439,14 +436,14 @@ impl LEVM {
439436
.transpose()
440437
.map(|account| Ok((*address, account?)))
441438
})
442-
.collect::<Result<HashMap<_, _>, ExecutionDBError>>()?;
439+
.collect::<Result<HashMap<_, _>, ProverDBError>>()?;
443440

444441
// fetch all read/written code from store
445442
let code_accessed = logger
446443
.code_accessed
447444
.lock()
448445
.map_err(|_| {
449-
ExecutionDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
446+
ProverDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
450447
})?
451448
.clone();
452449
let code = accounts
@@ -459,7 +456,7 @@ impl LEVM {
459456
.transpose()
460457
.map(|account| Ok((hash, account?)))
461458
})
462-
.collect::<Result<HashMap<_, _>, ExecutionDBError>>()?;
459+
.collect::<Result<HashMap<_, _>, ProverDBError>>()?;
463460

464461
// fetch all read/written storage from store
465462
let added_storage = execution_updates.iter().filter_map(|(address, update)| {
@@ -475,7 +472,7 @@ impl LEVM {
475472
.into_iter()
476473
.chain(added_storage)
477474
.map(|(address, keys)| {
478-
let keys: Result<HashMap<_, _>, ExecutionDBError> = keys
475+
let keys: Result<HashMap<_, _>, ProverDBError> = keys
479476
.iter()
480477
.filter_map(|key| {
481478
store
@@ -486,13 +483,13 @@ impl LEVM {
486483
.collect();
487484
Ok((address, keys?))
488485
})
489-
.collect::<Result<HashMap<_, _>, ExecutionDBError>>()?;
486+
.collect::<Result<HashMap<_, _>, ProverDBError>>()?;
490487

491488
let block_hashes = logger
492489
.block_hashes_accessed
493490
.lock()
494491
.map_err(|_| {
495-
ExecutionDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
492+
ProverDBError::Store(StoreError::Custom("Could not lock mutex".to_string()))
496493
})?
497494
.clone()
498495
.into_iter()
@@ -502,10 +499,10 @@ impl LEVM {
502499
// get account proofs
503500
let state_trie = store
504501
.state_trie(last_block.hash())?
505-
.ok_or(ExecutionDBError::NewMissingStateTrie(last_block.hash()))?;
506-
let parent_state_trie = store.state_trie(first_block_parent_hash)?.ok_or(
507-
ExecutionDBError::NewMissingStateTrie(first_block_parent_hash),
508-
)?;
502+
.ok_or(ProverDBError::NewMissingStateTrie(last_block.hash()))?;
503+
let parent_state_trie = store
504+
.state_trie(first_block_parent_hash)?
505+
.ok_or(ProverDBError::NewMissingStateTrie(first_block_parent_hash))?;
509506
let hashed_addresses: Vec<_> = state_accessed.keys().map(hash_address).collect();
510507
let initial_state_proofs = parent_state_trie.get_proofs(&hashed_addresses)?;
511508
let final_state_proofs: Vec<_> = hashed_addresses
@@ -533,7 +530,7 @@ impl LEVM {
533530
continue;
534531
};
535532
let storage_trie = store.storage_trie(last_block.hash(), address)?.ok_or(
536-
ExecutionDBError::NewMissingStorageTrie(last_block.hash(), address),
533+
ProverDBError::NewMissingStorageTrie(last_block.hash(), address),
537534
)?;
538535
let paths = storage_keys.iter().map(hash_key).collect::<Vec<_>>();
539536

@@ -561,7 +558,7 @@ impl LEVM {
561558
final_storage_proofs.insert(address, final_proofs);
562559
}
563560

564-
Ok(ExecutionDB {
561+
Ok(ProverDB {
565562
accounts,
566563
code,
567564
storage,

0 commit comments

Comments
 (0)