@@ -23,6 +23,7 @@ import (
23
23
"github.com/ethereum/go-ethereum/common"
24
24
"github.com/ethereum/go-ethereum/core/types"
25
25
"github.com/ethereum/go-ethereum/crypto"
26
+ "github.com/ethereum/go-ethereum/libevm"
26
27
"github.com/ethereum/go-ethereum/params"
27
28
"github.com/holiman/uint256"
28
29
)
@@ -426,10 +427,7 @@ func (c *codeAndHash) Hash() common.Hash {
426
427
}
427
428
428
429
// 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 ) {
433
431
// Depth check execution. Fail if we're trying to execute above the
434
432
// limit.
435
433
if evm .depth > int (params .CallCreateDepth ) {
@@ -453,6 +451,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
453
451
if evm .StateDB .GetNonce (address ) != 0 || (contractHash != (common.Hash {}) && contractHash != types .EmptyCodeHash ) {
454
452
return nil , common.Address {}, 0 , ErrContractAddressCollision
455
453
}
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
+
456
467
// Create a new account on the state
457
468
snapshot := evm .StateDB .Snapshot ()
458
469
evm .StateDB .CreateAccount (address )
0 commit comments