fluentbase_types/genesis.rs
1use crate::{address, hex, Address, Bytes, B256, UNIVERSAL_TOKEN_MAGIC_BYTES, WASM_MAGIC_BYTES};
2
3/// Address of the delegated **EVM runtime**.
4///
5/// Calls to this address are handled by the EVM execution engine rather than by
6/// normal contract bytecode. In other words, this is a dispatcher target, not a
7/// "deployed contract" in the usual sense.
8pub const PRECOMPILE_EVM_RUNTIME: Address = address!("0x0000000000000000000000000000000000520001");
9
10/// Address of the delegated **SVM runtime** (Solana VM).
11///
12/// This is feature-gated in some parts of the codebase (see `cfg(feature = "svm")`).
13pub const PRECOMPILE_SVM_RUNTIME: Address = address!("0x0000000000000000000000000000000000520003");
14
15/// Address of the **Wrapped ETH** contract (ERC-20 compatible representation of native ETH).
16///
17/// Note: Not in use
18pub const PRECOMPILE_UNUSED_4: Address = address!("0x0000000000000000000000000000000000520004");
19
20/// Address of the **WebAuthn verifier** runtime.
21///
22/// This runtime validates WebAuthn assertions (passkeys / security keys).
23pub const PRECOMPILE_WEBAUTHN_VERIFIER: Address =
24 address!("0x0000000000000000000000000000000000520005");
25
26/// Address of the **OAuth2 verifier** runtime.
27///
28/// Used for validating OAuth2/OpenID-style proofs and authorization assertions.
29pub const PRECOMPILE_OAUTH2_VERIFIER: Address =
30 address!("0x0000000000000000000000000000000000520006");
31
32/// Address of the **Nitro verifier** runtime.
33///
34/// Intended for validating attestations produced by AWS Nitro Enclaves (or compatible TEEs).
35pub const PRECOMPILE_NITRO_VERIFIER: Address =
36 address!("0x0000000000000000000000000000000000520007");
37
38/// Address of the delegated **Universal Token runtime**.
39///
40/// This runtime implements the Universal Token Standard (ERC20 + SPL),
41/// and is executed by the system runtime instead of normal contract bytecode.
42pub const PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME: Address =
43 address!("0x0000000000000000000000000000000000520008");
44
45/// Address of the delegated **Wasm runtime**.
46///
47/// Contracts that are recognized as Wasm/rWasm are dispatched here.
48pub const PRECOMPILE_WASM_RUNTIME: Address = address!("0x0000000000000000000000000000000000520009");
49
50/// A precompile smart contract that handles runtime upgrades.
51pub const PRECOMPILE_RUNTIME_UPGRADE: Address =
52 address!("0x0000000000000000000000000000000000520010");
53
54/// A precompile smart contract that can deploy child contracts using CREATE/CREATE2.
55pub const PRECOMPILE_CREATE2_FACTORY: Address =
56 address!("0x4e59b44847b379578588920cA78FbF26c0B4956C");
57pub const PRECOMPILE_CREATE2_FACTORY_DEPLOYER: Address =
58 address!("0x3fab184622dc19b6109349b94811493bf2a45362");
59
60/// A precompile smart contract that handles the bridge.
61///
62/// This address is pre-calculated based on the bridge deployer.
63pub const PRECOMPILE_ROLLUP_BRIDGE: Address =
64 address!("0x9CAcf613fC29015893728563f423fD26dCdB8Ddc");
65pub const PRECOMPILE_ROLLUP_BRIDGE_DEPLOYER: Address =
66 address!("0x482582979C9125abAb5a06F0E196E8F4015bF77A");
67
68/// A precompile smart contract that handles fee management.
69pub const PRECOMPILE_FEE_MANAGER: Address = address!("0x0000000000000000000000000000000000520fee");
70
71/// EIP-2935 system contract / precompile address (as specified by the EIP).
72///
73/// Kept as a standalone constant so fork-activation logic can include/exclude it.
74pub const PRECOMPILE_EIP2935: Address = address!("0x0000F90827F1C53a10cb7A02335B175320002935");
75
76/// EIP-7951 system contract / precompile address (as specified by the EIP).
77pub const PRECOMPILE_EIP7951: Address = address!("0x0000000000000000000000000000000000000100");
78
79/// Constructs an EVM-style precompile address from its canonical last byte.
80///
81/// Ethereum precompiles live at addresses `0x000..0001` to `0x000..0011`.
82/// Encoding them via the last byte keeps the mapping explicit and cheap.
83const fn evm_address(value: u8) -> Address {
84 Address::with_last_byte(value)
85}
86
87/// `ecrecover` precompile (EVM address 0x01).
88pub const PRECOMPILE_SECP256K1_RECOVER: Address = evm_address(0x01);
89/// `sha256` precompile (EVM address 0x02).
90pub const PRECOMPILE_SHA256: Address = evm_address(0x02);
91/// `ripemd160` precompile (EVM address 0x03).
92pub const PRECOMPILE_RIPEMD160: Address = evm_address(0x03);
93/// Identity precompile (copies input to output) (EVM address 0x04).
94pub const PRECOMPILE_IDENTITY: Address = evm_address(0x04);
95/// Big modular exponentiation precompile (EVM address 0x05).
96pub const PRECOMPILE_BIG_MODEXP: Address = evm_address(0x05);
97/// BN254 (a.k.a. alt_bn128) addition precompile (EVM address 0x06).
98pub const PRECOMPILE_BN256_ADD: Address = evm_address(0x06);
99/// BN254 (a.k.a. alt_bn128) multiplication precompile (EVM address 0x07).
100pub const PRECOMPILE_BN256_MUL: Address = evm_address(0x07);
101/// BN254 (a.k.a. alt_bn128) pairing check precompile (EVM address 0x08).
102pub const PRECOMPILE_BN256_PAIR: Address = evm_address(0x08);
103/// BLAKE2 compression function precompile (EVM address 0x09).
104pub const PRECOMPILE_BLAKE2F: Address = evm_address(0x09);
105/// KZG point evaluation precompile (EVM address 0x0a).
106pub const PRECOMPILE_KZG_POINT_EVALUATION: Address = evm_address(0x0a);
107/// BLS12-381 G1 add precompile (EVM address 0x0b).
108pub const PRECOMPILE_BLS12_381_G1_ADD: Address = evm_address(0x0b);
109/// BLS12-381 G1 MSM (multi-scalar multiplication) precompile (EVM address 0x0c).
110pub const PRECOMPILE_BLS12_381_G1_MSM: Address = evm_address(0x0c);
111/// BLS12-381 G2 add precompile (EVM address 0x0d).
112pub const PRECOMPILE_BLS12_381_G2_ADD: Address = evm_address(0x0d);
113/// BLS12-381 G2 MSM (multi-scalar multiplication) precompile (EVM address 0x0e).
114pub const PRECOMPILE_BLS12_381_G2_MSM: Address = evm_address(0x0e);
115/// BLS12-381 pairing check precompile (EVM address 0x0f).
116pub const PRECOMPILE_BLS12_381_PAIRING: Address = evm_address(0x0f);
117/// BLS12-381 map-to-G1 precompile (EVM address 0x10).
118pub const PRECOMPILE_BLS12_381_MAP_G1: Address = evm_address(0x10);
119/// BLS12-381 map-to-G2 precompile (EVM address 0x11).
120pub const PRECOMPILE_BLS12_381_MAP_G2: Address = evm_address(0x11);
121
122/// The full set of addresses treated as "system precompiles" by the executor.
123///
124/// This list is used for routing/dispatch decisions and must remain stable
125/// across nodes for consensus.
126///
127/// NOTE: DON'T EDIT, THIS LIST WILL BE REMOVED AT NEXT TESTNET SNAPSHOT!
128pub const TESTNET_LEGACY_PRECOMPILE_ADDRESSES: &[Address] = &[
129 PRECOMPILE_BIG_MODEXP, // FORK ALERT: DON'T TOUCH!
130 PRECOMPILE_BLAKE2F, // FORK ALERT: DON'T TOUCH!
131 PRECOMPILE_BLS12_381_G1_ADD, // FORK ALERT: DON'T TOUCH!
132 PRECOMPILE_BLS12_381_G1_MSM, // FORK ALERT: DON'T TOUCH!
133 PRECOMPILE_BLS12_381_G2_ADD, // FORK ALERT: DON'T TOUCH!
134 PRECOMPILE_BLS12_381_G2_MSM, // FORK ALERT: DON'T TOUCH!
135 PRECOMPILE_BLS12_381_MAP_G1, // FORK ALERT: DON'T TOUCH!
136 PRECOMPILE_BLS12_381_MAP_G2, // FORK ALERT: DON'T TOUCH!
137 PRECOMPILE_BLS12_381_PAIRING, // FORK ALERT: DON'T TOUCH!
138 PRECOMPILE_BN256_ADD, // FORK ALERT: DON'T TOUCH!
139 PRECOMPILE_BN256_MUL, // FORK ALERT: DON'T TOUCH!
140 PRECOMPILE_BN256_PAIR, // FORK ALERT: DON'T TOUCH!
141 PRECOMPILE_EIP2935, // FORK ALERT: DON'T TOUCH!
142 PRECOMPILE_EIP7951, // FORK ALERT: DON'T TOUCH!
143 PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME, // FORK ALERT: DON'T TOUCH!
144 PRECOMPILE_EVM_RUNTIME, // FORK ALERT: DON'T TOUCH!
145 PRECOMPILE_IDENTITY, // FORK ALERT: DON'T TOUCH!
146 PRECOMPILE_KZG_POINT_EVALUATION, // FORK ALERT: DON'T TOUCH!
147 PRECOMPILE_NITRO_VERIFIER, // FORK ALERT: DON'T TOUCH!
148 PRECOMPILE_OAUTH2_VERIFIER, // FORK ALERT: DON'T TOUCH!
149 PRECOMPILE_RIPEMD160, // FORK ALERT: DON'T TOUCH!
150 PRECOMPILE_SECP256K1_RECOVER, // FORK ALERT: DON'T TOUCH!
151 PRECOMPILE_SHA256, // FORK ALERT: DON'T TOUCH!
152 PRECOMPILE_SVM_RUNTIME, // FORK ALERT: DON'T TOUCH!
153 PRECOMPILE_WASM_RUNTIME, // FORK ALERT: DON'T TOUCH!
154 PRECOMPILE_RUNTIME_UPGRADE, // FORK ALERT: DON'T TOUCH!
155 PRECOMPILE_CREATE2_FACTORY, // FORK ALERT: DON'T TOUCH!
156 PRECOMPILE_FEE_MANAGER, // FORK ALERT: DON'T TOUCH!
157 PRECOMPILE_WEBAUTHN_VERIFIER, // FORK ALERT: DON'T TOUCH!
158 PRECOMPILE_UNUSED_4, // FORK ALERT: DON'T TOUCH!
159];
160
161/// Addresses whose execution is delegated to the **system runtime** implementation.
162///
163/// This is a narrower set than `PRECOMPILE_ADDRESSES`: some system contracts may
164/// exist, but not be executed by the system runtime (or may be feature/fork gated).
165pub const EXECUTE_USING_SYSTEM_RUNTIME_ADDRESSES: &[Address] = &[
166 PRECOMPILE_BIG_MODEXP,
167 PRECOMPILE_BLAKE2F,
168 PRECOMPILE_BLS12_381_G1_ADD,
169 PRECOMPILE_BLS12_381_G1_MSM,
170 PRECOMPILE_BLS12_381_G2_ADD,
171 PRECOMPILE_BLS12_381_G2_MSM,
172 PRECOMPILE_BLS12_381_MAP_G1,
173 PRECOMPILE_BLS12_381_MAP_G2,
174 PRECOMPILE_BLS12_381_PAIRING,
175 PRECOMPILE_BN256_ADD,
176 PRECOMPILE_BN256_MUL,
177 PRECOMPILE_BN256_PAIR,
178 // PRECOMPILE_EIP2935,
179 PRECOMPILE_EIP7951,
180 PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME,
181 PRECOMPILE_EVM_RUNTIME,
182 PRECOMPILE_IDENTITY,
183 PRECOMPILE_KZG_POINT_EVALUATION,
184 PRECOMPILE_NITRO_VERIFIER,
185 PRECOMPILE_OAUTH2_VERIFIER,
186 PRECOMPILE_RIPEMD160,
187 PRECOMPILE_SECP256K1_RECOVER,
188 PRECOMPILE_SHA256,
189 // PRECOMPILE_SVM_RUNTIME,
190 PRECOMPILE_WASM_RUNTIME,
191 PRECOMPILE_WEBAUTHN_VERIFIER,
192];
193
194/// Returns `true` if `address` should be executed by the system runtime.
195///
196/// This is a separate list from `PRECOMPILE_ADDRESSES` because:
197/// - some addresses may exist but be disabled until a fork activates them
198/// - some addresses may be routed via different execution strategies
199pub fn is_execute_using_system_runtime(address: &Address) -> bool {
200 EXECUTE_USING_SYSTEM_RUNTIME_ADDRESSES.contains(address)
201}
202
203/// Addresses whose execution should be charged by the runtime.
204///
205/// These contracts should be compiled with `consume_fuel=true` and
206/// `builtins_consume_fuel=true`.
207pub const ENGINE_METERED_PRECOMPILES: &[Address] = &[
208 PRECOMPILE_NITRO_VERIFIER,
209 PRECOMPILE_OAUTH2_VERIFIER,
210 PRECOMPILE_WASM_RUNTIME,
211 PRECOMPILE_WEBAUTHN_VERIFIER,
212 PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME,
213];
214
215/// Returns `true` if the contract at `address` should be charged fuel by the runtime.
216pub fn is_engine_metered_precompile(address: &Address) -> bool {
217 ENGINE_METERED_PRECOMPILES.contains(address)
218}
219
220/// Resolves and returns the account owner `Address` based on the provided input byte slice.
221///
222/// # Parameters
223/// - `input`: A byte slice (`&[u8]`) used to determine the runtime owner. The function
224/// inspects the beginning of the `input` slice to match specific magic byte sequences
225/// associated with predefined runtime owners.
226///
227/// # Notes
228/// - This function provides a mechanism to associate specific runtime types with accounts
229/// based on their initialization input data.
230pub fn resolve_precompiled_runtime_from_input(input: &[u8]) -> Address {
231 if input.len() > WASM_MAGIC_BYTES.len() && input[..WASM_MAGIC_BYTES.len()] == WASM_MAGIC_BYTES {
232 return PRECOMPILE_WASM_RUNTIME;
233 }
234 #[cfg(feature = "svm")]
235 if input.len() > crate::SVM_ELF_MAGIC_BYTES.len()
236 && input[..crate::SVM_ELF_MAGIC_BYTES.len()] == crate::SVM_ELF_MAGIC_BYTES
237 {
238 return PRECOMPILE_SVM_RUNTIME;
239 }
240 if input.len() > UNIVERSAL_TOKEN_MAGIC_BYTES.len()
241 && input[..UNIVERSAL_TOKEN_MAGIC_BYTES.len()] == UNIVERSAL_TOKEN_MAGIC_BYTES
242 {
243 PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME
244 } else {
245 PRECOMPILE_EVM_RUNTIME
246 }
247}
248
249/// Authority address that is allowed to update the code of arbitrary accounts.
250///
251/// This is the "admin" for genesis/state upgrade operations and should be
252/// treated as highly privileged.
253///
254/// P.S: This address is default for genesis-init, but once a chain is live, it should be
255/// reannounced or changed to smart contract (multisig). The address can be changed by upgrading
256/// the runtime.
257pub const DEFAULT_UPDATE_GENESIS_AUTH: Address =
258 address!("0xa7bf6a9168fe8a111307b7c94b8883fe02b30934");
259
260/// Default fee manager, should be changed after a chain is live
261pub const DEFAULT_FEE_MANAGER_AUTH: Address =
262 address!("0xa7bf6a9168fe8a111307b7c94b8883fe02b30934");
263
264/// Transaction calldata prefix for **genesis update**.
265/// Versioning allows introducing new update semantics without ambiguity.
266///
267/// Hash of: `upgradeTo(address,uint256,string,bytes)`
268pub const UPDATE_GENESIS_PREFIX: [u8; 4] = hex!("0x288fb3b8");
269
270#[derive(Debug, Clone)]
271pub struct GenesisContract {
272 /// Human-readable name of the genesis contract (used for manifests/debugging).
273 pub name: &'static str,
274
275 /// rWasm bytecode as stored in state at genesis.
276 pub rwasm_bytecode: Bytes,
277
278 /// Hash of `rwasm_bytecode`.
279 ///
280 /// Stored explicitly for determinism and to avoid recomputation.
281 pub rwasm_bytecode_hash: B256,
282
283 /// Address at which the contract is deployed at genesis.
284 pub address: Address,
285}
286
287/// Returns `true` if `address` corresponds to a delegated runtime dispatcher.
288///
289/// Delegated runtimes are handled specially by the executor (they are not normal
290/// bytecode-bearing contracts).
291pub fn is_delegated_runtime_address(address: &Address) -> bool {
292 address == &PRECOMPILE_EVM_RUNTIME
293 || address == &PRECOMPILE_SVM_RUNTIME
294 || address == &PRECOMPILE_UNIVERSAL_TOKEN_RUNTIME
295 || address == &PRECOMPILE_WASM_RUNTIME
296}