Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0xf5 Introduced: Constantinople (EIP-1014) CREATE2 deploys a new contract with a deterministic address computed from creator, salt, and init code hash. Unlike CREATE (which uses nonce), the address is predictable before deployment, enabling counterfactual instantiation and state channels.

Specification

Stack Input:
Stack Output:
Gas Cost: 32,000 + init_code_cost + keccak256_cost + memory_expansion + deployment_cost Operation:

Behavior

CREATE2 performs deterministic contract deployment:
  1. Pop 4 stack arguments: value, offset, length, salt
  2. Validate static context: Cannot be called in static mode (EIP-214)
  3. Charge gas:
    • Base: 32,000 gas
    • Init code: 2 gas/word (EIP-3860)
    • Keccak256: 6 gas/word (for init code hash)
    • Memory expansion
  4. Read init code from memory
  5. Compute deterministic address:
  6. Check collision: Fail if account exists at computed address
  7. Forward gas: Up to 63/64 of remaining gas (EIP-150)
  8. Execute init code in new context
  9. Store runtime code if successful (charged 200 gas/byte)
  10. Push address to stack (0 if failed)
Key differences from CREATE:
  • Address depends on salt and code hash, not nonce
  • Additional 6 gas/word for keccak256 hashing
  • Address predictable before deployment
  • Enables counterfactual patterns

Examples

Basic CREATE2 Deployment

Address Prediction

Factory Pattern with CREATE2

Minimal Proxy Factory (EIP-1167)

Counterfactual Instantiation

Gas Cost

Total cost: 32,000 + init_code_cost + keccak256_cost + memory_expansion + deployment_cost

Base Cost: 32,000 gas

Fixed cost for CREATE2 operation (same as CREATE).

Init Code Cost (EIP-3860)

Shanghai+: 2 gas per word for init code:
Pre-Shanghai: No init code cost.

Keccak256 Cost

CREATE2-specific: 6 gas per word for hashing init code:
This is the primary cost difference vs CREATE.

Memory Expansion

Dynamic cost for reading init code from memory:

Deployment Cost

Runtime code storage: 200 gas per byte of deployed code:

Gas Forwarding (EIP-150)

Same as CREATE - 63/64 rule applies.

Example Calculation

Common Usage

Upgradeable Factory

Registry Pattern

Multi-signature Wallet Factory

Security

Address Collision Attacks

CREATE2 enables deliberate address collisions through init code manipulation:
Mitigation (EIP-6780): SELFDESTRUCT only deletes if created in same transaction.

Init Code Hash Importance

Address depends on init code hash - different code = different address:

Salt Reuse

Same salt with same code fails:

Metamorphic Contracts

Contracts that change code after deployment:

Frontrunning

Deterministic addresses enable frontrunning:

Constructor Reentrancy

Same reentrancy risks as CREATE:

Implementation

References