diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index f8e11ef9e86..2eb3a751dc3 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -452,14 +452,14 @@ impl TransferToGadget { /// setting it's code_hash = EMPTY_HASH. The receiver account is also created /// unconditionally if must_create is true. This gadget is used in BeginTx. #[derive(Clone, Debug)] -pub(crate) struct TransferWithGasFeeGadget { - sender_sub_fee: UpdateBalanceGadget, +pub(crate) struct TransferWithGasFeeGadget { + sender_sub_fee: Option>, sender_sub_value: UpdateBalanceGadget, receiver: TransferToGadget, value_is_zero: IsZeroWordGadget>, } -impl TransferWithGasFeeGadget { +impl TransferWithGasFeeGadget { #[allow(clippy::too_many_arguments)] pub(crate) fn construct( cb: &mut EVMConstraintBuilder, @@ -468,10 +468,14 @@ impl TransferWithGasFeeGadget { receiver_exists: Expression, must_create: Expression, value: Word32Cell, - gas_fee: Word32Cell, reversion_info: &mut ReversionInfo, + gas_fee: Option>, ) -> Self { - let sender_sub_fee = cb.decrease_balance(sender_address.to_word(), gas_fee, None); + let sender_sub_fee = if WITH_FEE { + Some(cb.decrease_balance(sender_address.to_word(), gas_fee.expect("fee exists"), None)) + } else { + None + }; let value_is_zero = cb.is_zero_word(&value); // Skip transfer if value == 0 let sender_sub_value = cb.condition(not::expr(value_is_zero.expr()), |cb| { @@ -517,6 +521,19 @@ impl TransferWithGasFeeGadget { // +1 Write Account (sender) Balance // +1 Write Account (receiver) Balance not::expr(self.value_is_zero.expr()) * 2.expr() + + + /// without gas + + // +1 Write Account (receiver) CodeHash (account creation via code_hash update) + or::expr([ + not::expr(self.value_is_zero.expr()) * not::expr(self.receiver.receiver_exists.clone()), + self.receiver.must_create.clone()] + ) * 1.expr() + +// +1 Write Account (sender) Balance +// +1 Write Account (receiver) Balance +not::expr(self.value_is_zero.expr()) * 2.expr() + } #[allow(clippy::too_many_arguments)]