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 e30ce15
Show file tree
Hide file tree
Showing 64 changed files with 1,806 additions and 540 deletions.
106 changes: 36 additions & 70 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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" }
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
Loading

0 comments on commit e30ce15

Please sign in to comment.