Skip to content

Commit

Permalink
core/vm: fix contract creation witness gas charging logic (#389)
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign authored Feb 27, 2024
1 parent 5f05456 commit da8b32e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
}

if err == nil && evm.chainRules.IsPrague {
if len(ret) > 0 {
touchCodeChunksRangeOnReadAndChargeGas(address.Bytes(), 0, uint64(len(ret)), uint64(len(ret)), evm.Accesses)
}
if !contract.UseGas(evm.Accesses.TouchAndChargeContractCreateCompleted(address.Bytes()[:])) {
err = ErrOutOfGas
}
}

// When an error was returned by the EVM or when setting the creation code
// above we revert to the snapshot and consume any gas remaining. Additionally
// when we're in homestead this also counts for code storage gas errors.
Expand All @@ -529,16 +538,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
}
}

if err == nil && evm.chainRules.IsPrague {
if len(ret) > 0 {
touchCodeChunksRangeOnReadAndChargeGas(address.Bytes(), 0, uint64(len(ret)), uint64(len(ret)), evm.Accesses)
}
if !contract.UseGas(evm.Accesses.TouchAndChargeContractCreateCompleted(address.Bytes()[:])) {
evm.StateDB.RevertToSnapshot(snapshot)
err = ErrOutOfGas
}
}

if evm.Config.Tracer != nil {
if evm.depth == 0 {
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, err)
Expand Down

0 comments on commit da8b32e

Please sign in to comment.