1use once_cell::sync::OnceCell;
2use poseidon::hash::{
3 legacy,
4 params::{CODA_SIGNATURE, MAINNET_ZKAPP_BODY, MINA_SIGNATURE_MAINNET, TESTNET_ZKAPP_BODY},
5};
6
7use crate::constants::ConstraintConstants;
8
9#[derive(Debug, Clone)]
11pub enum NetworkId {
12 TESTNET = 0x00,
14
15 MAINNET = 0x01,
17}
18
19#[derive(Debug)]
20pub struct NetworkConfig {
21 pub name: &'static str,
22 pub network_id: NetworkId,
23 pub signature_prefix: &'static poseidon::hash::LazyParam,
24 pub legacy_signature_prefix: &'static poseidon::hash::LazyParam,
25 pub account_update_hash_param: &'static poseidon::hash::LazyParam,
26 pub constraint_system_digests: &'static [[u8; 16]; 3],
27 pub default_peers: Vec<&'static str>,
28 pub circuits_config: &'static CircuitsConfig,
29 pub constraint_constants: &'static ConstraintConstants,
30}
31
32#[derive(Debug)]
33pub struct CircuitsConfig {
34 pub directory_name: &'static str,
35
36 pub step_transaction_gates: &'static str,
37 pub wrap_transaction_gates: &'static str,
38 pub step_merge_gates: &'static str,
39 pub step_blockchain_gates: &'static str,
40 pub wrap_blockchain_gates: &'static str,
41 pub step_transaction_opt_signed_opt_signed_gates: &'static str,
42 pub step_transaction_opt_signed_gates: &'static str,
43 pub step_transaction_proved_gates: &'static str,
44}
45
46static CONFIG: OnceCell<NetworkConfig> = OnceCell::new();
47
48impl NetworkConfig {
49 pub fn global() -> &'static Self {
50 CONFIG.get_or_init(|| {
51 let config = Self::default_config();
52 crate::warn!(
53 crate::log::system_time();
54 kind = "network",
55 message = "no network config initialized, using default config",
56 config = config.name,
57 );
58 config
59 })
60 }
61
62 pub fn init(network_name: &str) -> Result<(), String> {
63 let config = match network_name {
64 "devnet" => Self::devnet_config(),
65 "mainnet" => Self::mainnet_config(),
66 other => Err(format!("Unknown network {other}"))?,
67 };
68
69 CONFIG
70 .set(config)
71 .map_err(|_| "Double network configuration initialization".to_owned())?;
72
73 Ok(())
74 }
75
76 fn default_config() -> Self {
77 Self::devnet_config()
78 }
79
80 fn mainnet_config() -> Self {
81 Self {
82 name: mainnet::NAME,
83 network_id: mainnet::NETWORK_ID,
84 signature_prefix: &MINA_SIGNATURE_MAINNET,
85 legacy_signature_prefix: &legacy::params::MINA_SIGNATURE_MAINNET,
86 account_update_hash_param: &MAINNET_ZKAPP_BODY,
87 constraint_system_digests: &mainnet::CONSTRAINT_SYSTEM_DIGESTS,
88 default_peers: mainnet::default_peers(),
89 circuits_config: &mainnet::CIRCUITS_CONFIG,
90 constraint_constants: &mainnet::CONSTRAINT_CONSTANTS,
91 }
92 }
93
94 fn devnet_config() -> Self {
95 Self {
96 name: devnet::NAME,
97 network_id: devnet::NETWORK_ID,
98 signature_prefix: &CODA_SIGNATURE,
99 legacy_signature_prefix: &legacy::params::CODA_SIGNATURE,
100 account_update_hash_param: &TESTNET_ZKAPP_BODY,
101 constraint_system_digests: &devnet::CONSTRAINT_SYSTEM_DIGESTS,
102 default_peers: devnet::default_peers(),
103 circuits_config: &devnet::CIRCUITS_CONFIG,
104 constraint_constants: &devnet::CONSTRAINT_CONSTANTS,
105 }
106 }
107}
108
109pub mod devnet {
112 use super::{CircuitsConfig, NetworkId};
113 use crate::constants::{ConstraintConstants, ForkConstants};
114
115 pub const NETWORK_ID: NetworkId = NetworkId::TESTNET;
116 pub const NAME: &str = "devnet";
117 pub const SIGNATURE_PREFIX: &str = "CodaSignature";
118 pub const ACCOUNT_UPDATE_HASH_PARAM: &str = "TestnetZkappBody";
119
120 pub const CONSTRAINT_SYSTEM_DIGESTS: [[u8; 16]; 3] = [
121 [
123 0xb8, 0x87, 0x9f, 0x67, 0x7f, 0x62, 0x2a, 0x1d, 0x86, 0x64, 0x80, 0x30, 0x70, 0x1f,
124 0x43, 0xe1,
125 ],
126 [
128 0x3b, 0xf6, 0xbb, 0x8a, 0x97, 0x66, 0x5f, 0xe7, 0xa9, 0xdf, 0x6f, 0xc1, 0x46, 0xe4,
129 0xf9, 0x42,
130 ],
131 [
133 0xd0, 0x24, 0xa9, 0xac, 0x78, 0xd4, 0xc9, 0x3a, 0x88, 0x8b, 0x63, 0xfc, 0x85, 0xee,
134 0xb6, 0x6a,
135 ],
136 ];
137
138 pub const CONSTRAINT_CONSTANTS: ConstraintConstants = ConstraintConstants {
139 sub_windows_per_window: 11,
140 ledger_depth: 35,
141 work_delay: 2,
142 block_window_duration_ms: 180000,
143 transaction_capacity_log_2: 7,
144 pending_coinbase_depth: 5,
145 coinbase_amount: 720000000000,
146 supercharged_coinbase_factor: 1,
147 account_creation_fee: 1000000000,
148 fork: Some(ForkConstants {
153 state_hash: ark_ff::MontFp!(
154 "7908066420535064797069631664846455037440232590837253108938061943122344055350"
155 ),
156 blockchain_length: 296371,
157 global_slot_since_genesis: 445860,
158 }),
159 };
160
161 pub const CIRCUITS_CONFIG: CircuitsConfig = CircuitsConfig {
162 directory_name: "3.0.1devnet",
163
164 step_transaction_gates: "step-step-proving-key-transaction-snark-transaction-0-c33ec5211c07928c87e850a63c6a2079",
165 wrap_transaction_gates:
166 "wrap-wrap-proving-key-transaction-snark-b9a01295c8cc9bda6d12142a581cd305",
167 step_merge_gates:
168 "step-step-proving-key-transaction-snark-merge-1-ba1d52dfdc2dd4d2e61f6c66ff2a5b2f",
169 step_blockchain_gates:
170 "step-step-proving-key-blockchain-snark-step-0-55f640777b6486a6fd3fdbc3fcffcc60",
171 wrap_blockchain_gates:
172 "wrap-wrap-proving-key-blockchain-snark-bbecaf158ca543ec8ac9e7144400e669",
173 step_transaction_opt_signed_opt_signed_gates: "step-step-proving-key-transaction-snark-opt_signed-opt_signed-2-48925e6a97197028e1a7c1ecec09021d",
174 step_transaction_opt_signed_gates:
175 "step-step-proving-key-transaction-snark-opt_signed-3-9eefed16953d2bfa78a257adece02d47",
176 step_transaction_proved_gates:
177 "step-step-proving-key-transaction-snark-proved-4-0cafcbc6dffccddbc82f8c2519c16341",
178 };
179
180 pub fn default_peers() -> Vec<&'static str> {
181 vec![
182 "/dns4/seed-1.devnet.gcp.o1test.net/tcp/10003/p2p/12D3KooWAdgYL6hv18M3iDBdaK1dRygPivSfAfBNDzie6YqydVbs",
183 "/dns4/seed-2.devnet.gcp.o1test.net/tcp/10003/p2p/12D3KooWLjs54xHzVmMmGYb7W5RVibqbwD1co7M2ZMfPgPm7iAag",
184 "/dns4/seed-3.devnet.gcp.o1test.net/tcp/10003/p2p/12D3KooWEiGVAFC7curXWXiGZyMWnZK9h8BKr88U8D5PKV3dXciv",
185 ]
186 }
187}
188
189pub mod mainnet {
190 use super::{CircuitsConfig, NetworkId};
191 use crate::constants::{ConstraintConstants, ForkConstants};
192
193 pub const NETWORK_ID: NetworkId = NetworkId::MAINNET;
194 pub const NAME: &str = "mainnet";
195 pub const SIGNATURE_PREFIX: &str = "MinaSignatureMainnet";
196 pub const ACCOUNT_UPDATE_HASH_PARAM: &str = "MainnetZkappBody";
197
198 pub const CONSTRAINT_SYSTEM_DIGESTS: [[u8; 16]; 3] = [
199 [
201 0xb8, 0x87, 0x9f, 0x67, 0x7f, 0x62, 0x2a, 0x1d, 0x86, 0x64, 0x80, 0x30, 0x70, 0x1f,
202 0x43, 0xe1,
203 ],
204 [
206 0xd3, 0x19, 0x48, 0xe6, 0x61, 0xcc, 0x66, 0x26, 0x75, 0xb0, 0xc0, 0x79, 0x45, 0x8f,
207 0x71, 0x4a,
208 ],
209 [
211 0x14, 0xab, 0x55, 0x62, 0xed, 0x29, 0x2d, 0xe7, 0xa3, 0xde, 0xb9, 0xe1, 0x2f, 0x00,
212 0xae, 0xc0,
213 ],
214 ];
215
216 pub const CONSTRAINT_CONSTANTS: ConstraintConstants = ConstraintConstants {
217 sub_windows_per_window: 11,
218 ledger_depth: 35,
219 work_delay: 2,
220 block_window_duration_ms: 180000,
221 transaction_capacity_log_2: 7,
222 pending_coinbase_depth: 5,
223 coinbase_amount: 720000000000,
224 supercharged_coinbase_factor: 1,
225 account_creation_fee: 1000000000,
226 fork: Some(ForkConstants {
231 state_hash: ark_ff::MontFp!(
232 "24465973112608446515163575794792913472627621028836869800891179577915755065526"
233 ),
234 blockchain_length: 359604,
235 global_slot_since_genesis: 564480,
236 }),
237 };
238
239 pub const CIRCUITS_CONFIG: CircuitsConfig = CircuitsConfig {
240 directory_name: "3.0.0mainnet",
241
242 step_transaction_gates: "step-step-proving-key-transaction-snark-transaction-0-b421ac835a0e73935f3d3569ff87f484",
243 wrap_transaction_gates:
244 "wrap-wrap-proving-key-transaction-snark-93928b62a1803f78b59f698ee4d36e63",
245 step_merge_gates:
246 "step-step-proving-key-transaction-snark-merge-1-ba1d52dfdc2dd4d2e61f6c66ff2a5b2f",
247 step_blockchain_gates:
248 "step-step-proving-key-blockchain-snark-step-0-281a97b76f28a0b850065190cbb892af",
249 wrap_blockchain_gates:
250 "wrap-wrap-proving-key-blockchain-snark-26c8a899619ad2682c077b0fecef87f8",
251 step_transaction_opt_signed_opt_signed_gates: "step-step-proving-key-transaction-snark-opt_signed-opt_signed-2-a84fb2a46cf4f9b58857ea5922f23266",
252 step_transaction_opt_signed_gates:
253 "step-step-proving-key-transaction-snark-opt_signed-3-a7e0f70d44ac6f0dd0afd3478e2b38ac",
254 step_transaction_proved_gates:
255 "step-step-proving-key-transaction-snark-proved-4-7bb3855dfcf14da4b3ffa7091adc0143",
256 };
257
258 pub fn default_peers() -> Vec<&'static str> {
259 vec![
260 "/dns4/mina-mainnet-seed.staketab.com/tcp/10003/p2p/12D3KooWSDTiXcdBVpN12ZqXJ49qCFp8zB1NnovuhZu6A28GLF1J",
261 "/dns4/mina-seed.bitcat365.com/tcp/10001/p2p/12D3KooWQzozNTDKL7MqUh6Nh11GMA4pQhRCAsNTRWxCAzAi4VbE",
262 "/dns4/production-mainnet-libp2p.minaprotocol.network/tcp/10000/p2p/12D3KooWPywsM191KGGNVGiNqN35nyyJg4W2BhhYukF6hP9YBR8q",
263 "/dns4/seed-1.mainnet.gcp.o1test.net/tcp/10003/p2p/12D3KooWCa1d7G3SkRxy846qTvdAFX69NnoYZ32orWVLqJcDVGHW",
264 "/dns4/seed-2.mainnet.gcp.o1test.net/tcp/32002/p2p/12D3KooWK4NfthViCTyLgVQa1WvqDC1NccVxGruCXCZUt3GqvFvn",
265 "/dns4/seed-3.mainnet.gcp.o1test.net/tcp/32003/p2p/12D3KooWNofeYVAJXA3WGg2qCDhs3GEe71kTmKpFQXRbZmCz1Vr7",
266 "/dns4/seed-4.mainnet.gcp.o1test.net/tcp/10003/p2p/12D3KooWEdBiTUQqxp3jeuWaZkwiSNcFxC6d6Tdq7u2Lf2ZD2Q6X",
267 "/dns4/seed-5.mainnet.gcp.o1test.net/tcp/32005/p2p/12D3KooWL1DJTigSwuKQRfQE3p7puFUqfbHjXbZJ9YBWtMNpr3GU",
268 "/dns4/seed-6.mainnet.gcp.o1test.net/tcp/32006/p2p/12D3KooWHGx4u32n42ub7dJNxAcAhwiA1WDq1Zsjn3k7RsS11pE8",
269 "/dns4/seed.minaexplorer.com/tcp/8302/p2p/12D3KooWR7coZtrMHvsgsfiWq2GESYypac3i29LFGp6EpbtjxBiJ",
270 "/dns4/seed.minataur.net/tcp/8302/p2p/12D3KooWNyExDzG8T1BYXHpXQS66kaw3zi6qi5Pg9KD3GEyHW5FF",
271 "/dns4/seed.piconbello.com/tcp/10001/p2p/12D3KooWRFac2AztcTeen2DYNwnTrmVBvwNDsRiFpDVdTkwdFAHP",
272 ]
273 }
274}