Skip to content

Commit

Permalink
Merge pull request #1 from johntaiko/feat/propose_tx_hash
Browse files Browse the repository at this point in the history
feat: get txs from l1
  • Loading branch information
smtmfft authored Feb 28, 2023
2 parents b42492a + b905679 commit cb7469e
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 65 deletions.
360 changes: 330 additions & 30 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ opt-level = 3
lto = "thin"

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/smtmfft/halo2.git", rev = "50ee8ad785c53232824e60b4ff6df32b69970358", package = "halo2_proofs" }
halo2_proofs = { git = "https://github.com/smtmfft/halo2.git", rev = "50ee8ad785c53232824e60b4ff6df32b69970358", package = "halo2_proofs" }
13 changes: 10 additions & 3 deletions common/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ pub struct ProofRequestOptions {
pub circuit: String,
/// the block number
pub block: u64,
/// the rpc url
pub rpc: String,
/// the l1 rpc url
pub l1_rpc: String,
/// the l2 rpc url
pub l2_rpc: String,
/// the prover address
pub prover: String,
/// the propose tx hash
pub propose_tx_hash: String,
/// retry proof computation if error
pub retry: bool,
/// Parameters file or directory to use.
Expand All @@ -74,7 +78,10 @@ pub struct ProofRequestOptions {
impl PartialEq for ProofRequestOptions {
fn eq(&self, other: &Self) -> bool {
self.block == other.block
&& self.rpc == other.rpc
&& self.l1_rpc == other.l1_rpc
&& self.l2_rpc == other.l2_rpc
&& self.prover == other.prover
&& self.propose_tx_hash == other.propose_tx_hash
&& self.param == other.param
&& self.circuit == other.circuit
&& self.mock == other.mock
Expand Down
19 changes: 15 additions & 4 deletions coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ edition = "2021"
[dependencies]
clap = { version = "4.0.15", features = ["derive", "env"] }
env_logger = "0.9.0"
ethers-core = "0.17.0"
ethers-signers = "0.17.0"
hyper = { version = "0.14.16", features = ["client", "server", "http1", "http2", "runtime"] }
ethers-core = "1.0.2"
ethers-signers = "1.0.2"
hyper = { version = "0.14.16", features = [
"client",
"server",
"http1",
"http2",
"runtime",
] }
log = "0.4.14"
rand = "0.8.4"
serde = { version = "1.0.136", features = ["derive"] }
Expand All @@ -20,5 +26,10 @@ tokio = { version = "1.16.1", features = ["macros", "rt-multi-thread", "time"] }
zkevm_common = { path = "../common" }

[dev-dependencies]
tokio = { version = "1.16.1", features = ["macros", "rt-multi-thread", "time", "parking_lot"] }
tokio = { version = "1.16.1", features = [
"macros",
"rt-multi-thread",
"time",
"parking_lot",
] }
rust-lzma = "0.5.1"
4 changes: 3 additions & 1 deletion coordinator/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,10 @@ impl SharedState {
let proof_options = ProofRequestOptions {
circuit: config.circuit_name.clone(),
block: block_num.as_u64(),
rpc: config.l2_rpc_url.to_string(),
l1_rpc: config.l1_rpc_url.to_string(),
l2_rpc: config.l2_rpc_url.to_string(),
prover: String::from(""),
propose_tx_hash: String::from(""),
retry: false,
param: config.params_path.clone(),
mock: config.mock_prover,
Expand Down
16 changes: 11 additions & 5 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ license = "MIT OR Apache-2.0"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_10_22" }
bus-mapping = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit" }
eth-types = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit" }
zkevm-circuits = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit", features = ["test"] }
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier", tag = "v2022_12_23", default-features = false, features = ["loader_evm", "loader_halo2", "system_halo2"] }
zkevm-circuits = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit", features = [
"test",
] }
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier", tag = "v2022_12_23", default-features = false, features = [
"loader_evm",
"loader_halo2",
"system_halo2",
] }

env_logger = "0.9.0"
ethers-providers = "0.17.0"
ethers-providers = "1.0.2"
hyper = { version = "0.14.16", features = ["server"] }
rand_xorshift = "0.3"
log = "0.4.14"
Expand All @@ -27,9 +33,9 @@ clap = { version = "4.0.14", features = ["derive", "env"] }
hex = "0.4.3"

# autogen
mock = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit", optional = true }
mock = { git = "https://github.com/smtmfft/zkevm-circuits.git", branch = "feature/root-circuit", optional = true }

ethers-signers = { version = "0.17.0", optional = true }
ethers-signers = { version = "1.0.2", optional = true }
zkevm_dev = { path = "../dev", optional = true }

[features]
Expand Down
2 changes: 1 addition & 1 deletion prover/src/bin/prover_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() {
let request = ProofRequestOptions {
circuit: "super".to_string(),
block: block_num,
rpc: rpc_url,
l2_rpc: rpc_url,
retry: false,
param: Some(params_path),
mock: false,
Expand Down
27 changes: 21 additions & 6 deletions prover/src/circuit_witness.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use bus_mapping::circuit_input_builder::BuilderClient;
use bus_mapping::circuit_input_builder::CircuitsParams;
use bus_mapping::mock::BlockData;
use bus_mapping::public_input_builder::get_txs_rlp;
use bus_mapping::rpc::GethClient;
use eth_types::geth_types;
use eth_types::geth_types::GethData;
use eth_types::Address;
use eth_types::ToBigEndian;
use eth_types::Word;
use eth_types::H256;
use eth_types::{geth_types, Bytes};
use ethers_providers::Http;
use halo2_proofs::halo2curves::bn256::Fr;
use std::str::FromStr;
Expand All @@ -21,6 +22,7 @@ pub struct CircuitWitness {
pub eth_block: eth_types::Block<eth_types::Transaction>,
pub block: bus_mapping::circuit_input_builder::Block,
pub code_db: bus_mapping::state_db::CodeDB,
pub txs_rlp: Bytes,
}

impl CircuitWitness {
Expand Down Expand Up @@ -58,19 +60,31 @@ impl CircuitWitness {
eth_block: empty_data.eth_block,
block: builder.block,
code_db: builder.code_db,
txs_rlp: Bytes::default(),
})
}

/// Gathers debug trace(s) from `rpc_url` for block `block_num`.
/// Expects a go-ethereum node with debug & archive capabilities on `rpc_url`.
pub async fn from_rpc(
block_num: &u64,
rpc_url: &str,
l1_rpc_url: &str,
propose_tx_hash: &str,
l2_rpc_url: &str,
) -> Result<Self, Box<dyn std::error::Error>> {
let url = Http::from_str(rpc_url)?;
let geth_client = GethClient::new(url);
let l1_url = Http::from_str(l1_rpc_url)?;
let l1_geth_client = GethClient::new(l1_url);
let propose_tx_hash = eth_types::H256::from_slice(
&hex::decode(propose_tx_hash).expect("parse propose tx hash"),
);
let txs_rlp = get_txs_rlp(&l1_geth_client, propose_tx_hash).await?;

let l2_url = Http::from_str(l2_rpc_url)?;
let l2_geth_client = GethClient::new(l2_url);
// TODO: add support for `eth_getHeaderByNumber`
let block = geth_client.get_block_by_number((*block_num).into()).await?;
let block = l2_geth_client
.get_block_by_number((*block_num).into())
.await?;
let circuit_config =
crate::match_circuit_params_txs!(block.transactions.len(), CIRCUIT_CONFIG, {
return Err(format!(
Expand All @@ -86,14 +100,15 @@ impl CircuitWitness {
max_rws: circuit_config.max_rws,
keccak_padding: Some(circuit_config.keccak_padding),
};
let builder = BuilderClient::new(geth_client, circuit_params).await?;
let builder = BuilderClient::new(l2_geth_client, circuit_params).await?;
let (builder, eth_block) = builder.gen_inputs(*block_num).await?;

Ok(Self {
circuit_config,
eth_block,
block: builder.block,
code_db: builder.code_db,
txs_rlp,
})
}

Expand Down
6 changes: 5 additions & 1 deletion prover/src/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ pub fn gen_pi_circuit<
let prover = eth_types::Address::from_slice(
&hex::decode(prover_address.as_bytes()).expect("parse_address"),
);
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>(PiCircuit::new_from_block_with_prover(&block, prover));
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>(PiCircuit::new_from_block_with_extra(
&block,
prover,
witness.txs_rlp.clone(),
));

Ok(circuit)
}
Expand Down
11 changes: 8 additions & 3 deletions prover/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,14 @@ async fn handle_method(
let options: ProofRequestOptions =
serde_json::from_value(options.to_owned()).map_err(|e| e.to_string())?;

let witness = CircuitWitness::from_rpc(&options.block, &options.rpc)
.await
.map_err(|e| e.to_string())?;
let witness = CircuitWitness::from_rpc(
&options.block,
&options.l1_rpc,
&options.propose_tx_hash,
&options.l2_rpc,
)
.await
.map_err(|e| e.to_string())?;

let circuit_config =
crate::match_circuit_params!(witness.gas_used(), CIRCUIT_CONFIG, {
Expand Down
22 changes: 14 additions & 8 deletions prover/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use halo2_proofs::plonk::Circuit;
use halo2_proofs::plonk::{keygen_pk, keygen_vk};
use halo2_proofs::poly::commitment::Params;
use hyper::Uri;
use rand::{thread_rng, Rng};
use snark_verifier::loader::native::NativeLoader;
use snark_verifier::system::halo2::compile;
use snark_verifier::system::halo2::transcript::evm::EvmTranscript;
use snark_verifier::system::halo2::Config as PlonkConfig;
use rand::{thread_rng, Rng};
use std::collections::HashMap;
use std::fmt::Write;
use std::fs::File;
Expand Down Expand Up @@ -89,11 +89,13 @@ macro_rules! gen_proof {
{ CIRCUIT_CONFIG.max_txs },
{ CIRCUIT_CONFIG.max_calldata },
{ CIRCUIT_CONFIG.max_rws },
_>(&witness, task_options.prover, fixed_rng())?;
_,
>(&witness, task_options.prover, fixed_rng())?;
circuit_proof.k = CIRCUIT_CONFIG.min_k as u8;
circuit_proof.instance = collect_instance(&circuit.0.instance());
let prover = MockProver::run(CIRCUIT_CONFIG.min_k as u32, &circuit, circuit.0.instance())
.expect("MockProver::run");
let prover =
MockProver::run(CIRCUIT_CONFIG.min_k as u32, &circuit, circuit.0.instance())
.expect("MockProver::run");
prover.verify_par().expect("MockProver::verify_par");
circuit_proof.duration = Instant::now().duration_since(time_started).as_millis() as u32;
} else {
Expand Down Expand Up @@ -372,10 +374,14 @@ impl SharedState {
let self_copy = self.clone();

tokio::spawn(async move {
let witness =
CircuitWitness::from_rpc(&task_options_copy.block, &task_options_copy.rpc)
.await
.map_err(|e| e.to_string())?;
let witness = CircuitWitness::from_rpc(
&task_options_copy.block,
&task_options_copy.l1_rpc,
&task_options_copy.propose_tx_hash,
&task_options_copy.l2_rpc,
)
.await
.map_err(|e| e.to_string())?;

let (config, circuit_proof, aggregation_proof) = crate::match_circuit_params_txs!(
witness.txs().len(),
Expand Down
4 changes: 2 additions & 2 deletions prover/tests/proverd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ async fn proverd_simple_signaling() {
circuit: "super".to_string(),
block: 1,
retry: false,
rpc: "http://localhost:1111".to_string(),
l2_rpc: "http://localhost:1111".to_string(),
..Default::default()
};
let proof_b = ProofRequestOptions {
circuit: "super".to_string(),
block: 2,
retry: false,
rpc: "http://localhost:1111".to_string(),
l2_rpc: "http://localhost:1111".to_string(),
..Default::default()
};

Expand Down

0 comments on commit cb7469e

Please sign in to comment.