Skip to content

Commit

Permalink
charge create init gas before transfer and colison check
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Sep 4, 2024
1 parent 12b4ff1 commit 632bc9d
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,15 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
return nil, common.Address{}, gas, ErrNonceUintOverflow
}
evm.StateDB.SetNonce(caller.Address(), nonce+1)

// Charge the contract creation init gas in verkle mode
if evm.chainRules.IsEIP4762 {
statelessGas := evm.Accesses.TouchAndChargeContractCreateInit(address.Bytes(), value.Sign() != 0)
if statelessGas > gas {
return nil, common.Address{}, gas, ErrOutOfGas
}
gas = gas - statelessGas
}
// We add this to the access list _before_ taking a snapshot. Even if the creation fails,
// the access-list change should not be rolled back
if evm.chainRules.IsEIP2929 {
Expand All @@ -476,12 +485,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
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
}
}

if evm.Config.Tracer != nil {
if evm.depth == 0 {
Expand All @@ -492,9 +495,8 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}

var ret []byte
if err == nil {
ret, err = evm.interpreter.Run(contract, nil, false)
}
var err error
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 632bc9d

Please sign in to comment.