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

Commit

Permalink
utility func renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed May 9, 2023
1 parent a3aa955 commit 088f583
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 32 deletions.
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/addmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {

cb.require_equal(
"check a_reduced + b 512 bit carry if n != 0",
sum_areduced_b_overflow.expr(),
sum_areduced_b_overflow.word_expr(),
sum_areduced_b.carry().clone().unwrap().expr() * not::expr(n_is_zero.expr()),
);

Expand All @@ -104,10 +104,10 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {

// pop/push values
// take care that if n==0 pushed value for r should be zero also
cb.stack_pop(a.expr());
cb.stack_pop(a.word_expr());
cb.stack_pop(b.expr());
cb.stack_pop(n.expr());
cb.stack_push(r.expr() * not::expr(n_is_zero.expr()));
cb.stack_push(r.word_expr() * not::expr(n_is_zero.expr()));

// State transition
let step_state_transition = StepStateTransition {
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
CallContextFieldTag::CallDataLength,
tx_call_data_length.expr(),
),
(CallContextFieldTag::Value, tx_value.expr()),
(CallContextFieldTag::Value, tx_value.word_expr()),
(CallContextFieldTag::IsStatic, 0.expr()),
(CallContextFieldTag::LastCalleeId, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
Expand Down Expand Up @@ -343,7 +343,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
CallContextFieldTag::CallDataLength,
tx_call_data_length.expr(),
),
(CallContextFieldTag::Value, tx_value.expr()),
(CallContextFieldTag::Value, tx_value.word_expr()),
(CallContextFieldTag::IsStatic, 0.expr()),
(CallContextFieldTag::LastCalleeId, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
CallContextFieldTag::Value,
select::expr(
is_delegatecall.expr(),
current_value.expr(),
current_value.word_expr(),
call_gadget.value.expr(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGStaticMemoryGadget<F> {

// Pop the address from the stack
// We still have to do this to verify the correctness of `address`
cb.stack_pop(address.expr());
cb.stack_pop(address.word_expr());

// TODO: Use ContextSwitchGadget to switch call context to caller's and
// consume all gas_left.
Expand Down
10 changes: 5 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ impl<F: Field> ExecutionGadget<F> for MulDivModGadget<F> {
// The second pop is multiplicand for MUL and divisor for DIV/MOD
// The push is product for MUL, quotient for DIV, and residue for MOD
// Note that for DIV/MOD, when divisor == 0, the push value is also 0.
cb.stack_pop(select::expr(is_mul.clone(), a.expr(), d.expr()));
cb.stack_pop(b.expr());
cb.stack_pop(select::expr(is_mul.clone(), a.word_expr(), d.word_expr()));
cb.stack_pop(b.word_expr());
cb.stack_push(
is_mul.clone() * d.expr()
+ is_div * a.expr() * (1.expr() - divisor_is_zero.expr())
+ is_mod * c.expr() * (1.expr() - divisor_is_zero.expr()),
is_mul.clone() * d.word_expr()
+ is_div * a.word_expr() * (1.expr() - divisor_is_zero.expr())
+ is_mod * c.word_expr() * (1.expr() - divisor_is_zero.expr()),
);

// Constraint for MUL case
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/mulmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ impl<F: Field> ExecutionGadget<F> for MulModGadget<F> {
1.expr() - lt.expr() - n_is_zero.expr(),
);

cb.stack_pop(a.expr());
cb.stack_pop(b.expr());
cb.stack_pop(n.expr());
cb.stack_push(r.expr());
cb.stack_pop(a.word_expr());
cb.stack_pop(b.word_expr());
cb.stack_pop(n.word_expr());
cb.stack_push(r.word_expr());

// State transition
let step_state_transition = StepStateTransition {
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ impl<F: Field> ExecutionGadget<F> for SignedDivModGadget<F> {
let remainder_is_zero =
IsZeroGadget::construct(cb, sum::expr(&remainder_abs_word.x().cells));

cb.stack_pop(dividend_abs_word.x().expr());
cb.stack_pop(divisor_abs_word.x().expr());
cb.stack_pop(dividend_abs_word.x().word_expr());
cb.stack_pop(divisor_abs_word.x().word_expr());
cb.stack_push(select::expr(
is_sdiv,
quotient_abs_word.x().expr() * (1.expr() - divisor_is_zero.expr()),
remainder_abs_word.x().expr() * (1.expr() - divisor_is_zero.expr()),
quotient_abs_word.x().word_expr() * (1.expr() - divisor_is_zero.expr()),
remainder_abs_word.x().word_expr() * (1.expr() - divisor_is_zero.expr()),
));

// Constrain `|quotient| * |divisor| + |remainder| = |dividend|`.
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/shl_shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl<F: Field> ExecutionGadget<F> for ShlShrGadget<F> {
// - for SHL, two pops are shift and quotient, and push is dividend.
// - for SHR, two pops are shift and dividend, and push is quotient.
cb.stack_pop(shift.expr());
cb.stack_pop(is_shl.expr() * quotient.expr() + is_shr.expr() * dividend.expr());
cb.stack_pop(is_shl.expr() * quotient.word_expr() + is_shr.expr() * dividend.word_expr());
cb.stack_push(
(is_shl.expr() * dividend.expr() + is_shr.expr() * quotient.expr())
(is_shl.expr() * dividend.word_expr() + is_shr.expr() * quotient.word_expr())
* (1.expr() - divisor_is_zero.expr()),
);

Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/util/common_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ impl<F: Field, const N_ADDENDS: usize, const INCREASE: bool>
let balance_sum = cb.query_word32();

let [value, value_prev] = if INCREASE {
[balance_sum.expr(), balance_addend.expr()]
[balance_sum.word_expr(), balance_addend.word_expr()]
} else {
[balance_addend.expr(), balance_sum.expr()]
[balance_addend.word_expr(), balance_sum.word_expr()]
};

let add_words = AddWordsGadget::construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<F: Field> AbsWordGadget<F> {
let add_words = AddWordsGadget::construct(cb, [x.clone(), x_abs.clone()], sum.clone());
cb.add_constraint(
"sum == 0 when x < 0",
is_neg.expr() * sum::expr(add_words.sum().expr().limbs),
is_neg.expr() * sum::expr(add_words.sum().word_expr().limbs),
);
cb.add_constraint(
"carry_hi == 1 when x < 0",
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/evm_circuit/util/math_gadget/byte_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ mod tests {
impl<F: Field, const N: u8> MathGadgetContainer<F> for ByteSizeGadgetContainer<F, N> {
fn configure_gadget_container(cb: &mut EVMConstraintBuilder<F>) -> Self {
let value_word32 = cb.query_word32();
let bytesize_gadget = ByteSizeGadget::<F>::construct(cb, value_word32.expr().limbs);
let bytesize_gadget =
ByteSizeGadget::<F>::construct(cb, value_word32.word_expr().limbs);
cb.require_equal(
"byte size gadget must equal N",
bytesize_gadget.byte_size(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl<F: Field> MulAddWordsGadget<F> {

let mut a_limbs = vec![];
let mut b_limbs = vec![];
let word4_a: Word4<Expression<F>> = a.expr().to_wordlimbs();
let word4_b: Word4<Expression<F>> = b.expr().to_wordlimbs();
let word4_a: Word4<Expression<F>> = a.word_expr().to_wordlimbs();
let word4_b: Word4<Expression<F>> = b.word_expr().to_wordlimbs();
for i in 0..4 {
a_limbs.push(word4_a.limbs[i].expr());
b_limbs.push(word4_b.limbs[i].expr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl<F: Field> MulAddWords512Gadget<F> {
// Split input words in limbs
let mut a_limbs = vec![];
let mut b_limbs = vec![];
let word4_a: Word4<Expression<F>> = words[0].expr().to_wordlimbs();
let word4_b: Word4<Expression<F>> = words[1].expr().to_wordlimbs();
let word4_a: Word4<Expression<F>> = words[0].word_expr().to_wordlimbs();
let word4_b: Word4<Expression<F>> = words[1].word_expr().to_wordlimbs();
for i in 0..4 {
a_limbs.push(word4_a.limbs[i].expr());
b_limbs.push(word4_b.limbs[i].expr());
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/util/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ impl<F: FieldExt, const N: usize> WordLimbs<Cell<F>, N> {
})
}

pub fn expr(&self) -> WordLimbs<Expression<F>, N> {
pub fn word_expr(&self) -> WordLimbs<Expression<F>, N> {
return WordLimbs::new(self.limbs.map(|cell| cell.expr()));
}

pub fn to_word(&self) -> Word<Expression<F>> {
Word(self.expr().to_wordlimbs())
Word(self.word_expr().to_wordlimbs())
}
}

Expand Down

0 comments on commit 088f583

Please sign in to comment.