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

Commit

Permalink
Add empty_hash_word as a global function
Browse files Browse the repository at this point in the history
  • Loading branch information
leolara committed Jun 17, 2023
1 parent 69043d0 commit 0ce0a6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
20 changes: 3 additions & 17 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use crate::{
evm_circuit::util::{
and,
constraint_builder::{BaseConstraintBuilder, ConstrainBuilderCommon},
from_bytes, not, or, rlc, select,
not, or, rlc, select,
},
table::{BytecodeFieldTag, BytecodeTable, KeccakTable, LookupTable},
util::{
get_push_size,
word::{Word, Word32, WordExpr},
word::{empty_code_hash_word_value, Word, Word32, WordExpr},
Challenges, Expr, SubCircuit, SubCircuitConfig,
},
witness,
Expand Down Expand Up @@ -502,15 +502,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
.evm_word()
.map(|challenge| rlc::value(EMPTY_CODE_HASH_LE.as_ref(), challenge));

let empty_hash_word = Word::new(
EMPTY_CODE_HASH_LE
.chunks(32 / 2)
.map(|bytes: &[u8]| Value::known(from_bytes::value::<F>(bytes)))
.collect_vec()
.try_into()
.unwrap(),
);

layouter.assign_region(
|| "assign bytecode",
|mut region| {
Expand All @@ -526,7 +517,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
&push_data_left_is_zero_chip,
&index_length_diff_is_zero_chip,
empty_hash,
empty_hash_word,
&mut offset,
last_row_offset,
fail_fast,
Expand All @@ -540,7 +530,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
&push_data_left_is_zero_chip,
&index_length_diff_is_zero_chip,
empty_hash,
empty_hash_word,
idx,
last_row_offset,
)?;
Expand Down Expand Up @@ -605,7 +594,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
push_data_left_is_zero_chip: &IsZeroChip<F>,
index_length_diff_is_zero_chip: &IsZeroChip<F>,
empty_hash: Value<F>,
empty_hash_word: Word<Value<F>>,
offset: &mut usize,
last_row_offset: usize,
fail_fast: bool,
Expand Down Expand Up @@ -707,7 +695,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
push_data_left_is_zero_chip,
index_length_diff_is_zero_chip,
empty_hash,
empty_hash_word,
*offset,
last_row_offset,
)?;
Expand All @@ -723,7 +710,6 @@ impl<F: Field> BytecodeCircuitConfig<F> {
push_data_left_is_zero_chip: &IsZeroChip<F>,
index_length_diff_is_zero_chip: &IsZeroChip<F>,
empty_hash: Value<F>,
empty_hash_word: Word<Value<F>>,
offset: usize,
last_row_offset: usize,
) -> Result<(), Error> {
Expand All @@ -735,7 +721,7 @@ impl<F: Field> BytecodeCircuitConfig<F> {
offset <= last_row_offset,
offset == last_row_offset,
empty_hash,
empty_hash_word,
empty_code_hash_word_value(),
F::from(BytecodeFieldTag::Header as u64),
F::ZERO,
F::ZERO,
Expand Down
12 changes: 12 additions & 0 deletions zkevm-circuits/src/util/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// - Limbs: An EVN word is 256 bits. Limbs N means split 256 into N limb. For example, N = 4, each
// limb is 256/4 = 64 bits

use bus_mapping::state_db::EMPTY_CODE_HASH_LE;
use eth_types::{Field, ToLittleEndian, H160};
use gadgets::util::{not, or, Expr};
use halo2_proofs::{
Expand Down Expand Up @@ -478,4 +479,15 @@ impl<F: Field> From<WordLegacy<F>> for Word32Cell<F> {
}
}

pub fn empty_code_hash_word_value<F: Field>() -> Word<Value<F>> {
Word::new(
EMPTY_CODE_HASH_LE
.chunks(32 / 2)
.map(|bytes: &[u8]| Value::known(from_bytes::value(bytes)))
.collect_vec()
.try_into()
.unwrap(),
)
}

// TODO unittest

0 comments on commit 0ce0a6d

Please sign in to comment.