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

Commit

Permalink
more util function
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed May 19, 2023
1 parent 75d64e7 commit 4d0a16d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
12 changes: 11 additions & 1 deletion zkevm-circuits/src/evm_circuit/util/common_gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ impl<F: Field, const IS_SUCCESS_CALL: bool> CommonCallGadget<F, IS_SUCCESS_CALL>
self.callee_address.expr()
}

pub fn callee_address_word(&self) -> Word<Expression<F>> {
self.callee_address.to_word()
}

pub fn gas_expr(&self) -> Expression<F> {
from_bytes::expr(&self.gas.limbs[..N_BYTES_GAS])
}
Expand Down Expand Up @@ -844,7 +848,13 @@ pub(crate) struct SstoreGasGadget<F, T> {
}

impl<F: Field, T: WordExpr<F>> SstoreGasGadget<F, T> {
pub(crate) fn construct(cb: &mut EVMConstraintBuilder<F>, is_warm: Cell<F>, value: T, value_prev: T, original_value: T) -> Self {
pub(crate) fn construct(
cb: &mut EVMConstraintBuilder<F>,
is_warm: Cell<F>,
value: T,
value_prev: T,
original_value: T,
) -> Self {
let value_eq_prev = IsEqualWordGadget::construct(cb, value, value_prev);
let original_eq_prev = IsEqualWordGadget::construct(cb, original_value, value_prev);
let original_is_zero = IsZeroWordGadget::construct(cb, original_value);
Expand Down
11 changes: 11 additions & 0 deletions zkevm-circuits/src/evm_circuit/util/constraint_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,17 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> {
word
}

pub(crate) fn tx_context_as_account_address(
&mut self,
id: Expression<F>,
field_tag: TxContextFieldTag,
index: Option<Expression<F>>,
) -> AccountAddress<F> {
let word = self.query_account_address();
self.tx_context_lookup(id, field_tag, index, word.to_word());
word
}

pub(crate) fn tx_context_lookup(
&mut self,
id: Expression<F>,
Expand Down
9 changes: 7 additions & 2 deletions zkevm-circuits/src/util/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,25 @@ impl<F: Field> Word<Expression<F>> {
}

// No overflow check on lo/hi limbs
pub fn add_unchecked(self, rhs: Self) -> Self {
pub fn add_unchecked(&self, rhs: Self) -> Self {
Word::new([
self.lo().clone() + rhs.lo().clone(),
self.hi().clone() + rhs.hi().clone(),
])
}

// No underflow check on lo/hi limbs
pub fn sub_unchecked(self, rhs: Self) -> Self {
pub fn sub_unchecked(&self, rhs: Self) -> Self {
Word::new([
self.lo().clone() - rhs.lo().clone(),
self.hi().clone() - rhs.hi().clone(),
])
}

// No overflow check
pub fn expr_unchecked(&self) -> Expression<F> {
self.lo().clone() * (1 << 128).expr() + self.hi().clone()
}
}

impl<F: Field> WordExpr<F> for Word<Expression<F>> {
Expand Down

0 comments on commit 4d0a16d

Please sign in to comment.