Skip to content

Commit

Permalink
feat: poseidon circuit and poseidon bytecode circuit (scroll-tech#291)
Browse files Browse the repository at this point in the history
* mpt_circuit: trival update (vk not compatible)

update mpt-circuit

Squashed commit of the following:

commit f114ba575f10961cda1fa3b89d93d028305f3357
Author: Ho Vei <noelwei@gmail.com>
Date:   Tue Jan 31 23:34:07 2023 +0800

    fix issues, make circuit work

commit 06412deafa68435c8c5d968add13d4aaf84549ca
Author: Ho Vei <noelwei@gmail.com>
Date:   Tue Jan 31 17:29:37 2023 +0800

    include poseidon codehash extension

commit 00d705b7cea50d2f4adcf9ce26e8aab0f444765a
Author: Ho Vei <noelwei@gmail.com>
Date:   Tue Jan 31 10:17:02 2023 +0800

    add hash block unrolling entry

commit f7bd7b298b1d775ede53f118f8d532e83ffcc329
Author: Ho Vei <noelwei@gmail.com>
Date:   Tue Jan 31 00:28:58 2023 +0800

    bytecode_hash_block extend

refactor to fit the upstream for poseidon codehash feat

* fmt

induce poseidon circuit

trivial

fix issue in feature poseidon-codehash

open an required method in supercircuit

* update mpt circuit dep and trivial fixings

* lint

---------

Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com>
  • Loading branch information
noel2004 and lispc authored Feb 9, 2023
1 parent 4dd7b83 commit 62b6349
Show file tree
Hide file tree
Showing 17 changed files with 1,160 additions and 215 deletions.
43 changes: 5 additions & 38 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ members = [
"mock",
]

[patch.crates-io]
# temporary solution to funty@1.2.0 being yanked, tracking issue: https://github.com/ferrilab/funty/issues/7
funty = { git = "https://github.com/ferrilab/funty/", rev = "7ef0d890fbcd8b3def1635ac1a877fc298488446" }

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "scroll-dev-0220" }

Expand Down
2 changes: 1 addition & 1 deletion eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ num = "0.4"
num-bigint = { version = "0.4" }
strum_macros = "0.24"
strum = "0.24"
mpt-circuits = { package = "halo2-mpt-circuits", git = "https://github.com/scroll-tech/mpt-circuit.git", branch = "scroll-dev-0111-halo2-upgrade" }
mpt-circuits = { package = "halo2-mpt-circuits", git = "https://github.com/scroll-tech/mpt-circuit.git", branch = "scroll-dev-0129" }
[features]
default = ["warn-unimplemented"]
warn-unimplemented = []
1 change: 1 addition & 0 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ zktrie = []
enable-sign-verify = []
codehash = []
reject-eip2718 = []
poseidon-codehash = []
12 changes: 12 additions & 0 deletions zkevm-circuits/src/bytecode_circuit/bytecode_unroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ pub fn unroll_with_codehash<F: Field>(code_hash: U256, bytes: Vec<u8>) -> Unroll
}
UnrolledBytecode { bytes, rows }
}

/// re-export bytes wrapped in hash field
pub use super::circuit::to_poseidon_hash::HASHBLOCK_BYTES_IN_FIELD;
use crate::table::PoseidonTable;

/// Apply default constants in mod
pub fn unroll_to_hash_input_default<F: Field>(
code: impl ExactSizeIterator<Item = u8>,
) -> Vec<[F; PoseidonTable::INPUT_WIDTH]> {
use super::circuit::to_poseidon_hash::unroll_to_hash_input;
unroll_to_hash_input::<F, HASHBLOCK_BYTES_IN_FIELD, { PoseidonTable::INPUT_WIDTH }>(code)
}
9 changes: 9 additions & 0 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use super::{
param::PUSH_TABLE_WIDTH,
};

/// An extended circuit for binding with poseidon
pub mod to_poseidon_hash;

#[cfg(feature = "onephase")]
use halo2_proofs::plonk::FirstPhase as SecondPhase;
#[cfg(not(feature = "onephase"))]
Expand Down Expand Up @@ -755,6 +758,12 @@ impl<F: Field> BytecodeCircuit<F> {
}

impl<F: Field> SubCircuit<F> for BytecodeCircuit<F> {
#[cfg(feature = "poseidon-codehash")]
type Config = to_poseidon_hash::ToHashBlockCircuitConfig<
F,
{ to_poseidon_hash::HASHBLOCK_BYTES_IN_FIELD },
>;
#[cfg(not(feature = "poseidon-codehash"))]
type Config = BytecodeCircuitConfig<F>;

fn new_from_block(block: &witness::Block<F>) -> Self {
Expand Down
Loading

0 comments on commit 62b6349

Please sign in to comment.