Skip to content

Commit

Permalink
feat: mitigate the long testing time by allowing partial fixed table (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
han0110 authored Nov 25, 2021
1 parent 08c08df commit cda9ee2
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 131 deletions.
237 changes: 129 additions & 108 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ impl<F: FieldExt> EvmCircuit<F> {
fn load_fixed_tables(
&self,
layouter: &mut impl Layouter<F>,
including_large_tables: bool,
) -> Result<(), Error> {
layouter.assign_region(
|| "fixed table",
Expand Down Expand Up @@ -872,129 +873,143 @@ impl<F: FieldExt> EvmCircuit<F> {
offset += 1;
}

// BitwiseAnd
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) & (b as u64);
region.assign_fixed(
|| "BitwiseAnd: tag",
self.fixed_table[0],
offset,
|| Ok(F::from_u64(FixedLookup::BitwiseAnd as u64)),
)?;
region.assign_fixed(
|| "BitwiseAnd: a",
self.fixed_table[1],
offset,
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| "BitwiseAnd: b",
self.fixed_table[2],
offset,
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| "BitwiseAnd: a&b",
self.fixed_table[3],
offset,
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
if including_large_tables {
// BitwiseAnd
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) & (b as u64);
region.assign_fixed(
|| "BitwiseAnd: tag",
self.fixed_table[0],
offset,
|| {
Ok(F::from_u64(
FixedLookup::BitwiseAnd as u64,
))
},
)?;
region.assign_fixed(
|| "BitwiseAnd: a",
self.fixed_table[1],
offset,
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| format!("BitwiseAnd: padding {}", idx),
*column,
|| "BitwiseAnd: b",
self.fixed_table[2],
offset,
|| Ok(F::zero()),
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| "BitwiseAnd: a&b",
self.fixed_table[3],
offset,
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
region.assign_fixed(
|| format!("BitwiseAnd: padding {}", idx),
*column,
offset,
|| Ok(F::zero()),
)?;
}
offset += 1;
}
offset += 1;
}
}

// BitwiseOr
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) | (b as u64);
region.assign_fixed(
|| "BitwiseOr: tag",
self.fixed_table[0],
offset,
|| Ok(F::from_u64(FixedLookup::BitwiseOr as u64)),
)?;
region.assign_fixed(
|| "BitwiseOr: a",
self.fixed_table[1],
offset,
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| "BitwiseOr: b",
self.fixed_table[2],
offset,
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| "BitwiseOr: a|b",
self.fixed_table[3],
offset,
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
// BitwiseOr
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) | (b as u64);
region.assign_fixed(
|| "BitwiseOr: tag",
self.fixed_table[0],
offset,
|| {
Ok(F::from_u64(
FixedLookup::BitwiseOr as u64,
))
},
)?;
region.assign_fixed(
|| "BitwiseOr: a",
self.fixed_table[1],
offset,
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| "BitwiseOr: b",
self.fixed_table[2],
offset,
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| format!("BitwiseOr: padding {}", idx),
*column,
|| "BitwiseOr: a|b",
self.fixed_table[3],
offset,
|| Ok(F::zero()),
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
region.assign_fixed(
|| format!("BitwiseOr: padding {}", idx),
*column,
offset,
|| Ok(F::zero()),
)?;
}
offset += 1;
}
offset += 1;
}
}

// BitwiseXor
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) ^ (b as u64);
region.assign_fixed(
|| "BitwiseXor: tag",
self.fixed_table[0],
offset,
|| Ok(F::from_u64(FixedLookup::BitwiseXor as u64)),
)?;
region.assign_fixed(
|| "BitwiseXor: a",
self.fixed_table[1],
offset,
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| "BitwiseXor: b",
self.fixed_table[2],
offset,
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| "BitwiseXor: a^b",
self.fixed_table[3],
offset,
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
// BitwiseXor
for a in 0..256 {
for b in 0..256 {
let c = (a as u64) ^ (b as u64);
region.assign_fixed(
|| "BitwiseXor: tag",
self.fixed_table[0],
offset,
|| {
Ok(F::from_u64(
FixedLookup::BitwiseXor as u64,
))
},
)?;
region.assign_fixed(
|| format!("BitwiseXor: padding {}", idx),
*column,
|| "BitwiseXor: a",
self.fixed_table[1],
offset,
|| Ok(F::zero()),
|| Ok(F::from_u64(a)),
)?;
region.assign_fixed(
|| "BitwiseXor: b",
self.fixed_table[2],
offset,
|| Ok(F::from_u64(b)),
)?;
region.assign_fixed(
|| "BitwiseXor: a^b",
self.fixed_table[3],
offset,
|| Ok(F::from_u64(c)),
)?;
for (idx, column) in
self.fixed_table[4..].iter().enumerate()
{
region.assign_fixed(
|| format!("BitwiseXor: padding {}", idx),
*column,
offset,
|| Ok(F::zero()),
)?;
}
offset += 1;
}
offset += 1;
}
}

Expand Down Expand Up @@ -1115,16 +1130,19 @@ mod test {
pub(crate) struct TestCircuit<F> {
execution_steps: Vec<ExecutionStep>,
operations: Vec<Operation<F>>,
including_large_tables: bool,
}

impl<F> TestCircuit<F> {
pub fn new(
execution_steps: Vec<ExecutionStep>,
operations: Vec<Operation<F>>,
including_large_tables: bool,
) -> Self {
Self {
execution_steps,
operations,
including_large_tables,
}
}
}
Expand All @@ -1149,7 +1167,10 @@ mod test {
config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
config.evm_circuit.load_fixed_tables(&mut layouter)?;
config.evm_circuit.load_fixed_tables(
&mut layouter,
self.including_large_tables,
)?;
config
.evm_circuit
.load_rw_tables(&mut layouter, &self.operations)?;
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/arithmetic/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
TestCircuit::<Base>::new($execution_steps, $operations, true);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_step:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_step, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_step, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/jumpdest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/pop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/op_execution/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ mod test {
macro_rules! try_test_circuit {
($execution_steps:expr, $operations:expr, $result:expr) => {{
let circuit =
TestCircuit::<Base>::new($execution_steps, $operations);
let prover = MockProver::<Base>::run(18, &circuit, vec![]).unwrap();
TestCircuit::<Base>::new($execution_steps, $operations, false);
let prover = MockProver::<Base>::run(11, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), $result);
}};
}
Expand Down
Loading

0 comments on commit cda9ee2

Please sign in to comment.