Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix bugs relating to gas and storage slot deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
frisitano committed Apr 22, 2024
1 parent fbff652 commit b7d2550
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 155 deletions.
41 changes: 19 additions & 22 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ thiserror = "1.0.50"
futures = "0.3.29"

# zk-evm dependencies
plonky2 = "0.2.2"
evm_arithmetization = { git = "https://github.com/fractal-zkp/zk_evm.git", branch = "trace-processing" }
trace_decoder = { git = "https://github.com/fractal-zkp/zk_evm.git", branch = "trace-processing" }
proof_gen = { git = "https://github.com/fractal-zkp/zk_evm.git", branch = "trace-processing" }
mpt_trie = { git = "https://github.com/fractal-zkp/zk_evm.git", branch = "trace-processing" }
plonky2 = "0.2.0"
evm_arithmetization = { path = "../zk_evm/evm_arithmetization" }
trace_decoder = { path = "../zk_evm/trace_decoder" }
proof_gen = { path = "../zk_evm/proof_gen" }
mpt_trie = { path = "../zk_evm/mpt_trie" }

[workspace.package]
edition = "2021"
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Usage: leader [OPTIONS] <COMMAND>
Commands:
stdio Reads input from stdin and writes output to stdout
jerigon Reads input from a Jerigon node and writes output to stdout
native Reads input from a native node and writes output to stdout
http Reads input from HTTP and writes output to a directory
help Print this message or the help of the given subcommand(s)
Expand Down Expand Up @@ -225,6 +226,38 @@ Prove a block.
cargo r --release --bin leader -- -r in-memory jerigon -u <RPC_URL> -b 16 > ./output/proof_16.json
```

### Native

The native command reads proof input from a native node and writes output to stdout.

```
cargo r --release --bin leader native --help
Reads input from a native node and writes output to stdout
Usage: leader native [OPTIONS] --rpc-url <RPC_URL> --block-number <BLOCK_NUMBER>
Options:
-u, --rpc-url <RPC_URL>
-b, --block-number <BLOCK_NUMBER>
The block number for which to generate a proof
-c, --checkpoint-block-number <CHECKPOINT_BLOCK_NUMBER>
The checkpoint block number [default: 0]
-f, --previous-proof <PREVIOUS_PROOF>
The previous proof output
-o, --proof-output-path <PROOF_OUTPUT_PATH>
If provided, write the generated proof to this file instead of stdout
-h, --help
Print help
```

Prove a block.

```bash
cargo r --release --bin leader -- -r in-memory native -u <RPC_URL> -b 16 > ./output/proof_16.json
```

### HTTP

The HTTP command reads proof input from HTTP and writes output to a directory.
Expand Down
47 changes: 47 additions & 0 deletions rpc/src/rpc/native/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use anyhow::{anyhow, Result};
use ethers::prelude::*;
use ethers::providers::{Http, Provider};
use ethers::types::{H160, H256};
use futures::stream::{self, TryStreamExt};
use tokio::sync::Mutex;
use trace_decoder::trace_protocol::{BlockTrace, TxnInfo};

pub async fn process_block_trace(
provider: Arc<Provider<Http>>,
block_number: u64,
) -> Result<BlockTrace> {
let block = provider
.get_block(block_number)
.await?
.ok_or_else(|| anyhow!("Block not found. Block number: {}", block_number))?;

let accounts_state = Arc::new(Mutex::new(HashMap::<H160, HashSet<H256>>::new()));
let code_db = Arc::new(Mutex::new(HashMap::<H256, Vec<u8>>::new()));
let tx_infos = stream::iter(&block.transactions)
.then(|tx_hash| {
let accounts_state = accounts_state.clone();
let provider = Arc::clone(&provider);
let code_db = Arc::clone(&code_db);
async move {
super::txn::process_transaction(provider, tx_hash, accounts_state, code_db).await
}
})
.try_collect::<Vec<TxnInfo>>()
.await?;

let trie_pre_images =
super::state::process_state_witness(Arc::clone(&provider), block, accounts_state).await?;

Ok(BlockTrace {
txn_info: tx_infos,
code_db: Some(
Arc::try_unwrap(code_db)
.map_err(|_| anyhow!("Lock still has multiple owners"))?
.into_inner(),
),
trie_pre_images: trie_pre_images,
})
}
46 changes: 5 additions & 41 deletions rpc/src/rpc/native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::Result;
use ethers::prelude::*;
use ethers::types::{GethDebugTracerType, H160, H256};
use futures::stream::{self, TryStreamExt};
use ethers::types::GethDebugTracerType;
use reqwest::ClientBuilder;
use tokio::sync::Mutex;
use trace_decoder::trace_protocol::{BlockTrace, TxnInfo};

use super::{async_trait, jerigon::RpcBlockMetadata, ProverInput, RpcClient};

mod block;
mod state;
mod trie;
mod txn;
Expand Down Expand Up @@ -39,42 +36,9 @@ impl RpcClient for NativeRpcClient {
block_number: u64,
checkpoint_block_number: u64,
) -> Result<ProverInput> {
let block = self
.provider
.get_block(block_number)
.await?
.ok_or_else(|| anyhow!("Block not found. Block number: {}", block_number))?;

let accounts_state = Arc::new(Mutex::new(HashMap::<H160, HashSet<H256>>::new()));
let code_db = Arc::new(Mutex::new(HashMap::<H256, Vec<u8>>::new()));
let tx_infos =
stream::iter(&block.transactions)
.then(|tx_hash| {
let accounts_state = accounts_state.clone();
let provider = Arc::clone(&self.provider);
let code_db = Arc::clone(&code_db);
async move {
txn::process_transaction(provider, tx_hash, accounts_state, code_db).await
}
})
.try_collect::<Vec<TxnInfo>>()
.await?;

let trie_pre_images =
state::process_state_witness(Arc::clone(&self.provider), block, accounts_state).await?;

let block_trace = BlockTrace {
txn_info: tx_infos,
code_db: Some(
Arc::try_unwrap(code_db)
.map_err(|_| anyhow!("Lock still has multiple owners"))?
.into_inner(),
),
trie_pre_images: trie_pre_images,
};

Ok(ProverInput {
block_trace,
block_trace: block::process_block_trace(Arc::clone(&self.provider), block_number)
.await?,
other_data: RpcBlockMetadata::fetch(
Arc::new(ClientBuilder::new().http1_only().build()?),
&self.rpc_url,
Expand Down
Loading

0 comments on commit b7d2550

Please sign in to comment.