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

Commit

Permalink
Merge branch 'main' into feat/#1665-ecrecover
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Feb 5, 2024
2 parents aed502b + 81e715a commit 7af89c8
Show file tree
Hide file tree
Showing 64 changed files with 1,868 additions and 583 deletions.
209 changes: 97 additions & 112 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ members = [
]

[patch.crates-io]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }

[patch."https://github.com/scroll-tech/halo2.git"]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }

[patch."https://github.com/privacy-scaling-explorations/halo2curves.git"]
halo2curves = { version = "0.1.0", features = ["derive_serde"] }
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mock = { path = "../mock", optional = true }

ethers-core = "=2.0.10"
ethers-providers = "=2.0.10"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
itertools = "0.10"
lazy_static = "1.4"
log = "0.4.14"
Expand All @@ -23,7 +23,7 @@ serde_json = "1.0.66"
strum = "0.24"
strum_macros = "0.24"
revm-precompile = { version = "=2.2.0", default-features = false, optional = true }

[dev-dependencies]
hex = "0.4.3"
pretty_assertions = "1.0.0"
Expand Down
72 changes: 69 additions & 3 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,43 @@ use std::{
pub use transaction::{Transaction, TransactionContext};
pub use withdrawal::{Withdrawal, WithdrawalContext};

/// Runtime Config
///
/// Default to mainnet block
#[derive(Debug, Clone, Copy)]
pub struct FeatureConfig {
/// Zero difficulty
pub zero_difficulty: bool,
/// Free first transaction
pub free_first_tx: bool,
/// Enable EIP1559
pub enable_eip1559: bool,
/// Allow invalid transactions to be included in a block
///
/// Transactions with mismatched nonce, insufficient gas limit, or insufficient balance
/// shouldn't be included in a mainnet block. However, rollup developers might want to
/// include invalid tx in the L2 block to support forced exit feature.
pub invalid_tx: bool,
}

impl Default for FeatureConfig {
fn default() -> Self {
Self {
zero_difficulty: true,
free_first_tx: false,
enable_eip1559: true,
invalid_tx: false,
}
}
}

impl FeatureConfig {
/// Check if we are mainnet config
pub fn is_mainnet(&self) -> bool {
self.zero_difficulty && !self.free_first_tx && self.enable_eip1559 && !self.invalid_tx
}
}

/// Circuit Setup Parameters
#[derive(Debug, Clone, Copy)]
pub struct FixedCParams {
Expand Down Expand Up @@ -157,18 +194,27 @@ pub struct CircuitInputBuilder<C: CircuitsParams> {
pub circuits_params: C,
/// Block Context
pub block_ctx: BlockContext,
/// Feature config
pub feature_config: FeatureConfig,
}

impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
/// Create a new CircuitInputBuilder from the given `eth_block` and
/// `constants`.
pub fn new(sdb: StateDB, code_db: CodeDB, block: Block, params: C) -> Self {
pub fn new(
sdb: StateDB,
code_db: CodeDB,
block: Block,
params: C,
feature_config: FeatureConfig,
) -> Self {
Self {
sdb,
code_db,
block,
circuits_params: params,
block_ctx: BlockContext::new(),
feature_config,
}
}

Expand Down Expand Up @@ -280,13 +326,15 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
let end_tx_step =
gen_associated_steps(&mut self.state_ref(&mut tx, &mut tx_ctx), ExecState::EndTx)?;
tx.steps_mut().push(end_tx_step);
} else {
} else if self.feature_config.invalid_tx {
// Generate InvalidTx step
let invalid_tx_step = gen_associated_steps(
&mut self.state_ref(&mut tx, &mut tx_ctx),
ExecState::InvalidTx,
)?;
tx.steps_mut().push(invalid_tx_step);
} else {
panic!("invalid tx support not enabled")
}

self.sdb.commit_tx();
Expand Down Expand Up @@ -465,6 +513,7 @@ impl CircuitInputBuilder<DynamicCParams> {
block: self.block,
circuits_params: c_params,
block_ctx: self.block_ctx,
feature_config: self.feature_config,
};

cib.set_end_block(c_params.max_rws)?;
Expand Down Expand Up @@ -575,6 +624,7 @@ pub struct BuilderClient<P: JsonRpcClient> {
cli: GethClient<P>,
chain_id: Word,
circuits_params: FixedCParams,
feature_config: FeatureConfig,
}

/// Get State Accesses from TxExecTraces
Expand Down Expand Up @@ -632,12 +682,22 @@ pub fn build_state_code_db(
impl<P: JsonRpcClient> BuilderClient<P> {
/// Create a new BuilderClient
pub async fn new(client: GethClient<P>, circuits_params: FixedCParams) -> Result<Self, Error> {
Self::new_with_features(client, circuits_params, FeatureConfig::default()).await
}

/// Create a new BuilderClient
pub async fn new_with_features(
client: GethClient<P>,
circuits_params: FixedCParams,
feature_config: FeatureConfig,
) -> Result<Self, Error> {
let chain_id = client.get_chain_id().await?;

Ok(Self {
cli: client,
chain_id: chain_id.into(),
circuits_params,
feature_config,
})
}

Expand Down Expand Up @@ -749,7 +809,13 @@ impl<P: JsonRpcClient> BuilderClient<P> {
prev_state_root: Word,
) -> Result<CircuitInputBuilder<FixedCParams>, Error> {
let block = Block::new(self.chain_id, history_hashes, prev_state_root, eth_block)?;
let mut builder = CircuitInputBuilder::new(sdb, code_db, block, self.circuits_params);
let mut builder = CircuitInputBuilder::new(
sdb,
code_db,
block,
self.circuits_params,
self.feature_config,
);
builder.handle_block(eth_block, geth_traces)?;
Ok(builder)
}
Expand Down
11 changes: 10 additions & 1 deletion bus-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
circuit_input_builder::{
get_state_accesses, Block, CircuitInputBuilder, CircuitsParams, DynamicCParams,
FixedCParams,
FeatureConfig, FixedCParams,
},
state_db::{self, CodeDB, StateDB},
};
Expand Down Expand Up @@ -34,6 +34,14 @@ impl<C: CircuitsParams> BlockData<C> {
/// Generate a new CircuitInputBuilder initialized with the context of the
/// BlockData.
pub fn new_circuit_input_builder(&self) -> CircuitInputBuilder<C> {
self.new_circuit_input_builder_with_feature(FeatureConfig::default())
}
/// Generate a new CircuitInputBuilder initialized with the context of the
/// BlockData.
pub fn new_circuit_input_builder_with_feature(
&self,
feature_config: FeatureConfig,
) -> CircuitInputBuilder<C> {
CircuitInputBuilder::new(
self.sdb.clone(),
self.code_db.clone(),
Expand All @@ -45,6 +53,7 @@ impl<C: CircuitsParams> BlockData<C> {
)
.unwrap(),
self.circuits_params,
feature_config,
)
}

Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
ark-std = { version = "0.3", features = ["print-trace"] }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test-circuits"] }
bus-mapping = { path = "../bus-mapping", features = ["test"] }
Expand Down
2 changes: 2 additions & 0 deletions circuit-benchmarks/src/mpt_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ mod tests {
}
}

let max_nodes = 720;
let circuit = MPTCircuit::<Fr> {
nodes,
keccak_data,
degree: degree as usize,
max_nodes,
disable_preimage_check: false,
_marker: PhantomData,
};
Expand Down
2 changes: 1 addition & 1 deletion eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ethers-core = "=2.0.10"
ethers-signers = "=2.0.10"
hex = "0.4"
lazy_static = "1.4"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
regex = "1.5.4"
serde = {version = "1.0.130", features = ["derive"] }
serde_json = "1.0.66"
Expand Down
2 changes: 1 addition & 1 deletion gadgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["The appliedzkp team"]
license = "MIT OR Apache-2.0"

[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
sha3 = "0.7.2"
eth-types = { path = "../eth-types" }
digest = "0.7.6"
Expand Down
2 changes: 1 addition & 1 deletion gadgets/src/batched_is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ mod test {
};
let k = 4;
let prover = MockProver::<Fr>::run(k, &circuit, vec![]).unwrap();
prover.assert_satisfied_par()
prover.assert_satisfied()
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions gadgets/src/is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mod test {
_marker: PhantomData,
};
let prover = MockProver::<Fp>::run(k, &circuit, vec![]).unwrap();
prover.assert_satisfied_par()
prover.assert_satisfied()
}};
}

Expand All @@ -188,7 +188,7 @@ mod test {
_marker: PhantomData,
};
let prover = MockProver::<Fp>::run(k, &circuit, vec![]).unwrap();
assert!(prover.verify_par().is_err());
assert!(prover.verify().is_err());
}};
}

