@@ -113,6 +113,9 @@ func (aw *AccessWitness) TouchAndChargeMessageCall(addr []byte, availableGas uin
113113func (aw * AccessWitness ) TouchAndChargeValueTransfer (callerAddr , targetAddr []byte , availableGas uint64 ) uint64 {
114114 chargedGas1 , _ := aw .touchAddressAndChargeGas (callerAddr , zeroTreeIndex , utils .BasicDataLeafKey , true , availableGas )
115115 chargedGas2 , _ := aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .BasicDataLeafKey , true , availableGas - chargedGas1 )
116+ if chargedGas1 + chargedGas2 == 0 {
117+ return params .WarmStorageReadCostEIP2929
118+ }
116119 return chargedGas1 + chargedGas2
117120}
118121
@@ -140,9 +143,14 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) {
140143 }
141144}
142145
143- func (aw * AccessWitness ) TouchTxExistingAndComputeGas (targetAddr []byte , sendsValue bool ) {
146+ func (aw * AccessWitness ) TouchTxTarget (targetAddr []byte , sendsValue , doesntExist bool ) {
144147 aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .BasicDataLeafKey , sendsValue , math .MaxUint64 )
145- aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .CodeHashLeafKey , false , math .MaxUint64 )
148+ // Note that we do a write-event in CodeHash without distinguishing if the tx target account
149+ // exists or not. Pre-7702, there's no situation in which an existing codeHash can be mutated, thus
150+ // doing a write-event shouldn't cause an observable difference in gas usage.
151+ // TODO(7702): re-check this in the spec and implementation to be sure is a correct solution after
152+ // EIP-7702 is implemented.
153+ aw .touchAddressAndChargeGas (targetAddr , zeroTreeIndex , utils .CodeHashLeafKey , doesntExist , math .MaxUint64 )
146154}
147155
148156func (aw * AccessWitness ) TouchSlotAndChargeGas (addr []byte , slot common.Hash , isWrite bool , availableGas uint64 , warmCostCharging bool ) uint64 {
@@ -294,9 +302,9 @@ func (aw *AccessWitness) TouchBasicData(addr []byte, isWrite bool, availableGas
294302 return wanted
295303}
296304
297- func (aw * AccessWitness ) TouchCodeHash (addr []byte , isWrite bool , availableGas uint64 ) uint64 {
305+ func (aw * AccessWitness ) TouchCodeHash (addr []byte , isWrite bool , availableGas uint64 , chargeWarmCosts bool ) uint64 {
298306 _ , wanted := aw .touchAddressAndChargeGas (addr , zeroTreeIndex , utils .CodeHashLeafKey , isWrite , availableGas )
299- if wanted == 0 {
307+ if wanted == 0 && chargeWarmCosts {
300308 if availableGas < params .WarmStorageReadCostEIP2929 {
301309 return availableGas
302310 }
0 commit comments