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

feat: support alpha3 testnet #91

Open
wants to merge 23 commits into
base: taiko-pi-test
Choose a base branch
from
Open
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
196 changes: 144 additions & 52 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ keccak256 = { path = "../keccak256" }
mock = { path = "../mock", optional = true }
ark-std = { version = "0.3", features = ["print-trace"] }

ethers-core = "2.0.0"
ethers-providers = "2.0.0"
ethers-core = "=2.0.0"
ethers-providers = "=2.0.0"
Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_10_22" }
itertools = "0.10"
lazy_static = "1.4"
Expand Down
58 changes: 26 additions & 32 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub use block::{Block, BlockContext};
pub use call::{Call, CallContext, CallKind};
use core::fmt::Debug;
use eth_types::sign_types::{pk_bytes_le, pk_bytes_swap_endianness, SignData};
use eth_types::ToWord;
use eth_types::{self, geth_types, Address, GethExecStep, GethExecTrace, Word};
use ethers_providers::JsonRpcClient;
pub use execution::{
Expand Down Expand Up @@ -400,38 +399,33 @@ impl<P: JsonRpcClient> BuilderClient<P> {
// self.cli.trace_block_by_number(block_num.into()).await?;

// fetch up to 256 blocks
let mut n_blocks = std::cmp::min(256, block_num as usize);
let mut next_hash = eth_block.parent_hash;
let mut prev_state_root: Option<Word> = None;
let mut history_hashes = vec![Word::default(); n_blocks];
while n_blocks > 0 {
n_blocks -= 1;

// TODO: consider replacing it with `eth_getHeaderByHash`, it's faster
let header = self.cli.get_block_by_hash(next_hash).await?;

// set the previous state root
if prev_state_root.is_none() {
prev_state_root = Some(header.state_root.to_word());
}

// latest block hash is the last item
let block_hash = header
.hash
.ok_or(Error::EthTypeError(eth_types::Error::IncompleteBlock))?
.to_word();
history_hashes[n_blocks] = block_hash;

// continue
next_hash = header.parent_hash;
}
let n_blocks = std::cmp::min(256, block_num as usize);
// let mut next_hash = eth_block.parent_hash;
// let mut prev_state_root: Option<Word> = None;
let history_hashes = vec![Word::default(); n_blocks];
// while n_blocks > 0 {
// n_blocks -= 1;

// // TODO: consider replacing it with `eth_getHeaderByHash`, it's faster
// let header = self.cli.get_block_by_hash(next_hash).await?;

// // set the previous state root
// if prev_state_root.is_none() {
// prev_state_root = Some(header.state_root.to_word());
// }

// // latest block hash is the last item
// let block_hash = header
// .hash
// .ok_or(Error::EthTypeError(eth_types::Error::IncompleteBlock))?
// .to_word();
// history_hashes[n_blocks] = block_hash;

// // continue
// next_hash = header.parent_hash;
// }

Ok((
eth_block,
geth_traces,
history_hashes,
prev_state_root.unwrap_or_default(),
))
Ok((eth_block, geth_traces, history_hashes, Default::default()))
}

/// Step 2. Get State Accesses from TxExecTraces
Expand Down
22 changes: 0 additions & 22 deletions bus-mapping/src/public_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,3 @@ pub async fn get_txs_rlp<P: JsonRpcClient>(
}
})
}

