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: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)
- 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_costBase 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:Keccak256 Cost
CREATE2-specific: 6 gas per word for hashing init code: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: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
- TypeScript
References
- Yellow Paper - Section 7 (Contract Creation)
- EIP-1014 - CREATE2 opcode
- EIP-150 - Gas cost changes (63/64 rule)
- EIP-170 - Contract code size limit
- EIP-1167 - Minimal proxy contract
- EIP-3860 - Init code size limit
- EIP-6780 - SELFDESTRUCT behavior (collision mitigation)
- evm.codes - CREATE2 - Interactive reference

