@@ -463,13 +463,16 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
463463
464464 ret , err := run (evm , contract , nil , false )
465465
466- // check whether the max code size has been exceeded
467- maxCodeSizeExceeded := evm .chainRules .IsEIP158 && len (ret ) > params .MaxCodeSize
466+ // Check whether the max code size has been exceeded, assign err if the case.
467+ if err == nil && evm .chainRules .IsEIP158 && len (ret ) > params .MaxCodeSize {
468+ err = ErrMaxCodeSizeExceeded
469+ }
470+
468471 // if the contract creation ran successfully and no errors were returned
469472 // calculate the gas required to store the code. If the code could not
470473 // be stored due to not enough gas set an error and let it be handled
471474 // by the error checking condition below.
472- if err == nil && ! maxCodeSizeExceeded {
475+ if err == nil {
473476 createDataGas := uint64 (len (ret )) * params .CreateDataGas
474477 if contract .UseGas (createDataGas ) {
475478 evm .StateDB .SetCode (address , ret )
@@ -481,21 +484,17 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
481484 // When an error was returned by the EVM or when setting the creation code
482485 // above we revert to the snapshot and consume any gas remaining. Additionally
483486 // when we're in homestead this also counts for code storage gas errors.
484- if maxCodeSizeExceeded || ( err != nil && (evm .chainRules .IsHomestead || err != ErrCodeStoreOutOfGas ) ) {
487+ if err != nil && (evm .chainRules .IsHomestead || err != ErrCodeStoreOutOfGas ) {
485488 evm .StateDB .RevertToSnapshot (snapshot )
486489 if err != ErrExecutionReverted {
487490 contract .UseGas (contract .Gas )
488491 }
489492 }
490- // Assign err if contract code size exceeds the max while the err is still empty.
491- if maxCodeSizeExceeded && err == nil {
492- err = ErrMaxCodeSizeExceeded
493- }
493+
494494 if evm .vmConfig .Debug && evm .depth == 0 {
495495 evm .vmConfig .Tracer .CaptureEnd (ret , gas - contract .Gas , time .Since (start ), err )
496496 }
497497 return ret , address , contract .Gas , err
498-
499498}
500499
501500// Create creates a new contract using code as deployment code.
0 commit comments