diff --git a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs index f0554c5b1f6..29ebf8f95a6 100644 --- a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs @@ -170,17 +170,13 @@ impl ExecutionGadget for BeginTxGadget { AccountFieldTag::CodeHash, code_hash.to_word(), ); - cb.require_equal( - "is create: callee_not_exists", - tx.is_create.expr(), - callee_not_exists.expr(), - ); // Transfer value from caller to callee, creating account if necessary. let transfer_with_gas_fee = TransferGadget::construct( cb, tx.caller_address.to_word(), tx.callee_address.to_word(), not::expr(callee_not_exists.expr()), + tx.is_create.expr(), tx.value.clone(), &mut reversion_info, Some(tx.mul_gas_fee_by_gas.product().clone()), diff --git a/zkevm-circuits/src/evm_circuit/execution/callop.rs b/zkevm-circuits/src/evm_circuit/execution/callop.rs index 0a35387ecca..5bdc1191d29 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callop.rs @@ -242,6 +242,7 @@ impl ExecutionGadget for CallOpGadget { caller_address.to_word(), callee_address.to_word(), not::expr(call_gadget.callee_not_exists.expr()), + false.expr(), call_gadget.value.clone(), &mut callee_reversion_info, None, diff --git a/zkevm-circuits/src/evm_circuit/execution/create.rs b/zkevm-circuits/src/evm_circuit/execution/create.rs index b351f4bfee0..e3979f78a1b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/create.rs +++ b/zkevm-circuits/src/evm_circuit/execution/create.rs @@ -334,6 +334,7 @@ impl ExecutionGadget< create.caller_address(), contract_addr.to_word(), 0.expr(), + true.expr(), value.clone(), &mut callee_reversion_info, None, diff --git a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs index 5996da5758a..4ebe758a314 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs @@ -107,6 +107,7 @@ impl ExecutionGadget for EndTxGadget { cb, coinbase.to_word(), 1.expr() - coinbase_code_hash_is_zero.expr(), + false.expr(), mul_effective_tip_by_gas_used.product().clone(), None, ); diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index c1450424350..56bf063b099 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -31,7 +31,7 @@ use bus_mapping::state_db::CodeDB; use eth_types::{ evm_types::GasCost, Field, OpsIdentity, ToAddress, ToLittleEndian, ToScalar, ToWord, U256, }; -use gadgets::util::{select, sum}; +use gadgets::util::{or, select, sum}; use halo2_proofs::{ circuit::Value, plonk::{Error, Expression}, @@ -370,6 +370,7 @@ impl pub(crate) struct TransferToGadget { receiver: UpdateBalanceGadget, receiver_exists: Expression, + opcode_is_create: Expression, value_is_zero: IsZeroWordGadget>, } @@ -379,6 +380,7 @@ impl TransferToGadget { cb: &mut EVMConstraintBuilder, receiver_address: WordLoHi>, receiver_exists: Expression, + opcode_is_create: Expression, value: Word32Cell, mut reversion_info: Option<&mut ReversionInfo>, ) -> Self { @@ -388,7 +390,7 @@ impl TransferToGadget { cb.condition( and::expr([ not::expr(receiver_exists.expr()), - not::expr(value_is_zero.expr()), + or::expr([not::expr(value_is_zero.expr()), opcode_is_create.expr()]), ]), |cb| { cb.account_write( @@ -408,6 +410,7 @@ impl TransferToGadget { Self { receiver, receiver_exists, + opcode_is_create, value_is_zero, } } @@ -434,8 +437,9 @@ impl TransferToGadget { pub(crate) fn rw_delta(&self) -> Expression { // +1 Write Account (receiver) CodeHash (account creation via code_hash update) and::expr([ - not::expr(self.receiver_exists.expr()),not::expr(self.value_is_zero.expr()) - ]) + + not::expr(self.receiver_exists.expr()), + or::expr([not::expr(self.value_is_zero.expr()), self.opcode_is_create.expr()]) + ])+ // +1 Write Account (receiver) Balance not::expr(self.value_is_zero.expr()) } @@ -463,6 +467,7 @@ impl TransferGadget { sender_address: WordLoHi>, receiver_address: WordLoHi>, receiver_exists: Expression, + opcode_is_create: Expression, value: Word32Cell, reversion_info: &mut ReversionInfo, gas_fee: Option>, @@ -481,6 +486,7 @@ impl TransferGadget { cb, receiver_address, receiver_exists, + opcode_is_create, value, Some(reversion_info), ); @@ -496,20 +502,18 @@ impl TransferGadget { pub(crate) fn rw_delta(&self) -> Expression { // +1 Write Account (sender) Balance (Not Reversible tx fee) WITH_FEE.expr() + - // +1 Write Account (receiver) CodeHash (account creation via code_hash update) - self.receiver.rw_delta()+ // +1 Write Account (sender) Balance - // +1 Write Account (receiver) Balance - not::expr(self.value_is_zero.expr()) * 2.expr() + not::expr(self.value_is_zero.expr()) + + // +1 Write Account (receiver) CodeHash (account creation via code_hash update) + self.receiver.rw_delta() } pub(crate) fn reversible_w_delta(&self) -> Expression { // NOTE: Write Account (sender) Balance (Not Reversible tx fee) - // +1 Write Account (receiver) CodeHash (account creation via code_hash update) - self.receiver.rw_delta()+ // +1 Write Account (sender) Balance - // +1 Write Account (receiver) Balance - not::expr(self.value_is_zero.expr()) * 2.expr() + not::expr(self.value_is_zero.expr()) + + // +1 Write Account (receiver) CodeHash (account creation via code_hash update) + self.receiver.rw_delta() } #[allow(clippy::too_many_arguments)]