Skip to content

Commit 1bdae10

Browse files
committed
update based on fixes added to the main branch
1 parent f534a4d commit 1bdae10

File tree

4 files changed

+18
-38
lines changed

4 files changed

+18
-38
lines changed

core/state/access_witness.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func (aw *AccessWitness) TouchFullAccount(addr []byte, isWrite bool) uint64 {
104104
// call to that account.
105105
func (aw *AccessWitness) TouchAndChargeMessageCall(destination []byte) uint64 {
106106
var gas uint64
107-
gas += aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.VersionLeafKey, false)
108-
gas += aw.touchAddressAndChargeGas(addr, zeroTreeIndex, utils.CodeSizeLeafKey, false)
107+
gas += aw.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.VersionLeafKey, false)
108+
gas += aw.touchAddressAndChargeGas(destination, zeroTreeIndex, utils.CodeSizeLeafKey, false)
109109
return gas
110110
}
111111

core/state_transition.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/ethereum/go-ethereum/core/tracing"
2727
"github.com/ethereum/go-ethereum/core/types"
2828
"github.com/ethereum/go-ethereum/core/vm"
29-
"github.com/ethereum/go-ethereum/crypto"
3029
"github.com/ethereum/go-ethereum/crypto/kzg4844"
3130
"github.com/ethereum/go-ethereum/params"
3231
"github.com/holiman/uint256"
@@ -424,18 +423,12 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
424423
originAddr := msg.From
425424

426425
st.evm.Accesses.TouchTxOrigin(originAddr.Bytes())
427-
originNonce := st.evm.StateDB.GetNonce(originAddr)
428426

429427
if msg.To != nil {
430428
st.evm.Accesses.TouchTxDestination(targetAddr.Bytes(), msg.Value.Sign() != 0)
431429

432430
// ensure the code size ends up in the access witness
433431
st.evm.StateDB.GetCodeSize(*targetAddr)
434-
} else {
435-
contractAddr := crypto.CreateAddress(originAddr, originNonce)
436-
if !tryConsumeGas(&st.gasRemaining, st.evm.Accesses.TouchAndChargeContractCreateInit(contractAddr.Bytes(), msg.Value.Sign() != 0)) {
437-
return nil, fmt.Errorf("%w: Insufficient funds to cover witness access costs for transaction: have %d, want %d", ErrInsufficientBalanceWitness, st.gasRemaining, gas)
438-
}
439432
}
440433
}
441434

core/vm/gas_table.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize
403403
return 0, ErrGasUintOverflow
404404
}
405405
if evm.chainRules.IsEIP4762 {
406-
if _, isPrecompile := evm.precompile(address); !isPrecompile {
407-
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeMessageCall(address.Bytes()[:]))
408-
if overflow {
409-
return 0, ErrGasUintOverflow
410-
}
411-
}
412406
if transfersValue {
413407
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
414408
if overflow {
@@ -444,8 +438,9 @@ func gasCallCode(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memory
444438
}
445439
if evm.chainRules.IsEIP4762 {
446440
address := common.Address(stack.Back(1).Bytes20())
447-
if _, isPrecompile := evm.precompile(address); !isPrecompile {
448-
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeMessageCall(address.Bytes()))
441+
transfersValue := !stack.Back(2).IsZero()
442+
if transfersValue {
443+
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
449444
if overflow {
450445
return 0, ErrGasUintOverflow
451446
}
@@ -467,15 +462,6 @@ func gasDelegateCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
467462
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
468463
return 0, ErrGasUintOverflow
469464
}
470-
if evm.chainRules.IsEIP4762 {
471-
address := common.Address(stack.Back(1).Bytes20())
472-
if _, isPrecompile := evm.precompile(address); !isPrecompile {
473-
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeMessageCall(address.Bytes()))
474-
if overflow {
475-
return 0, ErrGasUintOverflow
476-
}
477-
}
478-
}
479465
return gas, nil
480466
}
481467

@@ -492,15 +478,6 @@ func gasStaticCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memo
492478
if gas, overflow = math.SafeAdd(gas, evm.callGasTemp); overflow {
493479
return 0, ErrGasUintOverflow
494480
}
495-
if evm.chainRules.IsEIP4762 {
496-
address := common.Address(stack.Back(1).Bytes20())
497-
if _, isPrecompile := evm.precompile(address); !isPrecompile {
498-
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeMessageCall(address.Bytes()))
499-
if overflow {
500-
return 0, ErrGasUintOverflow
501-
}
502-
}
503-
}
504481
return gas, nil
505482
}
506483

core/vm/operations_verkle.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,22 @@ func gasBalance4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
4949

5050
func gasExtCodeSize4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
5151
address := stack.peek().Bytes20()
52+
if _, isPrecompile := evm.precompile(address); isPrecompile {
53+
return 0, nil
54+
}
5255
wgas := evm.Accesses.TouchVersion(address[:], false)
5356
wgas += evm.Accesses.TouchCodeSize(address[:], false)
5457
if wgas == 0 {
5558
wgas = params.WarmStorageReadCostEIP2929
5659
}
57-
5860
return wgas, nil
5961
}
6062

6163
func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
6264
address := stack.peek().Bytes20()
65+
if _, isPrecompile := evm.precompile(address); isPrecompile {
66+
return 0, nil
67+
}
6368
codehashgas := evm.Accesses.TouchCodeHash(address[:], false)
6469
if codehashgas == 0 {
6570
codehashgas = params.WarmStorageReadCostEIP2929
@@ -73,8 +78,10 @@ func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
7378
if err != nil {
7479
return 0, err
7580
}
76-
wgas := evm.Accesses.TouchCodeSize(contract.Address().Bytes(), false)
77-
wgas += evm.Accesses.TouchCodeHash(contract.Address().Bytes(), false)
81+
if _, isPrecompile := evm.precompile(contract.Address()); isPrecompile {
82+
return gas, nil
83+
}
84+
wgas := evm.Accesses.TouchAndChargeMessageCall(contract.Address().Bytes())
7885
if wgas == 0 {
7986
wgas = params.WarmStorageReadCostEIP2929
8087
}
@@ -91,6 +98,9 @@ var (
9198

9299
func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
93100
beneficiaryAddr := common.Address(stack.peek().Bytes20())
101+
if _, isPrecompile := evm.precompile(beneficiaryAddr); isPrecompile {
102+
return 0, nil
103+
}
94104
contractAddr := contract.Address()
95105
statelessGas := evm.Accesses.TouchVersion(contractAddr[:], false)
96106
statelessGas += evm.Accesses.TouchCodeSize(contractAddr[:], false)

0 commit comments

Comments
 (0)