#[cfg(test)]
mod tests {
use ethers_core::utils::rlp;
use ethers_providers::Http;
use std::str::FromStr;

use super::*;
#[tokio::test]
async fn test() {
let l1_provider =
Http::from_str("https://l1rpc.internal.taiko.xyz").expect("Http geth url");
let l1_geth_client = GethClient::new(l1_provider);
let propose_tx_hash = H256::from_slice(
&hex::decode("6384692336baecbdcafb0bfe84437372d3ec2727a4c6bd7a6cf66644773b8124")
.unwrap(),
);
let tx = get_txs_rlp(&l1_geth_client, propose_tx_hash).await.unwrap();
let txs: Vec<eth_types::Transaction> = rlp::Rlp::new(&tx).as_list().unwrap();
println!("{:?}", txs);
}
}
4 changes: 2 additions & 2 deletions circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rand = "0.8"
itertools = "0.10"
eth-types = { path = "../eth-types" }
env_logger = "0.9"
ethers-signers = "2.0.0"
ethers-signers = "=2.0.0"
mock = { path = "../mock" }
rand_chacha = "0.3"
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier", tag = "v2022_12_23", default-features = false, features = [
Expand All @@ -26,7 +26,7 @@ snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-
"system_halo2",
] }
clap = { version = "4.0", features = ["derive"] }
ethers-providers = "2.0.0"
ethers-providers = "=2.0.0"
tokio = { version = "1.22", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
137 changes: 75 additions & 62 deletions circuit-benchmarks/examples/pi_circuit_integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! PI circuit benchmarks
use ark_std::{end_timer, start_timer};
use eth_types::{Bytes, U256};
use eth_types::{Bytes, H256, U256};
use halo2_proofs::plonk::{create_proof, keygen_pk, keygen_vk, verify_proof};
use halo2_proofs::poly::kzg::commitment::{KZGCommitmentScheme, ParamsKZG};
use halo2_proofs::{
Expand Down Expand Up @@ -41,11 +41,7 @@ mod test {
const MAX_CALLDATA: usize = 65536 * 16;

let public_data = generate_publicdata::<MAX_TXS, MAX_CALLDATA>();
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>(PiCircuit::<Fr>::new(
MAX_TXS,
MAX_CALLDATA,
randomness,
));
let circuit = PiTestCircuit::<Fr>(PiCircuit::<Fr>::new(public_data));
let public_inputs = circuit.0.instance();
let instance: Vec<&[Fr]> = public_inputs.iter().map(|input| &input[..]).collect();
let instances = &[&instance[..]][..];
Expand Down Expand Up @@ -186,11 +182,7 @@ mod test {
fn new_pi_circuit<const MAX_TXS: usize, const MAX_CALLDATA: usize>(
) -> PiTestCircuit<Fr, MAX_TXS, MAX_CALLDATA> {
let public_data = generate_publicdata::<MAX_TXS, MAX_CALLDATA>();
let circuit = PiTestCircuit::<Fr, MAX_TXS, MAX_CALLDATA>(PiCircuit::<Fr>::new(
MAX_TXS,
MAX_CALLDATA,
randomness,
));
let circuit = PiTestCircuit::<Fr>(PiCircuit::<Fr>::new(public_data));
circuit
}
}
Expand Down Expand Up @@ -255,9 +247,7 @@ trait InstancesExport {
fn instances(&self) -> Vec<Vec<Fr>>;
}

impl<const MAX_TXS: usize, const MAX_CALLDATA: usize> InstancesExport
for PiTestCircuit<Fr, MAX_TXS, MAX_CALLDATA>
{
impl InstancesExport for PiTestCircuit<Fr> {
fn num_instance() -> Vec<usize> {
vec![2]
}
Expand Down Expand Up @@ -305,12 +295,11 @@ fn evm_verify(deployment_code: Vec<u8>, instances: Vec<Vec<Fr>>, proof: Vec<u8>)
let mut evm = ExecutorBuilder::default()
.with_gas_limit(u64::MAX.into())
.build();

let caller = Address::from_low_u64_be(0xfe);
let verifier = evm
.deploy(caller, deployment_code.into(), 0.into())
.address
.unwrap();
let deploy = evm.deploy(caller, deployment_code.into(), 0.into());
println!("deploy exit reason: {:?}", deploy.exit_reason);
let verifier = deploy.address.unwrap();

let result = evm.call_raw(caller, verifier, calldata.into(), 0.into());

dbg!(result.gas_used);
Expand Down Expand Up @@ -412,13 +401,12 @@ fn load_circuit_pk<C: Circuit<Fr>>(
}

use bus_mapping::circuit_input_builder::{BuilderClient, CircuitsParams};
use bus_mapping::public_input_builder::get_txs_rlp;
use bus_mapping::rpc::GethClient;
use bus_mapping::Error;
use clap::Parser;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use zkevm_circuits::evm_circuit::witness::block_convert;
use zkevm_circuits::evm_circuit::witness::{block_convert, Taiko};
use zkevm_circuits::tx_circuit::PrimeField;

#[cfg(feature = "http_provider")]
Expand All @@ -429,22 +417,73 @@ use ethers_providers::Ws;
#[derive(Parser, Debug)]
#[clap(version, about)]
pub(crate) struct ProverCmdConfig {
/// l1_geth_url
l1_geth_url: Option<String>,
/// propose tx hash
propose_tx_hash: Option<String>,
/// l2_geth_url
l2_geth_url: Option<String>,
/// block_num
block_num: Option<u64>,
/// prover address
address: Option<String>,
prover: Option<String>,

/// l1 signal service address
l1_signal_service: Option<String>,
/// l2 signal service address
l2_signal_service: Option<String>,
/// l2 contract address
l2_contract: Option<String>,
block_hash: Option<String>,
parent_hash: Option<String>,
/// meta hash
meta_hash: Option<String>,
/// signal root
signal_root: Option<String>,
/// extra message
graffiti: Option<String>,
gas_used: Option<u32>,
/// parent gas used
parent_gas_used: Option<u32>,
/// block max gas limit
block_max_gas_limit: Option<u64>,
/// max bytes per tx list
max_bytes_per_tx_list: Option<u64>,
/// max transactions per block
max_transactions_per_block: Option<u64>,
/// generate yul
yul_output: Option<String>,
/// output_file
output: Option<String>,
}

impl ProverCmdConfig {
fn as_taiko_witness(&self) -> Taiko {
Taiko {
l1_signal_service: parse_address(&self.l1_signal_service),
l2_signal_service: parse_address(&self.l2_signal_service),
l2_contract: parse_address(&self.l2_contract),
meta_hash: parse_hash(&self.meta_hash),
block_hash: parse_hash(&self.block_hash),
parent_hash: parse_hash(&self.parent_hash),
signal_root: parse_hash(&self.signal_root),
graffiti: parse_hash(&self.graffiti),
prover: parse_address(&self.prover),
parent_gas_used: self.parent_gas_used.unwrap(),
gas_used: self.gas_used.unwrap(),
block_max_gas_limit: self.block_max_gas_limit.unwrap(),
max_bytes_per_tx_list: self.max_bytes_per_tx_list.unwrap(),
max_transactions_per_block: self.max_transactions_per_block.unwrap(),
}
}
}

fn parse_hash(input: &Option<String>) -> H256 {
H256::from_slice(&hex::decode(input.as_ref().unwrap().as_bytes()).expect("parse_hash"))
}

fn parse_address(input: &Option<String>) -> Address {
eth_types::Address::from_slice(
&hex::decode(input.as_ref().unwrap().as_bytes()).expect("parse_address"),
)
}

#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct CircuitConfig {
pub block_gas_limit: usize,
Expand Down Expand Up @@ -507,24 +546,9 @@ async fn main() -> Result<(), Error> {

let config = ProverCmdConfig::parse();
let block_num = config.block_num.map_or_else(|| 1, |n| n);
let prover = eth_types::Address::from_slice(
&hex::decode(config.address.expect("needs prover").as_bytes()).expect("parse_address"),
);

#[cfg(feature = "http_provider")]
let l1_provider = Http::from_str(&config.l1_geth_url.unwrap()).expect("Http geth url");
#[cfg(not(feature = "http_provider"))]
let l1_provider = Ws::connect(&config.l1_geth_url.unwrap())
.await
.expect("l1 ws rpc connected");
let l1_geth_client = GethClient::new(l1_provider);
let propose_tx_hash = eth_types::H256::from_slice(
&hex::decode(config.propose_tx_hash.unwrap().as_bytes()).expect("parse_hash"),
);
let txs_rlp = get_txs_rlp(&l1_geth_client, propose_tx_hash).await?;

#[cfg(feature = "http_provider")]
let l2_provider = Http::from_str(&config.l2_geth_url.unwrap()).expect("Http geth url");
let l2_provider = Http::from_str(config.l2_geth_url.as_ref().unwrap()).expect("Http geth url");
#[cfg(not(feature = "http_provider"))]
let l2_provider = Ws::connect(&config.l2_geth_url.unwrap())
.await
Expand All @@ -550,19 +574,13 @@ async fn main() -> Result<(), Error> {
let builder = BuilderClient::new(l2_geth_client, circuit_params.clone()).await?;
let (builder, _) = builder.gen_inputs(block_num).await?;
let block = block_convert(&builder.block, &builder.code_db).unwrap();
let taiko = config.as_taiko_witness();
select_circuit_config!(
txs,
{
let public_data = PublicData::new(&block, prover, txs_rlp);
let public_data = PublicData::new(&block, &taiko);
log::info!("using CIRCUIT_CONFIG = {:?}", CIRCUIT_CONFIG);
let circuit =
PiTestCircuit::<Fr, { CIRCUIT_CONFIG.max_txs }, { CIRCUIT_CONFIG.max_calldata }>(
PiCircuit::new(
CIRCUIT_CONFIG.max_txs,
CIRCUIT_CONFIG.max_calldata,
public_data,
),
);
let circuit = PiTestCircuit::<Fr>(PiCircuit::new(public_data));
assert!(block.txs.len() <= CIRCUIT_CONFIG.max_txs);

let params = get_circuit_params::<0>(CIRCUIT_CONFIG.min_k as usize);
Expand All @@ -579,15 +597,11 @@ async fn main() -> Result<(), Error> {

let deployment_code = if config.yul_output.is_some() {
gen_evm_verifier(
&params,
pk.get_vk(),
PiTestCircuit::<
Fr,
{ CIRCUIT_CONFIG.max_txs },
{ CIRCUIT_CONFIG.max_calldata },
>::num_instance(),
config.yul_output
)
&params,
pk.get_vk(),
PiTestCircuit::<Fr>::num_instance(),
config.yul_output,
)
} else {
vec![]
};
Expand Down Expand Up @@ -619,8 +633,7 @@ async fn main() -> Result<(), Error> {
let output_file = if let Some(output) = config.output {
output
} else {
let l1_tx_hash = propose_tx_hash.to_string();
format!("./block-{}_proof-new.json", &l1_tx_hash)
format!("./block-{}_proof-new.json", config.block_num.unwrap())
};
File::create(output_file)
.expect("open output_file")
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/examples/super_circuit_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn bench_super_circuit_prover() {

block.sign(&wallets);

type TestSuperCircuit = SuperCircuit::<Fr, 4, 32, 512>;
type TestSuperCircuit = SuperCircuit<Fr, 4, 32, 512>;
let (_, circuit, instance, _) = TestSuperCircuit::build(block).unwrap();
let instance_refs: Vec<&[Fr]> = instance.iter().map(|v| &v[..]).collect();

Expand Down
4 changes: 2 additions & 2 deletions eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["The appliedzkp team"]
license = "MIT OR Apache-2.0"

[dependencies]
ethers-core = "2.0.0"
ethers-signers = "2.0.0"
ethers-core = "=2.0.0"
ethers-signers = "=2.0.0"
hex = "0.4"
lazy_static = "1.4"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2022_10_22" }
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
lazy_static = "1.4"
ethers = { version = "2.0.0", features = ["ethers-solc"] }
ethers = { version = "=2.0.0", features = ["ethers-solc"] }
serde_json = "1.0.66"
serde = { version = "1.0.130", features = ["derive"] }
bus-mapping = { path = "../bus-mapping" }
Expand Down
Loading