@@ -23,6 +23,7 @@ import (
2323 "github.com/ethereum/go-ethereum/common"
2424 "github.com/ethereum/go-ethereum/core/types"
2525 "github.com/ethereum/go-ethereum/crypto"
26+ "github.com/ethereum/go-ethereum/libevm"
2627 "github.com/ethereum/go-ethereum/params"
2728 "github.com/holiman/uint256"
2829)
@@ -426,10 +427,7 @@ func (c *codeAndHash) Hash() common.Hash {
426427}
427428
428429// create creates a new contract using code as deployment code.
429- func (evm * EVM ) create (caller ContractRef , codeAndHash * codeAndHash , gas uint64 , value * uint256.Int , address common.Address , typ OpCode ) (deployedCode []byte , deployedAddress common.Address , gasRemaining uint64 , retErr error ) {
430- defer func () {
431- deployedCode , deployedAddress , gasRemaining , retErr = evm .canCreateContract (caller , deployedCode , deployedAddress , gasRemaining , retErr )
432- }()
430+ func (evm * EVM ) create (caller ContractRef , codeAndHash * codeAndHash , gas uint64 , value * uint256.Int , address common.Address , typ OpCode ) ([]byte , common.Address , uint64 , error ) {
433431 // Depth check execution. Fail if we're trying to execute above the
434432 // limit.
435433 if evm .depth > int (params .CallCreateDepth ) {
@@ -453,6 +451,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
453451 if evm .StateDB .GetNonce (address ) != 0 || (contractHash != (common.Hash {}) && contractHash != types .EmptyCodeHash ) {
454452 return nil , common.Address {}, 0 , ErrContractAddressCollision
455453 }
454+
455+ //libevm:start
456+ //
457+ // This check MUST be placed after the caller's nonce is incremented but
458+ // before all other state-modifying behaviour, even if changes may be
459+ // reverted to the snapshot.
460+ addrs := & libevm.AddressContext {Origin : evm .Origin , Caller : caller .Address (), Self : address }
461+ gas , err := evm .chainRules .Hooks ().CanCreateContract (addrs , gas , evm .StateDB )
462+ if err != nil {
463+ return nil , common.Address {}, gas , err
464+ }
465+ //libevm:end
466+
456467 // Create a new account on the state
457468 snapshot := evm .StateDB .Snapshot ()
458469 evm .StateDB .CreateAccount (address )
0 commit comments