Expand Down
2 changes: 1 addition & 1 deletion gadgets/src/mul_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ mod test {
_marker: PhantomData,
};
let prover = MockProver::<Fp>::run(k, &circuit, vec![]).unwrap();
prover.assert_satisfied_par()
prover.assert_satisfied()
}};
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ url = "2.2.2"
pretty_assertions = "1.0.0"
log = "0.4.14"
env_logger = "0.9"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
rand_chacha = "0.3"
paste = "1.0"
rand_xorshift = "0.3.0"
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<C: SubCircuit<Fr> + Circuit<Fr>> IntegrationTest<C> {
self.test_variadic(&mock_prover);

mock_prover
.verify_par()
.verify()
.expect("mock prover verification failed");
}

Expand Down Expand Up @@ -468,7 +468,7 @@ impl<C: SubCircuit<Fr> + Circuit<Fr>> IntegrationTest<C> {
.unwrap();
self.test_root_variadic(&mock_prover);
mock_prover
.verify_par()
.verify()
.expect("mock prover verification failed");
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion light-client-poc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
zkevm-circuits = { path = "../zkevm-circuits", features=["test-circuits"]}
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" }
eyre = { version = "0.6.8" }
hex = "0.4.3"
num_enum = "0.6.1"
Expand Down
4 changes: 3 additions & 1 deletion light-client-poc/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ mod witness;

pub use prover::StateUpdateCircuitKeys;

pub use state_update::{StateUpdateCircuit, DEFAULT_CIRCUIT_DEGREE, DEFAULT_MAX_PROOF_COUNT};
pub use state_update::{
StateUpdateCircuit, DEFAULT_CIRCUIT_DEGREE, DEFAULT_MAX_NODES, DEFAULT_MAX_PROOF_COUNT,
};
pub use witness::{PublicInputs, StateUpdateWitness};
2 changes: 1 addition & 1 deletion light-client-poc/src/circuit/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl StateUpdateCircuit<Fr> {

let prover =
MockProver::<Fr>::run(self.degree as u32, self, vec![public_inputs.0]).unwrap();
prover.assert_satisfied_at_rows_par(0..num_rows, 0..num_rows);
prover.assert_satisfied_at_rows(0..num_rows, 0..num_rows);
}

pub fn prove(self, keys: &StateUpdateCircuitKeys) -> Result<Vec<u8>> {
Expand Down
17 changes: 11 additions & 6 deletions light-client-poc/src/circuit/state_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use zkevm_circuits::{
util::{SubCircuit, SubCircuitConfig},
};

pub const DEFAULT_MAX_NODES: usize = 4000;
pub const DEFAULT_MAX_PROOF_COUNT: usize = 20;
pub const DEFAULT_CIRCUIT_DEGREE: usize = 14;

Expand Down Expand Up @@ -90,6 +91,7 @@ impl<F: Field> Circuit<F> for StateUpdateCircuit<F> {
MPTCircuitParams {
degree: self.mpt_circuit.degree,
disable_preimage_check: self.mpt_circuit.disable_preimage_check,
max_nodes: self.mpt_circuit.max_nodes,
}
}

Expand Down Expand Up @@ -301,14 +303,15 @@ impl<F: Field> Circuit<F> for StateUpdateCircuit<F> {

// assign MPT witness

let height =
config
.mpt_config
.assign(&mut layouter, &self.mpt_circuit.nodes, &challenges)?;
config.mpt_config.load_fixed_table(&mut layouter)?;
config
.mpt_config
.load_mult_table(&mut layouter, &challenges, height)?;
.assign(&mut layouter, &self.mpt_circuit.nodes, &challenges)?;
config.mpt_config.load_fixed_table(&mut layouter)?;
config.mpt_config.load_mult_table(
&mut layouter,
&challenges,
self.mpt_circuit.max_nodes,
)?;

#[cfg(feature = "disable-keccak")]
config.mpt_config.keccak_table.dev_load(
Expand Down Expand Up @@ -466,6 +469,7 @@ impl StateUpdateCircuit<Fr> {
pub fn new(
witness: StateUpdateWitness<Fr>,
degree: usize,
max_nodes: usize,
max_proof_count: usize,
) -> Result<StateUpdateCircuit<Fr>> {
let StateUpdateWitness {
Expand All @@ -489,6 +493,7 @@ impl StateUpdateCircuit<Fr> {
nodes: mpt_witness,
keccak_data: keccak_data.clone(),
degree,
max_nodes,
disable_preimage_check,
_marker: std::marker::PhantomData,
};
Expand Down
Loading

0 comments on commit 7af89c8

Please sign in to comment.