Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 8ba838b

Browse files
authored
Replace word::Word with WordLoHi (privacy-scaling-explorations#1747)
### Description Replacing Word with WordHiLo. ### Issue Link privacy-scaling-explorations#1736 ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update - [x] Refactor ### Contents - Replace word::Word with WordLoHi - Replace word::WordCell with WordLoHiCell ### Rationale - WordLimbs and WordCell is used somewhere so couldn't go with that. - ZWord and CWord could be used, however, I saw that Word is actually an alias for Word2 ([source](https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/7f356548dd6dd614289b9700a40fbc80c4949b47/zkevm-circuits/src/util/word.rs#L203)). Which is an alias of WordLimbs<2>. So Word2 could be better than ZWord or CWord, but I think WordHiLo is even better and makes the code more obvious, since we have hi-lo terminology in many places. ### How Has This Been Tested? Built all packages locally.
1 parent be9fed5 commit 8ba838b

File tree

109 files changed

+968
-935
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

+968
-935
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [ ] New feature (non-breaking change which adds functionality)
1313
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
1414
- [ ] This change requires a documentation update
15+
- [ ] Refactor (no updates to logic)
1516

1617
### Contents
1718

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

Lines changed: 7 additions & 7 deletions
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::WordLoHi;
1313

1414
#[derive(Clone, Debug)]
15-
pub struct EqualWordsConfig<F: Field>(Word<IsZeroConfig<F>>);
15+
pub struct EqualWordsConfig<F: Field>(WordLoHi<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: (WordLoHi<Column<Advice>>, Rotation),
21+
second: (WordLoHi<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(WordLoHi::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: &WordLoHi<F>,
58+
second: &WordLoHi<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

Lines changed: 6 additions & 6 deletions
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::WordLoHi, 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: WordLoHi::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: WordLoHi::new([meta.advice_column(), meta.advice_column()]),
123+
old_root: WordLoHi::new([meta.advice_column(), meta.advice_column()]),
124+
new_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]),
125+
old_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]),
126126
};
127127

128128
for col in [

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

Lines changed: 9 additions & 11 deletions
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::WordLoHi,
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: WordLoHi<F>,
84+
pub key: WordLoHi<F>,
85+
pub old_root: WordLoHi<F>,
86+
pub new_root: WordLoHi<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: WordLoHi::<F>::from(value),
352+
key: WordLoHi::<F>::from(key),
353+
old_root: WordLoHi::<F>::from(from_root),
354+
new_root: WordLoHi::<F>::from(to_root),
357355
};
358356
lc_proofs.push(lc_proof);
359357
}

zkevm-circuits/src/bytecode_circuit.rs

Lines changed: 12 additions & 6 deletions
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, WordLoHi},
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: WordLoHi<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: WordLoHi<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 = WordLoHi::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: WordLoHi<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

Lines changed: 5 additions & 5 deletions
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::WordLoHi, 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 WordLoHiCell<F> = WordLoHi<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> WordLoHiCell<F> {
109+
pub fn expr(&self) -> WordLoHi<Expression<F>> {
110+
WordLoHi::new([self.lo().expr(), self.hi().expr()])
111111
}
112112
}
113113

zkevm-circuits/src/circuit_tools/constraint_builder.rs

Lines changed: 5 additions & 5 deletions
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::WordLoHi, 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, WordLoHiCell},
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) -> WordLoHiCell<F> {
356+
WordLoHi::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 WordLoHi<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

Lines changed: 8 additions & 8 deletions
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, WordLoHi},
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: &WordLoHi<Expression<F>>,
111+
rhs: &WordLoHi<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: WordLoHi<F>,
133+
rhs: WordLoHi<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<WordLoHi<F>>,
147+
rhs: Value<WordLoHi<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, WordLoHi::from(lhs), WordLoHi::from(rhs))
163163
}
164164
}
165165

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use crate::util::word::Word;
1+
use crate::util::word::WordLoHi;
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) -> WordLoHi<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) => WordLoHi::from(*n as u64).into_value(),
10+
NumberOrHash::Hash(h) => WordLoHi::from(*h).into_value(),
1111
}
1212
}

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

Lines changed: 3 additions & 3 deletions
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, WordLoHi},
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(WordLoHi::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(WordLoHi::select(is_sub.expr().0, a.to_word(), c.to_word()));
6060

6161
// State transition
6262
let step_state_transition = StepStateTransition {

0 commit comments

Comments
 (0)