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:
- Pop 4 stack arguments: value, offset, length, salt
- Validate static context: Cannot be called in static mode (EIP-214)
- Charge gas:
- Base: 32,000 gas
- Init code: 2 gas/word (EIP-3860)
- Keccak256: 6 gas/word (for init code hash)
- Memory expansion
- Read init code from memory
- Compute deterministic address:
- Check collision: Fail if account exists at computed address
- Forward gas: Up to 63/64 of remaining gas (EIP-150)
- Execute init code in new context
- Store runtime code if successful (charged 200 gas/byte)
- 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:
Contracts that change code after deployment:
Frontrunning
Deterministic addresses enable frontrunning:
Constructor Reentrancy
Same reentrancy risks as CREATE:
Implementation
References