@@ -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