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

Commit 8696420

Browse files
committed
Replace word::Word with WordHiLo
1 parent 7f35654 commit 8696420

File tree

109 files changed

+956
-921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+956
-921
lines changed

light-client-poc/src/circuit/equal_words.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ use halo2_proofs::{
99
plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector},
1010
poly::Rotation,
1111
};
12-
use zkevm_circuits::util::word::Word;
12+
use zkevm_circuits::util::word::WordHiLo;
1313

1414
#[derive(Clone, Debug)]
15-
pub struct EqualWordsConfig<F: Field>(Word<IsZeroConfig<F>>);
15+
pub struct EqualWordsConfig<F: Field>(WordHiLo<IsZeroConfig<F>>);
1616
impl<F: Field> EqualWordsConfig<F> {
1717
pub fn configure(
1818
meta: &mut ConstraintSystem<F>,
1919
q_enable: Selector,
20-
first: (Word<Column<Advice>>, Rotation),
21-
second: (Word<Column<Advice>>, Rotation),
20+
first: (WordHiLo<Column<Advice>>, Rotation),
21+
second: (WordHiLo<Column<Advice>>, Rotation),
2222
) -> Self {
2323
let lo_inv = meta.advice_column();
2424
let lo = IsZeroChip::configure(
@@ -42,7 +42,7 @@ impl<F: Field> EqualWordsConfig<F> {
4242
hi_inv,
4343
);
4444

45-
Self(Word::new([lo, hi]))
45+
Self(WordHiLo::new([lo, hi]))
4646
}
4747

4848
pub fn expr(&self) -> Expression<F> {
@@ -54,8 +54,8 @@ impl<F: Field> EqualWordsConfig<F> {
5454
region: &mut Region<'_, F>,
5555
offset: usize,
5656
name: &str,
57-
first: &Word<F>,
58-
second: &Word<F>,
57+
first: &WordHiLo<F>,
58+
second: &WordHiLo<F>,
5959
) -> Result<(), Error> {
6060
region.name_column(|| format!("{}_lo_inv", name), self.0.lo().value_inv);
6161
region.name_column(|| format!("{}_hi_inv", name), self.0.hi().value_inv);

light-client-poc/src/circuit/state_update.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use halo2_proofs::{
2121
use zkevm_circuits::{
2222
mpt_circuit::{MPTCircuit, MPTCircuitParams, MPTConfig},
2323
table::{KeccakTable, MptTable},
24-
util::{word, Challenges},
24+
util::{word::WordHiLo, Challenges},
2525
};
2626

2727
use super::witness::{
@@ -117,12 +117,12 @@ impl<F: Field> Circuit<F> for StateUpdateCircuit<F> {
117117
let pi_instance = meta.instance_column();
118118
let pi_mpt = MptTable {
119119
address: meta.advice_column(),
120-
storage_key: word::Word::new([meta.advice_column(), meta.advice_column()]),
120+
storage_key: WordHiLo::new([meta.advice_column(), meta.advice_column()]),
121121
proof_type: meta.advice_column(),
122-
new_root: word::Word::new([meta.advice_column(), meta.advice_column()]),
123-
old_root: word::Word::new([meta.advice_column(), meta.advice_column()]),
124-
new_value: word::Word::new([meta.advice_column(), meta.advice_column()]),
125-
old_value: word::Word::new([meta.advice_column(), meta.advice_column()]),
122+
new_root: WordHiLo::new([meta.advice_column(), meta.advice_column()]),
123+
old_root: WordHiLo::new([meta.advice_column(), meta.advice_column()]),
124+
new_value: WordHiLo::new([meta.advice_column(), meta.advice_column()]),
125+
old_value: WordHiLo::new([meta.advice_column(), meta.advice_column()]),
126126
};
127127

128128
for col in [

light-client-poc/src/circuit/witness.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use eyre::Result;
1515

1616
use mpt_witness_generator::{ProofType, TrieModification};
1717
use zkevm_circuits::{
18-
mpt_circuit::witness_row::Node,
19-
table::mpt_table::MPTProofType,
20-
util::word::{self, Word},
18+
mpt_circuit::witness_row::Node, table::mpt_table::MPTProofType, util::word::WordHiLo,
2119
};
2220

2321
#[derive(Default, Debug, Clone)]
@@ -82,10 +80,10 @@ pub struct StateUpdateWitness<F: Field> {
8280
pub struct SingleTrieModification<F: Field> {
8381
pub typ: F,
8482
pub address: F,
85-
pub value: word::Word<F>,
86-
pub key: word::Word<F>,
87-
pub old_root: word::Word<F>,
88-
pub new_root: word::Word<F>,
83+
pub value: WordHiLo<F>,
84+
pub key: WordHiLo<F>,
85+
pub old_root: WordHiLo<F>,
86+
pub new_root: WordHiLo<F>,
8987
}
9088

9189
#[derive(Default, Clone)]
@@ -350,10 +348,10 @@ impl<F: Field> StateUpdateWitness<F> {
350348
let lc_proof = SingleTrieModification::<F> {
351349
typ: F::from(proof_type as u64),
352350
address: address.to_scalar().unwrap(),
353-
value: Word::<F>::from(value),
354-
key: Word::<F>::from(key),
355-
old_root: Word::<F>::from(from_root),
356-
new_root: Word::<F>::from(to_root),
351+
value: WordHiLo::<F>::from(value),
352+
key: WordHiLo::<F>::from(key),
353+
old_root: WordHiLo::<F>::from(from_root),
354+
new_root: WordHiLo::<F>::from(to_root),
357355
};
358356
lc_proofs.push(lc_proof);
359357
}

zkevm-circuits/src/bytecode_circuit.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::{
1616
},
1717
table::{BytecodeFieldTag, BytecodeTable, KeccakTable, LookupTable},
1818
util::{
19-
self, get_push_size,
20-
word::{empty_code_hash_word_value, Word, Word32, WordExpr},
19+
get_push_size,
20+
word::{empty_code_hash_word_value, Word32, WordExpr, WordHiLo},
2121
Challenges, Expr, SubCircuit, SubCircuitConfig,
2222
},
2323
witness::{self},
@@ -40,7 +40,7 @@ const PUSH_TABLE_WIDTH: usize = 2;
4040
#[derive(Debug, Clone, Default)]
4141
/// Row for assignment
4242
pub(crate) struct BytecodeCircuitRow<F: Field> {
43-
pub(crate) code_hash: Word<Value<F>>,
43+
pub(crate) code_hash: WordHiLo<Value<F>>,
4444
tag: F,
4545
pub(crate) index: F,
4646
pub(crate) is_code: F,
@@ -52,7 +52,13 @@ pub(crate) struct BytecodeCircuitRow<F: Field> {
5252
}
5353
impl<F: Field> BytecodeCircuitRow<F> {
5454
#[cfg(test)]
55-
pub(crate) fn new(code_hash: Word<Value<F>>, tag: F, index: F, is_code: F, value: F) -> Self {
55+
pub(crate) fn new(
56+
code_hash: WordHiLo<Value<F>>,
57+
tag: F,
58+
index: F,
59+
is_code: F,
60+
value: F,
61+
) -> Self {
5662
Self {
5763
code_hash,
5864
tag,
@@ -89,7 +95,7 @@ impl<F: Field> From<Vec<Bytecode>> for BytecodeCircuitAssignment<F> {
8995
fn from(codes: Vec<Bytecode>) -> Self {
9096
let mut rows = vec![];
9197
for bytecode in codes.iter() {
92-
let code_hash = util::word::Word::from(bytecode.hash()).into_value();
98+
let code_hash = WordHiLo::from(bytecode.hash()).into_value();
9399
let code_size = bytecode.codesize();
94100
let head = BytecodeCircuitRow {
95101
code_hash,
@@ -366,7 +372,7 @@ impl<F: Field> SubCircuitConfig<F> for BytecodeCircuitConfig<F> {
366372
meta.query_advice(length, Rotation::cur()),
367373
);
368374

369-
let empty_hash_word: Word<Expression<F>> =
375+
let empty_hash_word: WordHiLo<Expression<F>> =
370376
Word32::new(*EMPTY_CODE_HASH_LE).to_expr().to_word();
371377

372378
cb.require_equal_word(

zkevm-circuits/src/circuit_tools/cell_manager.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
circuit_tools::cached_region::CachedRegion,
55
evm_circuit::util::rlc,
66
table::LookupTable,
7-
util::{query_expression, word::Word, Expr},
7+
util::{query_expression, word::WordHiLo, Expr},
88
};
99
use eth_types::Field;
1010
use halo2_proofs::{
@@ -103,11 +103,11 @@ impl<F: Field> Expr<F> for &Cell<F> {
103103
}
104104
}
105105

106-
pub(crate) type WordCell<F> = Word<Cell<F>>;
106+
pub(crate) type WordHiLoCell<F> = WordHiLo<Cell<F>>;
107107

108-
impl<F: Field> WordCell<F> {
109-
pub fn expr(&self) -> Word<Expression<F>> {
110-
Word::new([self.lo().expr(), self.hi().expr()])
108+
impl<F: Field> WordHiLoCell<F> {
109+
pub fn expr(&self) -> WordHiLo<Expression<F>> {
110+
WordHiLo::new([self.lo().expr(), self.hi().expr()])
111111
}
112112
}
113113

zkevm-circuits/src/circuit_tools/constraint_builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
use crate::{
1010
evm_circuit::util::rlc,
1111
table::LookupTable,
12-
util::{query_expression, word::Word, Expr},
12+
util::{query_expression, word::WordHiLo, Expr},
1313
};
1414
use eth_types::Field;
1515
use gadgets::util::{and, sum, Scalar};
@@ -18,7 +18,7 @@ use itertools::Itertools;
1818

1919
use super::{
2020
cached_region::StoredExpression,
21-
cell_manager::{Cell, CellManager, CellType, WordCell},
21+
cell_manager::{Cell, CellManager, CellType, WordHiLoCell},
2222
};
2323

2424
fn get_condition_expr<F: Field>(conditions: &Vec<Expression<F>>) -> Expression<F> {
@@ -352,8 +352,8 @@ impl<F: Field, C: CellType> ConstraintBuilder<F, C> {
352352
}
353353

354354
// default query_word is 2 limbs. Each limb is not guaranteed to be 128 bits.
355-
pub(crate) fn query_word_unchecked(&mut self) -> WordCell<F> {
356-
Word::new(self.query_cells_dyn(C::default(), 2).try_into().unwrap())
355+
pub(crate) fn query_word_unchecked(&mut self) -> WordHiLoCell<F> {
356+
WordHiLo::new(self.query_cells_dyn(C::default(), 2).try_into().unwrap())
357357
}
358358

359359
pub(crate) fn validate_degree(&self, degree: usize, name: &'static str) {
@@ -718,7 +718,7 @@ impl<F: Field, E: Expr<F>> ExprVec<F> for &[E] {
718718
}
719719
}
720720

721-
impl<F: Field, E: Expr<F> + Clone> ExprVec<F> for Word<E> {
721+
impl<F: Field, E: Expr<F> + Clone> ExprVec<F> for WordHiLo<E> {
722722
fn to_expr_vec(&self) -> Vec<Expression<F>> {
723723
vec![self.lo().expr(), self.hi().expr()]
724724
}

zkevm-circuits/src/circuit_tools/gadgets.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use halo2_proofs::{
88

99
use crate::{
1010
evm_circuit::util::{from_bytes, pow_of_two, transpose_val_ret},
11-
util::word::{Word, WordExpr},
11+
util::word::{WordExpr, WordHiLo},
1212
};
1313

1414
use super::{
@@ -107,8 +107,8 @@ pub struct IsEqualWordGadget<F> {
107107
impl<F: Field> IsEqualWordGadget<F> {
108108
pub(crate) fn construct<C: CellType>(
109109
cb: &mut ConstraintBuilder<F, C>,
110-
lhs: &Word<Expression<F>>,
111-
rhs: &Word<Expression<F>>,
110+
lhs: &WordHiLo<Expression<F>>,
111+
rhs: &WordHiLo<Expression<F>>,
112112
) -> Self {
113113
let (lhs_lo, lhs_hi) = lhs.to_word().to_lo_hi();
114114
let (rhs_lo, rhs_hi) = rhs.to_word().to_lo_hi();
@@ -129,8 +129,8 @@ impl<F: Field> IsEqualWordGadget<F> {
129129
&self,
130130
region: &mut CachedRegion<'_, '_, F>,
131131
offset: usize,
132-
lhs: Word<F>,
133-
rhs: Word<F>,
132+
lhs: WordHiLo<F>,
133+
rhs: WordHiLo<F>,
134134
) -> Result<F, Error> {
135135
let (lhs_lo, lhs_hi) = lhs.to_lo_hi();
136136
let (rhs_lo, rhs_hi) = rhs.to_lo_hi();
@@ -143,8 +143,8 @@ impl<F: Field> IsEqualWordGadget<F> {
143143
&self,
144144
region: &mut CachedRegion<'_, '_, F>,
145145
offset: usize,
146-
lhs: Value<Word<F>>,
147-
rhs: Value<Word<F>>,
146+
lhs: Value<WordHiLo<F>>,
147+
rhs: Value<WordHiLo<F>>,
148148
) -> Result<Value<F>, Error> {
149149
transpose_val_ret(
150150
lhs.zip(rhs)
@@ -159,7 +159,7 @@ impl<F: Field> IsEqualWordGadget<F> {
159159
lhs: eth_types::Word,
160160
rhs: eth_types::Word,
161161
) -> Result<F, Error> {
162-
self.assign(region, offset, Word::from(lhs), Word::from(rhs))
162+
self.assign(region, offset, WordHiLo::from(lhs), WordHiLo::from(rhs))
163163
}
164164
}
165165

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::util::word::Word;
1+
use crate::util::word::WordHiLo;
22
use bus_mapping::circuit_input_builder::NumberOrHash;
33
use eth_types::Field;
44
use halo2_proofs::circuit::Value;
55

66
/// Encode the type `NumberOrHash` into a field element
7-
pub fn number_or_hash_to_word<F: Field>(v: &NumberOrHash) -> Word<Value<F>> {
7+
pub fn number_or_hash_to_word<F: Field>(v: &NumberOrHash) -> WordHiLo<Value<F>> {
88
match v {
9-
NumberOrHash::Number(n) => Word::from(*n as u64).into_value(),
10-
NumberOrHash::Hash(h) => Word::from(*h).into_value(),
9+
NumberOrHash::Number(n) => WordHiLo::from(*n as u64).into_value(),
10+
NumberOrHash::Hash(h) => WordHiLo::from(*h).into_value(),
1111
}
1212
}

zkevm-circuits/src/evm_circuit/execution/add_sub.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
witness::{Block, Call, ExecStep, Transaction},
1212
},
1313
util::{
14-
word::{Word, WordExpr},
14+
word::{WordExpr, WordHiLo},
1515
Expr,
1616
},
1717
};
@@ -54,9 +54,9 @@ impl<F: Field> ExecutionGadget<F> for AddSubGadget<F> {
5454
// ADD: Pop a and b from the stack, push c on the stack
5555
// SUB: Pop c and b from the stack, push a on the stack
5656

57-
cb.stack_pop(Word::select(is_sub.expr().0, c.to_word(), a.to_word()));
57+
cb.stack_pop(WordHiLo::select(is_sub.expr().0, c.to_word(), a.to_word()));
5858
cb.stack_pop(b.to_word());
59-
cb.stack_push(Word::select(is_sub.expr().0, a.to_word(), c.to_word()));
59+
cb.stack_push(WordHiLo::select(is_sub.expr().0, a.to_word(), c.to_word()));
6060

6161
// State transition
6262
let step_state_transition = StepStateTransition {

zkevm-circuits/src/evm_circuit/execution/addmod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
witness::{Block, Call, ExecStep, Transaction},
1818
},
1919
util::{
20-
word::{Word, Word32Cell, WordExpr},
20+
word::{Word32Cell, WordExpr, WordHiLo},
2121
Expr,
2222
},
2323
};
@@ -94,7 +94,7 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {
9494
cb.require_equal_word(
9595
"check a_reduced + b 512 bit carry if n != 0",
9696
sum_areduced_b_overflow.to_word(),
97-
Word::from_lo_unchecked(sum_areduced_b.carry().clone().unwrap().expr())
97+
WordHiLo::from_lo_unchecked(sum_areduced_b.carry().clone().unwrap().expr())
9898
.mul_selector(not::expr(n_is_zero.expr())),
9999
);
100100

@@ -220,7 +220,7 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {
220220
self.cmp_areduced_n.assign(region, offset, a_reduced, n)?;
221221

222222
self.n_is_zero
223-
.assign_value(region, offset, Value::known(Word::from(n)))?;
223+
.assign_value(region, offset, Value::known(WordHiLo::from(n)))?;
224224

225225
Ok(())
226226
}

zkevm-circuits/src/evm_circuit/execution/address.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
},
1212
table::CallContextFieldTag,
1313
util::{
14-
word::{WordCell, WordExpr},
14+
word::{WordExpr, WordHiLoCell},
1515
Expr,
1616
},
1717
};
@@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error;
2222
#[derive(Clone, Debug)]
2323
pub(crate) struct AddressGadget<F> {
2424
same_context: SameContextGadget<F>,
25-
address: WordCell<F>,
25+
address: WordHiLoCell<F>,
2626
}
2727

2828
impl<F: Field> ExecutionGadget<F> for AddressGadget<F> {

zkevm-circuits/src/evm_circuit/execution/balance.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
},
1616
table::{AccountFieldTag, CallContextFieldTag},
1717
util::{
18-
word::{Word, Word32Cell, WordCell, WordExpr},
18+
word::{Word32Cell, WordExpr, WordHiLo, WordHiLoCell},
1919
Expr,
2020
},
2121
};
@@ -29,8 +29,8 @@ pub(crate) struct BalanceGadget<F> {
2929
reversion_info: ReversionInfo<F>,
3030
tx_id: Cell<F>,
3131
is_warm: Cell<F>,
32-
code_hash: WordCell<F>,
33-
not_exists: IsZeroWordGadget<F, WordCell<F>>,
32+
code_hash: WordHiLoCell<F>,
33+
not_exists: IsZeroWordGadget<F, WordHiLoCell<F>>,
3434
balance: Word32Cell<F>,
3535
}
3636

@@ -139,7 +139,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {
139139
self.code_hash
140140
.assign_u256(region, offset, code_hash.to_word())?;
141141
self.not_exists
142-
.assign_value(region, offset, Value::known(Word::from(code_hash)))?;
142+
.assign_value(region, offset, Value::known(WordHiLo::from(code_hash)))?;
143143
let balance = if code_hash.is_zero() {
144144
eth_types::Word::zero()
145145
} else {

0 commit comments

Comments
 (0)