Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/prover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- run: rustup component add rustfmt --toolchain nightly-2024-07-07
- run: cargo fmt --all --check

build:
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/deploy-config/holesky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
l2BaseFee: 0.1, // Gwei

// verify contract config
programVkey: '0x006c835a4c049b699a3675fefa51b182c7efe404a656151c0410245966724bc3',
programVkey: '0x0059b74a8fd03c44462de3916b45ebeedb9f1158e3037e8c40b8941cbe438d7e',
// rollup contract config
// initialize config
finalizationPeriodSeconds: 600,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/deploy-config/l1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config = {
l2BaseFee: 0.1, // Gwei

// verify contract config
programVkey: '0x006c835a4c049b699a3675fefa51b182c7efe404a656151c0410245966724bc3',
programVkey: '0x0059b74a8fd03c44462de3916b45ebeedb9f1158e3037e8c40b8941cbe438d7e',
// rollup contract config
// initialize config
finalizationPeriodSeconds: 10,
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/deploy-config/qanetl1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
l2BaseFee: 0.1, // Gwei

// verify contract config
programVkey: '0x006c835a4c049b699a3675fefa51b182c7efe404a656151c0410245966724bc3',
programVkey: '0x0059b74a8fd03c44462de3916b45ebeedb9f1158e3037e8c40b8941cbe438d7e',
// rollup contract config
// initialize config
finalizationPeriodSeconds: 600,
Expand Down
8 changes: 4 additions & 4 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ sp1-helper = { git = "https://github.com/morph-l2/sp1.git", branch = "morph-1.0"
poseidon-bn254 = { git = "https://github.com/scroll-tech/poseidon-bn254", branch = "master", features = ["bn254"] }
zktrie = { git = "https://github.com/scroll-tech/zktrie.git", branch = "main", features= ["rs_zktrie"] }


# binary dependencies
anyhow = "1.0"
async-channel = "2.2"
Expand Down
9 changes: 4 additions & 5 deletions prover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ Generate zk proof for the l2 batch.
## Requirements

- [Rust](https://rustup.rs/)
- [SP1](https://succinctlabs.github.io/sp1/getting-started/install.html)
- [SP1](https://docs.succinct.xyz/docs/sp1/getting-started/install)


### Fast Run
### Fast Run
```sh
cd bin/host
RUST_LOG=info TRUSTED_SETUP_4844=../../configs/4844_trusted_setup.txt cargo run --release
RUST_LOG=info TRUSTED_SETUP_4844=./configs/4844_trusted_setup.txt cargo run --release
```
or

```sh
RUST_LOG=info TRUSTED_SETUP_4844=../../configs/4844_trusted_setup.txt cargo run --release -- --block-path ../../testdata/mainnet_batch_traces_l1.json
RUST_LOG=info TRUSTED_SETUP_4844=./configs/4844_trusted_setup.txt cargo run --release -- --block-path ./testdata/viridian/eip7702_traces.json
```

### Build the Program
Expand Down
Binary file modified prover/bin/client/elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
2 changes: 1 addition & 1 deletion prover/bin/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sbv_primitives::types::BlockTrace;
struct Args {
#[clap(long)]
prove: bool,
#[clap(long, default_value = "../../testdata/mainnet_batch_traces.json")]
#[clap(long, default_value = "./testdata/viridian/eip7702_traces.json")]
block_path: String,
}

Expand Down
11 changes: 7 additions & 4 deletions prover/bin/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use once_cell::sync::Lazy;
use prometheus::{IntGauge, Registry};

// environment variables
pub static PROVER_PROOF_DIR: Lazy<String> = Lazy::new(|| read_env_var("PROVER_PROOF_DIR", "./proof".to_string()));
pub static PROVER_L2_RPC: Lazy<String> = Lazy::new(|| read_env_var("PROVER_L2_RPC", "localhost:8545".to_string()));
pub static PROVER_PROOF_DIR: Lazy<String> =
Lazy::new(|| read_env_var("PROVER_PROOF_DIR", "./proof".to_string()));
pub static PROVER_L2_RPC: Lazy<String> =
Lazy::new(|| read_env_var("PROVER_L2_RPC", "localhost:8545".to_string()));

// metrics
pub static REGISTRY: Lazy<Registry> = Lazy::new(Registry::new);
pub static PROVE_RESULT: Lazy<IntGauge> =
Lazy::new(|| IntGauge::new("prove_result", "prove result").expect("prove metric can be created")); // 1 = Ok, 2 = Fail
pub static PROVE_RESULT: Lazy<IntGauge> = Lazy::new(|| {
IntGauge::new("prove_result", "prove result").expect("prove metric can be created")
}); // 1 = Ok, 2 = Fail
pub static PROVE_TIME: Lazy<IntGauge> =
Lazy::new(|| IntGauge::new("prove_time", "prove time").expect("time metric can be created"));

Expand Down
9 changes: 2 additions & 7 deletions prover/crates/core/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ impl BatchInfo {
/// Construct by block traces
pub fn from_block_traces<T: Block>(traces: &[T]) -> (Self, Rc<ZkMemoryDb>) {
let chain_id = traces.first().unwrap().chain_id();
let prev_state_root = traces
.first()
.expect("at least 1 block needed")
.root_before();
let prev_state_root = traces.first().expect("at least 1 block needed").root_before();
let post_state_root = traces.last().expect("at least 1 block needed").root_after();

let mut data_hasher = Keccak::v256();
Expand Down Expand Up @@ -144,9 +141,7 @@ mod tests {
pub struct BlockTraceJsonRpcResult {
pub result: BlockTrace,
}
serde_json::from_str::<BlockTraceJsonRpcResult>(s)
.unwrap()
.result
serde_json::from_str::<BlockTraceJsonRpcResult>(s).unwrap().result
});

let fork_config = HardforkConfig::default_from_chain_id(traces[0].chain_id());
Expand Down
107 changes: 46 additions & 61 deletions prover/crates/core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use sbv_primitives::{
zk_trie::{SharedMemoryDb, ZkMemoryDb, ZkTrie},
Block,
};
use std::rc::Rc;
use std::{cell::RefCell, collections::HashMap, convert::Infallible, fmt};
use std::{cell::RefCell, collections::HashMap, convert::Infallible, fmt, rc::Rc};

type Result<T, E = ZkTrieError> = std::result::Result<T, E>;

Expand Down Expand Up @@ -92,19 +91,13 @@ impl ReadOnlyDB {
address: Address,
storage_root: B256,
) -> Option<B256> {
self.prev_storage_roots
.borrow_mut()
.insert(address, storage_root)
self.prev_storage_roots.borrow_mut().insert(address, storage_root)
}

/// Get the previous storage root of an account.
#[inline]
pub(crate) fn prev_storage_root(&self, address: &Address) -> B256 {
self.prev_storage_roots
.borrow()
.get(address)
.copied()
.unwrap_or_default()
self.prev_storage_roots.borrow().get(address).copied().unwrap_or_default()
}

/// Get the zkTrie root.
Expand Down Expand Up @@ -162,41 +155,35 @@ impl DatabaseRef for ReadOnlyDB {

/// Get basic account information.
fn basic_ref(&self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
Ok(self
.zktrie_db_ref
.get_account(address.as_slice())
.map(|account_data| {
let code_size =
u64::from_be_bytes((&account_data[0][16..24]).try_into().unwrap()) as usize;
let nonce = u64::from_be_bytes((&account_data[0][24..]).try_into().unwrap());
let balance = U256::from_be_bytes(account_data[1]);
let code_hash = B256::from(account_data[3]);
let poseidon_code_hash = B256::from(account_data[4]);

let storage_root = B256::from(account_data[2]);
self.prev_storage_roots
.borrow_mut()
.entry(address)
.or_insert(storage_root.0.into());

let zktrie_db = self.zktrie_db.clone();
self.storage_trie_refs.borrow_mut().insert(
address,
Lazy::new(Box::new(move || {
zktrie_db
.new_ref_trie(&storage_root.0)
.expect("storage trie associated with account not found")
})),
);
AccountInfo {
balance,
nonce,
code_size,
code_hash,
poseidon_code_hash,
code: self.code_db.get(&code_hash).cloned(),
}
}))
Ok(self.zktrie_db_ref.get_account(address.as_slice()).map(|account_data| {
let code_size =
u64::from_be_bytes((&account_data[0][16..24]).try_into().unwrap()) as usize;
let nonce = u64::from_be_bytes((&account_data[0][24..]).try_into().unwrap());
let balance = U256::from_be_bytes(account_data[1]);
let code_hash = B256::from(account_data[3]);
let poseidon_code_hash = B256::from(account_data[4]);

let storage_root = B256::from(account_data[2]);
self.prev_storage_roots.borrow_mut().entry(address).or_insert(storage_root.0.into());

let zktrie_db = self.zktrie_db.clone();
self.storage_trie_refs.borrow_mut().insert(
address,
Lazy::new(Box::new(move || {
zktrie_db
.new_ref_trie(&storage_root.0)
.expect("storage trie associated with account not found")
})),
);
AccountInfo {
balance,
nonce,
code_size,
code_hash,
poseidon_code_hash,
code: self.code_db.get(&code_hash).cloned(),
}
}))
}

/// Get account code by its code hash.
Expand All @@ -217,22 +204,20 @@ impl DatabaseRef for ReadOnlyDB {
/// Get storage value of address at index.
fn storage_ref(&self, address: Address, index: U256) -> Result<U256, Self::Error> {
let mut storage_trie_refs = self.storage_trie_refs.borrow_mut();
let trie = storage_trie_refs
.entry(address)
.or_insert_with_key(|address| {
let storage_root = self
.zktrie_db_ref
.get_account(address.as_slice())
.map(|account_data| B256::from(account_data[2]))
.unwrap_or_default();
let zktrie_db = self.zktrie_db.clone();
Lazy::new(Box::new(move || {
zktrie_db
.clone()
.new_ref_trie(&storage_root.0)
.expect("storage trie associated with account not found")
}))
});
let trie = storage_trie_refs.entry(address).or_insert_with_key(|address| {
let storage_root = self
.zktrie_db_ref
.get_account(address.as_slice())
.map(|account_data| B256::from(account_data[2]))
.unwrap_or_default();
let zktrie_db = self.zktrie_db.clone();
Lazy::new(Box::new(move || {
zktrie_db
.clone()
.new_ref_trie(&storage_root.0)
.expect("storage trie associated with account not found")
}))
});

Ok(trie
.get_store(&index.to_be_bytes::<32>())
Expand Down
3 changes: 1 addition & 2 deletions prover/crates/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use revm::primitives::alloy_primitives::SignatureError;
use revm::primitives::{EVMError, B256};
use revm::primitives::{alloy_primitives::SignatureError, EVMError, B256};
use std::convert::Infallible;

/// Error variants encountered during manipulation of a zkTrie.
Expand Down
11 changes: 4 additions & 7 deletions prover/crates/core/src/executor/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::error::ZkTrieError;
use crate::{executor::hooks::ExecuteHooks, EvmExecutor, HardforkConfig, ReadOnlyDB};
use crate::{
error::ZkTrieError, executor::hooks::ExecuteHooks, EvmExecutor, HardforkConfig, ReadOnlyDB,
};
use core::fmt;
use revm::db::CacheDB;
use sbv_primitives::{zk_trie::ZkMemoryDb, Block};
Expand All @@ -25,11 +26,7 @@ impl fmt::Debug for EvmExecutorBuilder<'_, ()> {
impl<'e> EvmExecutorBuilder<'e, ()> {
/// Create a new builder.
pub fn new(zktrie_db: Rc<ZkMemoryDb>) -> Self {
Self {
hardfork_config: (),
execute_hooks: ExecuteHooks::default(),
zktrie_db,
}
Self { hardfork_config: (), execute_hooks: ExecuteHooks::default(), zktrie_db }
}
}

Expand Down
5 changes: 1 addition & 4 deletions prover/crates/core/src/executor/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ impl Debug for ExecuteHooks<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExecuteHooks")
.field("tx_rlp_handlers", &self.tx_rlp_handlers.len())
.field(
"post_tx_execution_handlers",
&self.post_tx_execution_handlers.len(),
)
.field("post_tx_execution_handlers", &self.post_tx_execution_handlers.len())
.finish()
}
}
18 changes: 16 additions & 2 deletions prover/crates/core/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@ use crate::{
use revm::{
db::{AccountState, CacheDB},
primitives::{
AccountInfo, BlockEnv, Env, SpecId, TxEnv, B256, KECCAK_EMPTY, POSEIDON_EMPTY, U256,
AccountInfo, AuthorizationList as RevmAuthorizationList, BlockEnv, Env, SpecId, TxEnv,
B256, KECCAK_EMPTY, POSEIDON_EMPTY, U256,
},
Database,
};
use sbv_primitives::{zk_trie::ZkMemoryDb, Address, Block, Transaction, TxTrace};
use sbv_primitives::{
zk_trie::ZkMemoryDb, Address, Block, SignedAuthorization, Transaction, TxTrace,
};
use std::{fmt::Debug, rc::Rc};

mod builder;
pub use builder::EvmExecutorBuilder;

/// Convert from Option<&[SignedAuthorization]> to Option<RevmAuthorizationList>
fn convert_authorization_list(
auth_list: Option<&[SignedAuthorization]>,
) -> Option<RevmAuthorizationList> {
auth_list.map(|list| {
let signed_auths: Vec<SignedAuthorization> = list.to_vec();
RevmAuthorizationList::from(signed_auths)
})
}

/// Execute hooks
pub mod hooks;

Expand Down Expand Up @@ -105,6 +118,7 @@ impl EvmExecutor<'_> {
nonce: if !tx.is_l1_msg() { Some(tx.nonce()) } else { None },
chain_id: tx.chain_id(),
access_list: tx.access_list().cloned().unwrap_or_default().0,
authorization_list: convert_authorization_list(tx.authorization_list()),
gas_priority_fee: tx.max_priority_fee_per_gas().map(U256::from),
..Default::default()
};
Expand Down
Loading
Loading