Skip to content

Commit

Permalink
fix create init gas consumption issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Mar 25, 2024
1 parent d5952ff commit 28ec9b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if evm.chainRules.IsEIP2929 {
evm.StateDB.AddAddressToAccessList(address)
}
if evm.chainRules.IsEIP4762 {
evm.Accesses.TouchAndChargeContractCreateInit(address.Bytes(), value.Sign() == 0)
}
// Ensure there's no existing contract already at the designated address
contractHash := evm.StateDB.GetCodeHash(address)
if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) {
Expand All @@ -481,6 +478,14 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
contract.SetCodeOptionalHash(&address, codeAndHash)
contract.IsDeployment = true

// Charge the contract creation init gas in verkle mode
var err error
if evm.chainRules.IsEIP4762 {
if !contract.UseGas(evm.Accesses.TouchAndChargeContractCreateInit(address.Bytes(), value.Sign() != 0)) {
err = ErrOutOfGas

Check failure on line 485 in core/vm/evm.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
}
}

if evm.Config.Tracer != nil {
if evm.depth == 0 {
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
Expand All @@ -489,7 +494,8 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
}

ret, err := evm.interpreter.Run(contract, nil, false)
var ret []byte
ret, err = evm.interpreter.Run(contract, nil, false)

// Check whether the max code size has been exceeded, assign err if the case.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
Expand Down

0 comments on commit 28ec9b4

Please sign in to comment.