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

[proof-chunk] merge to main branch #1785

Merged
merged 16 commits into from
Mar 21, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
merge main back to proof chunk
  • Loading branch information
hero78119 committed Mar 1, 2024
commit 2fb87b0d96b07ec652fd55c37846e5c325c54b47
3 changes: 2 additions & 1 deletion bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ pub struct CircuitInputBuilder<C: CircuitsParams> {
pub block_ctx: BlockContext,
/// Chunk Context
pub chunk_ctx: ChunkContext,
/// Circuit Params before chunking
/// Circuits Setup Parameters before chunking
pub circuits_params: C,
/// Feature config
pub feature_config: FeatureConfig,
@@ -929,6 +929,7 @@ impl<C: CircuitsParams> CircuitInputBuilder<C> {
max_bytecode,
max_evm_rows,
max_keccak_rows,
max_vertical_circuit_rows: 0,
}
}
}
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@

use super::{
get_call_memory_offset_length, get_create_init_code, Block, BlockContext, Call, CallContext,
CallKind, ChunkContext, CodeSource, CopyEvent, ExecState, ExecStep, ExpEvent, Transaction,
TransactionContext,
CallKind, ChunkContext, CodeSource, CopyEvent, ExecState, ExecStep, ExpEvent, PrecompileEvent,
Transaction, TransactionContext,
};
use crate::{
error::{DepthError, ExecError, InsufficientBalanceError, NonceUintOverflowError},
4 changes: 2 additions & 2 deletions gadgets/src/permutation.rs
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ impl<F: Field> PermutationChipConfig<F> {

// power_of_gamma start from gamma**1
let power_of_gamma = {
let num_of_col = col_values.get(0).map(|row| row.len()).unwrap_or_default();
let num_of_col = col_values.first().map(|row| row.len()).unwrap_or_default();
std::iter::successors(Some(gamma), |prev| (*prev * gamma).into())
.take(num_of_col.saturating_sub(1))
.collect::<Vec<Value<F>>>()
@@ -327,7 +327,7 @@ pub fn get_permutation_fingerprints<F: Field>(
acc_fingerprints_prev: Value<F>,
) -> Vec<(Value<F>, Value<F>)> {
let power_of_gamma = {
let num_of_col = col_values.get(0).map(|row| row.len()).unwrap_or_default();
let num_of_col = col_values.first().map(|row| row.len()).unwrap_or_default();
std::iter::successors(Some(Value::known(F::ONE)), |prev| (*prev * gamma).into())
.take(num_of_col)
.collect::<Vec<Value<F>>>()
7 changes: 6 additions & 1 deletion zkevm-circuits/src/bin/stats/main.rs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ use zkevm_circuits::{
TxTable, UXTable, WdTable,
},
tx_circuit::{TxCircuitConfig, TxCircuitConfigArgs},
util::{Challenges, SubCircuitConfig},
util::{chunk_ctx::ChunkContextConfig, Challenges, SubCircuitConfig},
};

fn main() {
@@ -343,6 +343,10 @@ fn record_stats<F: eth_types::Field>(
stats.record("state", meta);
let exp_circuit = ExpCircuitConfig::new(meta, exp_table);
stats.record("exp", meta);

let sig_table = SigTable::construct(meta);

let chunk_ctx_config = ChunkContextConfig::new(meta, &challenges);
let evm_circuit = EvmCircuitConfig::new(
meta,
EvmCircuitConfigArgs {
@@ -357,6 +361,7 @@ fn record_stats<F: eth_types::Field>(
u8_table,
u16_table,
sig_table,
chunk_ctx_config,
feature_config,
},
);
9 changes: 9 additions & 0 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ pub struct EvmCircuitConfig<F> {
copy_table: CopyTable,
keccak_table: KeccakTable,
exp_table: ExpTable,
sig_table: SigTable,
/// rw permutation config
pub rw_permutation_config: PermutationChipConfig<F>,

@@ -84,6 +85,8 @@ pub struct EvmCircuitConfigArgs<F: Field> {
pub u8_table: UXTable<8>,
/// U16Table
pub u16_table: UXTable<16>,
/// SigTable
pub sig_table: SigTable,
/// chunk_ctx config
pub chunk_ctx_config: ChunkContextConfig<F>,
/// Feature config
@@ -107,6 +110,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
exp_table,
u8_table,
u16_table,
sig_table,
chunk_ctx_config,
feature_config,
}: Self::ConfigArgs,
@@ -126,6 +130,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
&copy_table,
&keccak_table,
&exp_table,
&sig_table,
&chunk_ctx_config.chunk_ctx_table,
&chunk_ctx_config.is_first_chunk,
&chunk_ctx_config.is_last_chunk,
@@ -144,6 +149,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
exp_table.annotate_columns(meta);
u8_table.annotate_columns(meta);
u16_table.annotate_columns(meta);
sig_table.annotate_columns(meta);
chunk_ctx_config.chunk_ctx_table.annotate_columns(meta);

let rw_permutation_config = PermutationChip::configure(
@@ -166,6 +172,7 @@ impl<F: Field> SubCircuitConfig<F> for EvmCircuitConfig<F> {
copy_table,
keccak_table,
exp_table,
sig_table,
rw_permutation_config,
chunk_ctx_config,
pi_chunk_continuity,
@@ -529,6 +536,7 @@ impl<F: Field> Circuit<F> for EvmCircuit<F> {
exp_table,
u8_table,
u16_table,
sig_table,
chunk_ctx_config,
feature_config: params,
},
@@ -688,6 +696,7 @@ mod evm_circuit_stats {
max_bytecode: 512,
max_evm_rows: 0,
max_keccak_rows: 0,
max_vertical_circuit_rows: 0,
};
let builder = BlockData::new_from_geth_data_with_params(block.clone(), circuits_params)
.new_circuit_input_builder()
8 changes: 7 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@ use super::{
param::{
BLOCK_TABLE_LOOKUPS, BYTECODE_TABLE_LOOKUPS, CHUNK_CTX_TABLE_LOOKUPS, COPY_TABLE_LOOKUPS,
EXP_TABLE_LOOKUPS, FIXED_TABLE_LOOKUPS, KECCAK_TABLE_LOOKUPS, N_COPY_COLUMNS,
N_PHASE1_COLUMNS, N_U16_LOOKUPS, N_U8_LOOKUPS, RW_TABLE_LOOKUPS, TX_TABLE_LOOKUPS,
N_PHASE1_COLUMNS, N_U16_LOOKUPS, N_U8_LOOKUPS, RW_TABLE_LOOKUPS, SIG_TABLE_LOOKUPS,
TX_TABLE_LOOKUPS,
},
step::HasExecutionState,
util::{instrumentation::Instrument, CachedRegion, StoredExpression},
@@ -374,6 +375,7 @@ impl<F: Field> ExecutionConfig<F> {
copy_table: &dyn LookupTable<F>,
keccak_table: &dyn LookupTable<F>,
exp_table: &dyn LookupTable<F>,
sig_table: &dyn LookupTable<F>,
chunk_ctx_table: &dyn LookupTable<F>,
is_first_chunk: &IsZeroConfig<F>,
is_last_chunk: &IsZeroConfig<F>,
@@ -696,6 +698,7 @@ impl<F: Field> ExecutionConfig<F> {
copy_table,
keccak_table,
exp_table,
sig_table,
chunk_ctx_table,
&challenges,
&cell_manager,
@@ -1040,6 +1043,7 @@ impl<F: Field> ExecutionConfig<F> {
copy_table: &dyn LookupTable<F>,
keccak_table: &dyn LookupTable<F>,
exp_table: &dyn LookupTable<F>,
sig_table: &dyn LookupTable<F>,
chunk_ctx_table: &dyn LookupTable<F>,
challenges: &Challenges<Expression<F>>,
cell_manager: &CellManager<CMFixedWidthStrategy>,
@@ -1060,6 +1064,7 @@ impl<F: Field> ExecutionConfig<F> {
Table::Copy => copy_table,
Table::Keccak => keccak_table,
Table::Exp => exp_table,
Table::Sig => sig_table,
Table::ChunkCtx => chunk_ctx_table,
}
.table_exprs(meta);
@@ -1351,6 +1356,7 @@ impl<F: Field> ExecutionConfig<F> {
("EVM_lookup_copy", COPY_TABLE_LOOKUPS),
("EVM_lookup_keccak", KECCAK_TABLE_LOOKUPS),
("EVM_lookup_exp", EXP_TABLE_LOOKUPS),
("EVM_lookup_sig", SIG_TABLE_LOOKUPS),
("EVM_lookupchunk_ctx", CHUNK_CTX_TABLE_LOOKUPS),
("EVM_adv_phase2", N_PHASE2_COLUMNS),
("EVM_copy", N_COPY_COLUMNS),
7 changes: 5 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
@@ -21,13 +21,16 @@ use crate::{
},
witness::{Block, Call, ExecStep, Transaction},
},
util::word::{WordCell, WordExpr},
util::word::WordExpr,
};

use crate::{
evm_circuit::witness::Chunk,
table::{AccountFieldTag, CallContextFieldTag},
util::Expr,
util::{
word::{WordLoHi, WordLoHiCell},
Expr,
},
};
use bus_mapping::{
circuit_input_builder::CopyDataType,
23 changes: 11 additions & 12 deletions zkevm-circuits/src/evm_circuit/execution/end_block.rs
Original file line number Diff line number Diff line change
@@ -15,14 +15,14 @@ use crate::{
table::{CallContextFieldTag, TxContextFieldTag},
util::{word::WordLoHi, Expr},
};
use eth_types::Field;
use eth_types::{Field, OpsIdentity};
use halo2_proofs::{circuit::Value, plonk::Error};

#[derive(Clone, Debug)]
pub(crate) struct EndBlockGadget<F> {
total_txs: Cell<F>,
total_txs_is_max_txs: IsEqualGadget<F>,
is_empty_rwc: IsZeroGadget<F>,
is_empty_block: IsEqualGadget<F>,
max_txs: Cell<F>,
rw_table_padding_gadget: RwTablePaddingGadget<F>,
}
@@ -35,17 +35,17 @@ impl<F: Field> ExecutionGadget<F> for EndBlockGadget<F> {
fn configure(cb: &mut EVMConstraintBuilder<F>) -> Self {
let max_txs = cb.query_copy_cell();
let total_txs = cb.query_cell();
let total_txs_is_max_txs = IsEqualGadget::construct(cb, total_txs.expr(), max_txs.expr());
let is_empty_rwc =
IsZeroGadget::construct(cb, cb.curr.state.rw_counter.clone().expr() - 1.expr());
let total_txs_is_max_txs = cb.is_eq(total_txs.expr(), max_txs.expr());
// Note that rw_counter starts at 1
let is_empty_block = cb.is_eq(cb.curr.state.rw_counter.clone().expr(), 1.expr());

// 1. Constraint total_rws and total_txs witness values depending on the empty
// block case.
cb.condition(is_empty_rwc.expr(), |cb| {
cb.condition(is_empty_block.expr(), |cb| {
// 1a.
cb.require_equal("total_txs is 0 in empty block", total_txs.expr(), 0.expr());
});
cb.condition(not::expr(is_empty_rwc.expr()), |cb| {
cb.condition(not::expr(is_empty_block.expr()), |cb| {
// 1b. total_txs matches the tx_id that corresponds to the final step.
cb.call_context_lookup_read(
None,
@@ -107,7 +107,7 @@ impl<F: Field> ExecutionGadget<F> for EndBlockGadget<F> {
max_txs,
total_txs,
total_txs_is_max_txs,
is_empty_rwc,
is_empty_block,
rw_table_padding_gadget,
}
}
@@ -122,12 +122,11 @@ impl<F: Field> ExecutionGadget<F> for EndBlockGadget<F> {
_: &Call,
step: &ExecStep,
) -> Result<(), Error> {
let total_rwc = u64::from(step.rwc) - 1;
self.is_empty_rwc
.assign(region, offset, F::from(total_rwc))?;
self.is_empty_block
.assign(region, offset, F::from(u64::from(step.rwc)), F::ONE)?;

let inner_rws_before_padding =
step.rwc_inner_chunk.0 as u64 - 1 + if total_rwc > 0 { 1 } else { 0 };
step.rwc_inner_chunk.0 as u64 - 1 + if u64::from(step.rwc) > 1 { 1 } else { 0 };
self.rw_table_padding_gadget.assign_exec_step(
region,
offset,
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/invalid_tx.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ use crate::{
witness::{Block, Call, ExecStep, Transaction},
},
table::AccountFieldTag,
util::word::{Word32Cell, WordExpr},
util::word::{Word32Cell, WordExpr, WordLoHi},
witness::Chunk,
};
use eth_types::{Field, ToScalar};
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ use crate::{
},
table::CallContextFieldTag,
util::word::{Word32Cell, WordExpr, WordLimbs, WordLoHi, WordLoHiCell},
witness::{Block, Call, ExecStep, Transaction},
witness::{Block, Call, Chunk, ExecStep, Transaction},
};

#[derive(Clone, Debug)]
@@ -206,6 +206,7 @@ impl<F: Field> ExecutionGadget<F> for EcrecoverGadget<F> {
region: &mut CachedRegion<'_, '_, F>,
offset: usize,
block: &Block<F>,
_chunk: &Chunk<F>,
_tx: &Transaction,
call: &Call,
step: &ExecStep,
7 changes: 6 additions & 1 deletion zkevm-circuits/src/evm_circuit/param.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use halo2_proofs::{
use std::collections::HashMap;

// Step dimension
pub(crate) const STEP_WIDTH: usize = 138;
pub(crate) const STEP_WIDTH: usize = 139;
/// Step height
pub const MAX_STEP_HEIGHT: usize = 19;
/// The height of the state of a step, used by gates that connect two
@@ -43,6 +43,7 @@ pub(crate) const EVM_LOOKUP_COLS: usize = FIXED_TABLE_LOOKUPS
+ COPY_TABLE_LOOKUPS
+ KECCAK_TABLE_LOOKUPS
+ EXP_TABLE_LOOKUPS
+ SIG_TABLE_LOOKUPS
+ CHUNK_CTX_TABLE_LOOKUPS;

/// Lookups done per row.
@@ -55,6 +56,7 @@ pub const LOOKUP_CONFIG: &[(Table, usize)] = &[
(Table::Copy, COPY_TABLE_LOOKUPS),
(Table::Keccak, KECCAK_TABLE_LOOKUPS),
(Table::Exp, EXP_TABLE_LOOKUPS),
(Table::Sig, SIG_TABLE_LOOKUPS),
(Table::ChunkCtx, CHUNK_CTX_TABLE_LOOKUPS),
];

@@ -82,6 +84,9 @@ pub const KECCAK_TABLE_LOOKUPS: usize = 1;
/// Exp Table lookups done in EVMCircuit
pub const EXP_TABLE_LOOKUPS: usize = 1;

/// Sig Table lookups done in EVMCircuit
pub const SIG_TABLE_LOOKUPS: usize = 1;

/// chunk_ctx Table lookups done in EVMCircuit
pub const CHUNK_CTX_TABLE_LOOKUPS: usize = 1;

34 changes: 31 additions & 3 deletions zkevm-circuits/src/evm_circuit/table.rs
Original file line number Diff line number Diff line change
@@ -191,6 +191,8 @@ pub enum Table {
Keccak,
/// Lookup for exp table
Exp,
/// Lookup for sig table
Sig,
/// Lookup for chunk context
ChunkCtx,
}
@@ -361,13 +363,22 @@ pub(crate) enum Lookup<F> {
exponent_lo_hi: [Expression<F>; 2],
exponentiation_lo_hi: [Expression<F>; 2],
},
SigTable {
msg_hash: WordLoHi<Expression<F>>,
sig_v: Expression<F>,
sig_r: WordLoHi<Expression<F>>,
sig_s: WordLoHi<Expression<F>>,
recovered_addr: Expression<F>,
is_valid: Expression<F>,
},
/// Lookup to block table, which contains constants of this block.
ChunkCtx {
/// Tag to specify which field to read.
field_tag: Expression<F>,
/// value
value: Expression<F>,
},

/// Conditional lookup enabled by the first element.
Conditional(Expression<F>, Box<Lookup<F>>),
}
@@ -507,9 +518,26 @@ impl<F: Field> Lookup<F> {
exponentiation_lo_hi[0].clone(),
exponentiation_lo_hi[1].clone(),
],
Self::ChunkCtx { field_tag, value } => {
vec![field_tag.clone(), value.clone()]
}
Self::SigTable {
msg_hash,
sig_v,
sig_r,
sig_s,
recovered_addr,
is_valid,
} => vec![
1.expr(), // q_enable
msg_hash.lo(),
msg_hash.hi(),
sig_v.clone(),
sig_r.lo(),
sig_r.hi(),
sig_s.lo(),
sig_s.hi(),
recovered_addr.clone(),
is_valid.clone(),
],
Self::ChunkCtx { field_tag, value } => vec![field_tag.clone(), value.clone()],
Self::Conditional(condition, lookup) => lookup
.input_exprs()
.into_iter()
Loading
Loading
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.