diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index 16140440b8..0f2404e496 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -697,6 +697,10 @@ impl CommonCallGadget self.callee_address.expr() } + pub fn callee_address_word(&self) -> Word> { + self.callee_address.to_word() + } + pub fn gas_expr(&self) -> Expression { from_bytes::expr(&self.gas.limbs[..N_BYTES_GAS]) } @@ -844,7 +848,13 @@ pub(crate) struct SstoreGasGadget { } impl> SstoreGasGadget { - pub(crate) fn construct(cb: &mut EVMConstraintBuilder, is_warm: Cell, value: T, value_prev: T, original_value: T) -> Self { + pub(crate) fn construct( + cb: &mut EVMConstraintBuilder, + is_warm: Cell, + 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); diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 152089e5c5..8b20696b5f 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -754,6 +754,17 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { word } + pub(crate) fn tx_context_as_account_address( + &mut self, + id: Expression, + field_tag: TxContextFieldTag, + index: Option>, + ) -> AccountAddress { + 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, diff --git a/zkevm-circuits/src/util/word.rs b/zkevm-circuits/src/util/word.rs index 5777f47b75..ae04e41281 100644 --- a/zkevm-circuits/src/util/word.rs +++ b/zkevm-circuits/src/util/word.rs @@ -258,7 +258,7 @@ impl Word> { } // 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(), @@ -266,12 +266,17 @@ impl Word> { } // 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 { + self.lo().clone() * (1 << 128).expr() + self.hi().clone() + } } impl WordExpr for Word> {