Skip to content

Commit 0ee5162

Browse files
authored
[r30] rpc: return empty code for store out-of-gas in CREATE calls (#15585)
Cherry-pick #15581
1 parent d3636d1 commit 0ee5162

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/vm/evm.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,22 +474,26 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gasRemainin
474474
if err == nil && evm.chainRules.IsLondon && len(ret) >= 1 && ret[0] == 0xEF {
475475
err = ErrInvalidCode
476476
}
477-
// if the contract creation ran successfully and no errors were returned
477+
// If the contract creation ran successfully and no errors were returned,
478478
// calculate the gas required to store the code. If the code could not
479-
// be stored due to not enough gas set an error and let it be handled
479+
// be stored due to not enough gas, set an error when we're in Homestead and let it be handled
480480
// by the error checking condition below.
481481
if err == nil {
482482
createDataGas := uint64(len(ret)) * params.CreateDataGas
483483
if contract.UseGas(createDataGas, tracing.GasChangeCallCodeStorage) {
484484
evm.intraBlockState.SetCode(address, ret)
485-
} else if evm.chainRules.IsHomestead {
486-
err = ErrCodeStoreOutOfGas
485+
} else {
486+
// If we run out of gas, we do not store the code: the returned code must be empty.
487+
ret = []byte{}
488+
if evm.chainRules.IsHomestead {
489+
err = ErrCodeStoreOutOfGas
490+
}
487491
}
488492
}
489493

490494
// When an error was returned by the EVM or when setting the creation code
491-
// above we revert to the snapshot and consume any gas remaining. Additionally
492-
// when we're in homestead this also counts for code storage gas errors.
495+
// above, we revert to the snapshot and consume any gas remaining. Additionally,
496+
// when we're in Homestead, this also counts for code storage gas errors.
493497
if err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas) {
494498
evm.intraBlockState.RevertToSnapshot(snapshot)
495499
if err != ErrExecutionReverted {

0 commit comments

Comments
 (0)