Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* WIP

* Join EVM + TxCircuit

* WIP clean

* WIP add bytecode circuit

* Fix tx_circuit compat with EVM

* Add bytecode circuit to super circuit

* WIP

* Fix bytecode assignment

* Harmonize tables

* Reuse keccak table between TxCircuit and BytecodeCircuit

* WIP

* WIP

* WIP

* Do some clean ups

* WIP

* Move cross-circuit table stuff to src/table.rs

* cargo fmt

* Document pub stuff

* Fix merge

* Pass clippy

* WIP

* Abstract CopyTable from CopyCircuit

* Mark super circuit test as serial

* Introduce Super Circuit and adapt existing circuits for it

The SuperCircuit is a new circuit that will contain all the circuits of the
zkEVM in order to achieve two things:
- Check the correct integration between circuits via the shared lookup tables
- Allow having a single circuit setup for which a proof can be generated that
would be verified under a single aggregation circuit for the first milestone

Summary of changes:
- general:
  - Addapt the circuits so that the shared tables can be assigned outside of
    the circuit's assign functions.

- evm_circuit.rs
  - load table functions moved to `table.rs`

- bytecode_circuit/bytecode_unroller.rs
  - Rename `hash_length` to `code_length` in `Config`
  - Rename `r` to `randomness`
  - Add `is_enabled` expression to the keccak lookup
  - Move `load_keccaks` to `table.rs`
  - Fix endianness in keccak hash output
  - Add function to obtain all the keccak inputs required by the `SignVerifyChip`

- table.rs
  - Move table definitions from `evm_circuit/table.rs` and `rw_table.rs` to here
  - Move all shared table load functions to here
  - Add BytecodeTable to help reusing the table config with other
  - Rename `hash` to `code_hash` in `BytecodeTable`
  - Use `RLC(reversed(input))` in keccak table assignment for `input_rlc`.

- tx_circuit.rs
  - Add function to obtain all the keccak inputs required by the `TxCircuit`
  - Fix `Gas` encoding: remove RLC
  - Add missing field `TxFieldTag::CallDataGasCost`

- tx_circuit/sign_verify.rs
  - Move `load_keccak` to `table.rs`
  - Add function to obtain all the keccak inputs required by the `SignVerifyChip`
  - Reverse the `pk_hash` used in the lookup so that the RLC is calculated as if
    it was a hash in an Ethereum Word.

* Reset our halo2 fork

* Address comments from @han0110 and @lispc
  • Loading branch information
ed255 authored Jul 28, 2022
1 parent 7c759ee commit 9e4701e
Show file tree
Hide file tree
Showing 42 changed files with 1,903 additions and 1,160 deletions.
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eth_types::{
GethExecStep, H256,
};
use gadgets::impl_expr;
use halo2_proofs::{arithmetic::FieldExt, plonk::Expression};
use halo2_proofs::plonk::Expression;
use strum_macros::EnumIter;

/// An execution step of the EVM.
Expand Down Expand Up @@ -201,7 +201,7 @@ pub enum NumberOrHash {

/// Defines a copy event associated with EVM opcodes such as CALLDATACOPY,
/// CODECOPY, CREATE, etc. More information:
/// https://github.com/privacy-scaling-explorations/zkevm-specs/blob/master/specs/copy-proof.md.
/// <https://github.com/privacy-scaling-explorations/zkevm-specs/blob/master/specs/copy-proof.md>.
#[derive(Clone, Debug)]
pub struct CopyEvent {
/// Represents the start address at the source of the copy event.
Expand Down
9 changes: 5 additions & 4 deletions circuit-benchmarks/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use halo2_proofs::{
plonk::{Circuit, ConstraintSystem, Error, Expression},
};
use zkevm_circuits::evm_circuit::{witness::Block, EvmCircuit};
use zkevm_circuits::table::{BlockTable, BytecodeTable, RwTable, TxTable};

#[derive(Debug, Default)]
pub struct TestCircuit<F> {
Expand All @@ -21,10 +22,10 @@ impl<F: Field> Circuit<F> for TestCircuit<F> {
}

fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
let tx_table = [(); 4].map(|_| meta.advice_column());
let rw_table = [(); 11].map(|_| meta.advice_column());
let bytecode_table = [(); 5].map(|_| meta.advice_column());
let block_table = [(); 3].map(|_| meta.advice_column());
let tx_table = TxTable::construct(meta);
let rw_table = RwTable::construct(meta);
let bytecode_table = BytecodeTable::construct(meta);
let block_table = BlockTable::construct(meta);
let copy_table = [(); 11].map(|_| meta.advice_column());
// Use constant expression to mock constant instance column for a more
// reasonable benchmark.
Expand Down
4 changes: 2 additions & 2 deletions gadgets/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ pub trait Expr<F: FieldExt> {
#[macro_export]
macro_rules! impl_expr {
($type:ty) => {
impl<F: FieldExt> $crate::util::Expr<F> for $type {
impl<F: halo2_proofs::arithmetic::FieldExt> $crate::util::Expr<F> for $type {
#[inline]
fn expr(&self) -> Expression<F> {
Expression::Constant(F::from(*self as u64))
}
}
};
($type:ty, $method:path) => {
impl<F: FieldExt> $crate::util::Expr<F> for $type {
impl<F: halo2_proofs::arithmetic::FieldExt> $crate::util::Expr<F> for $type {
#[inline]
fn expr(&self) -> Expression<F> {
Expression::Constant(F::from($method(self) as u64))
Expand Down
Loading

0 comments on commit 9e4701e

Please sign in to comment.