anvil_zksync_config/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
use crate::constants::*;
use crate::types::*;
use crate::utils::{format_eth, format_gwei};
use alloy::primitives::hex;
use alloy::signers::local::PrivateKeySigner;
use anvil_zksync_common::cache::{CacheConfig, DEFAULT_DISK_CACHE_DIR};
use anvil_zksync_common::sh_println;
use anvil_zksync_types::{
    LogLevel, ShowCalls, ShowGasDetails, ShowStorageLogs, ShowVMDetails, TransactionOrder,
};
use colored::{Colorize, CustomColor};
use serde_json::{json, to_writer, Value};
use std::collections::HashMap;
use std::fs::File;
use std::net::{IpAddr, Ipv4Addr};
use std::path::PathBuf;
use std::time::Duration;
use zksync_types::fee_model::FeeModelConfigV2;
use zksync_types::{ProtocolVersionId, U256};

pub const VERSION_MESSAGE: &str = concat!(env!("CARGO_PKG_VERSION"));

/// Protocol version that is used in anvil-zksync by default. Should match what is currently
/// deployed to mainnet.
pub const DEFAULT_PROTOCOL_VERSION: ProtocolVersionId = ProtocolVersionId::Version26;

const BANNER: &str = r#"
                      _  _         _____ _  __
  __ _  _ __  __   __(_)| |       |__  /| |/ / ___  _   _  _ __    ___
 / _` || '_ \ \ \ / /| || | _____   / / | ' / / __|| | | || '_ \  / __|
| (_| || | | | \ V / | || ||_____| / /_ | . \ \__ \| |_| || | | || (__
 \__,_||_| |_|  \_/  |_||_|       /____||_|\_\|___/ \__, ||_| |_| \___|
                                                    |___/
"#;
/// Struct to hold the details of the fork for display purposes
pub struct ForkPrintInfo {
    pub network_rpc: String,
    pub l1_block: String,
    pub l2_block: String,
    pub block_timestamp: String,
    pub fork_block_hash: String,
    pub fee_model_config_v2: FeeModelConfigV2,
}

/// Defines the configuration parameters for the [InMemoryNode].
#[derive(Debug, Clone)]
pub struct TestNodeConfig {
    /// Filename to write anvil-zksync output as json
    pub config_out: Option<String>,
    /// Port the node will listen on
    pub port: u16,
    /// Print node config on startup if true
    pub show_node_config: bool,
    /// Print transactions and calls summary if true
    pub show_tx_summary: bool,
    /// If true, logs events.
    pub show_event_logs: bool,
    /// Disables printing of `console.log` invocations to stdout if true
    pub disable_console_log: bool,
    /// Controls visibility of call logs
    pub show_calls: ShowCalls,
    /// Whether to show call output data
    pub show_outputs: bool,
    /// Level of detail for storage logs
    pub show_storage_logs: ShowStorageLogs,
    /// Level of detail for VM execution logs
    pub show_vm_details: ShowVMDetails,
    /// Level of detail for gas usage logs
    pub show_gas_details: ShowGasDetails,
    /// Numeric verbosity derived from repeated `-v` flags (e.g. -v = 1, -vv = 2, etc.).
    pub verbosity: u8,
    /// Whether to resolve hash references
    pub resolve_hashes: bool,
    /// Don’t print anything on startup if true
    pub silent: bool,
    /// Configuration for system contracts
    pub system_contracts_options: SystemContractsOptions,
    /// Protocol version to use for new blocks. Also affects revision of built-in contracts that
    /// will get deployed (if applicable)
    pub protocol_version: Option<ProtocolVersionId>,
    /// Directory to override bytecodes
    pub override_bytecodes_dir: Option<String>,
    /// Enable bytecode compression
    pub bytecode_compression: bool,
    /// Enables EVM emulation mode
    pub use_evm_emulator: bool,
    /// Enables ZKOS mode (experimental)
    pub use_zkos: bool,
    /// Optional chain ID for the node
    pub chain_id: Option<u32>,
    /// L1 gas price (optional override)
    pub l1_gas_price: Option<u64>,
    /// L2 gas price (optional override)
    pub l2_gas_price: Option<u64>,
    /// Price for pubdata on L1
    pub l1_pubdata_price: Option<u64>,
    /// L1 gas price scale factor for gas estimation
    pub price_scale_factor: Option<f64>,
    /// The factor by which to scale the gasLimit
    pub limit_scale_factor: Option<f32>,
    /// Logging verbosity level
    pub log_level: LogLevel,
    /// Path to the log file
    pub log_file_path: String,
    /// Directory to store cache files (defaults to `./cache`)
    pub cache_dir: String,
    /// Cache configuration for the test node
    pub cache_config: CacheConfig,
    /// Signer accounts that will be initialized with `genesis_balance` in the genesis block.
    pub genesis_accounts: Vec<PrivateKeySigner>,
    /// Native token balance of every genesis account in the genesis block
    pub genesis_balance: U256,
    /// The generator used to generate the dev accounts
    pub account_generator: Option<AccountGenerator>,
    /// Signer accounts that can sign messages/transactions
    pub signer_accounts: Vec<PrivateKeySigner>,
    /// The genesis to use to initialize the node
    pub genesis: Option<Genesis>,
    /// Genesis block timestamp
    pub genesis_timestamp: Option<u64>,
    /// Enable auto impersonation of accounts on startup
    pub enable_auto_impersonate: bool,
    /// Whether the node operates in offline mode
    pub offline: bool,
    /// The host the server will listen on
    pub host: Vec<IpAddr>,
    /// Whether we need to enable the health check endpoint.
    pub health_check_endpoint: bool,
    /// Block time in seconds for interval sealing.
    /// If unset, node seals a new block as soon as there is at least one transaction.
    pub block_time: Option<Duration>,
    /// Maximum number of transactions per block
    pub max_transactions: usize,
    /// Disable automatic sealing mode and use `BlockSealer::Noop` instead
    pub no_mining: bool,
    /// The cors `allow_origin` header
    pub allow_origin: String,
    /// Disable CORS if true
    pub no_cors: bool,
    /// How transactions are sorted in the mempool
    pub transaction_order: TransactionOrder,
    /// Path to load/dump the state from
    pub state: Option<PathBuf>,
    /// Path to dump the state to
    pub dump_state: Option<PathBuf>,
    /// Interval to dump the state
    pub state_interval: Option<u64>,
    /// Preserve historical states
    pub preserve_historical_states: bool,
    /// State to load
    pub load_state: Option<PathBuf>,
    /// L1 configuration, disabled if `None`
    pub l1_config: Option<L1Config>,
    /// Whether to automatically execute L1 batches
    pub auto_execute_l1: bool,
}

#[derive(Debug, Clone)]
pub enum L1Config {
    /// Spawn a separate `anvil` process and initialize it to use as L1.
    Spawn {
        /// Port the spawned L1 anvil node will listen on
        port: u16,
    },
    /// Use externally set up L1.
    External {
        /// Address of L1 node's JSON-RPC endpoint
        address: String,
    },
}

impl Default for TestNodeConfig {
    fn default() -> Self {
        // generate some random wallets
        let genesis_accounts = AccountGenerator::new(10).phrase(DEFAULT_MNEMONIC).gen();
        Self {
            // Node configuration defaults
            config_out: None,
            port: NODE_PORT,
            show_node_config: true,
            show_tx_summary: true,
            show_event_logs: false,
            disable_console_log: false,
            show_calls: Default::default(),
            show_outputs: false,
            show_storage_logs: Default::default(),
            show_vm_details: Default::default(),
            show_gas_details: Default::default(),
            resolve_hashes: false,
            verbosity: 0,
            silent: false,
            system_contracts_options: Default::default(),
            protocol_version: None,
            override_bytecodes_dir: None,
            bytecode_compression: false,
            use_evm_emulator: false,
            use_zkos: false,
            chain_id: None,

            // Gas configuration defaults
            l1_gas_price: None,
            l2_gas_price: None,
            l1_pubdata_price: None,
            price_scale_factor: None,
            limit_scale_factor: None,

            // Log configuration defaults
            log_level: Default::default(),
            log_file_path: String::from(DEFAULT_LOG_FILE_PATH),

            // Cache configuration default
            cache_dir: String::from(DEFAULT_DISK_CACHE_DIR),
            cache_config: Default::default(),

            // Account generator
            account_generator: None,
            genesis_accounts: genesis_accounts.clone(),
            signer_accounts: genesis_accounts,
            enable_auto_impersonate: false,
            // 100ETH default balance
            genesis_balance: U256::from(100u128 * 10u128.pow(18)),
            genesis_timestamp: Some(NON_FORK_FIRST_BLOCK_TIMESTAMP),
            genesis: None,

            // Offline mode disabled by default
            offline: false,
            host: vec![IpAddr::V4(Ipv4Addr::LOCALHOST)],
            health_check_endpoint: false,

            // Block sealing configuration default
            block_time: None,
            no_mining: false,

            max_transactions: 1000,
            transaction_order: TransactionOrder::Fifo,

            // Server configuration
            allow_origin: "*".to_string(),
            no_cors: false,

            // state configuration
            state: None,
            dump_state: None,
            state_interval: None,
            preserve_historical_states: false,
            load_state: None,
            l1_config: None,
            auto_execute_l1: false,
        }
    }
}

impl TestNodeConfig {
    pub fn protocol_version(&self) -> ProtocolVersionId {
        match self.system_contracts_options {
            SystemContractsOptions::BuiltIn => self
                .protocol_version
                .unwrap_or(DEFAULT_PROTOCOL_VERSION),
            SystemContractsOptions::Local =>
                self.protocol_version.expect("cannot deduce protocol version when using local contracts; please specify --protocol-version explicitly"),
            SystemContractsOptions::BuiltInWithoutSecurity => self
                .protocol_version
                .unwrap_or(DEFAULT_PROTOCOL_VERSION),
        }
    }
}

impl TestNodeConfig {
    pub fn print(&self, fork_details: Option<&ForkPrintInfo>) {
        if let Some(config_out) = self.config_out.as_deref() {
            let file = File::create(config_out)
                .expect("Unable to create anvil-zksync config description file");
            to_writer(&file, &self.as_json(fork_details)).expect("Failed writing json");
        }

        if self.silent || !self.show_node_config {
            return;
        }

        let color = CustomColor::new(13, 71, 198);

        // Banner, version and repository section.
        sh_println!(
            r#"
{} 
Version:        {}
Repository:     {}

"#,
            BANNER.custom_color(color),
            VERSION_MESSAGE.green(),
            "https://github.com/matter-labs/anvil-zksync".green()
        );

        // Rich Accounts.
        let balance = format_eth(self.genesis_balance);
        let mut rich_accounts = String::new();
        for (idx, account) in self.genesis_accounts.iter().enumerate() {
            rich_accounts.push_str(&format!("({}) {} ({})\n", idx, account.address(), balance));
        }
        sh_println!(
            r#"
Rich Accounts
========================
{}
"#,
            rich_accounts
        );

        // Private Keys.
        let mut private_keys = String::new();
        for (idx, account) in self.genesis_accounts.iter().enumerate() {
            let private_key = hex::encode(account.credential().to_bytes());
            private_keys.push_str(&format!("({}) 0x{}\n", idx, private_key));
        }
        sh_println!(
            r#"
Private Keys
========================
{}
"#,
            private_keys
        );

        // Wallet configuration.
        if let Some(ref generator) = self.account_generator {
            sh_println!(
                r#"
Wallet
========================
Mnemonic:            {}
Derivation path:     {}
"#,
                generator.get_phrase().green(),
                generator.get_derivation_path().green()
            );
        }

        // Either print Fork Details (if provided) or the Network Configuration.
        if let Some(fd) = fork_details {
            sh_println!(
                r#"
Fork Details
========================
Network RPC:               {}
Chain ID:                  {}
L1 Batch #:                {}
L2 Block #:                {}
Block Timestamp:           {}
Fork Block Hash:           {}
Compute Overhead Part:     {}
Pubdata Overhead Part:     {}
Batch Overhead L1 Gas:     {}
Max Gas Per Batch:         {}
Max Pubdata Per Batch:     {}
"#,
                fd.network_rpc.green(),
                self.get_chain_id().to_string().green(),
                fd.l1_block.green(),
                fd.l2_block.green(),
                fd.block_timestamp.to_string().green(),
                format!("{:#}", fd.fork_block_hash).green(),
                fd.fee_model_config_v2
                    .compute_overhead_part
                    .to_string()
                    .green(),
                fd.fee_model_config_v2
                    .pubdata_overhead_part
                    .to_string()
                    .green(),
                fd.fee_model_config_v2
                    .batch_overhead_l1_gas
                    .to_string()
                    .green(),
                fd.fee_model_config_v2.max_gas_per_batch.to_string().green(),
                fd.fee_model_config_v2
                    .max_pubdata_per_batch
                    .to_string()
                    .green()
            );
        } else {
            sh_println!(
                r#"
Network Configuration
========================
Chain ID: {}
"#,
                self.chain_id
                    .unwrap_or(TEST_NODE_NETWORK_ID)
                    .to_string()
                    .green()
            );
        }

        // Gas Configuration.
        sh_println!(
            r#"
Gas Configuration
========================
L1 Gas Price (gwei):               {}
L2 Gas Price (gwei):               {}
L1 Pubdata Price (gwei):           {}
Estimated Gas Price Scale Factor:  {}
Estimated Gas Limit Scale Factor:  {}
"#,
            format_gwei(self.get_l1_gas_price().into()).green(),
            format_gwei(self.get_l2_gas_price().into()).green(),
            format_gwei(self.get_l1_pubdata_price().into()).green(),
            self.get_price_scale().to_string().green(),
            self.get_gas_limit_scale().to_string().green()
        );

        // Genesis Timestamp.
        sh_println!(
            r#"
Genesis Timestamp
========================
{}
"#,
            self.get_genesis_timestamp().to_string().green()
        );

        // Node Configuration.
        sh_println!(
            r#"
Node Configuration
========================
Port:                  {}
EVM Emulator:          {}
Health Check Endpoint: {}
ZK OS:                 {}
L1:                    {}
"#,
            self.port,
            if self.use_evm_emulator {
                "Enabled".green()
            } else {
                "Disabled".red()
            },
            if self.health_check_endpoint {
                "Enabled".green()
            } else {
                "Disabled".red()
            },
            if self.use_zkos {
                "Enabled".green()
            } else {
                "Disabled".red()
            },
            if self.l1_config.is_some() {
                "Enabled".green()
            } else {
                "Disabled".red()
            }
        );

        // L1 Configuration
        match self.l1_config.as_ref() {
            Some(L1Config::Spawn { port }) => {
                sh_println!(
                    r#"
L1 Configuration (Spawned)
========================
Port: {port}
"#
                );
            }
            Some(L1Config::External { address }) => {
                sh_println!(
                    r#"
L1 Configuration (External)
========================
Address: {address}
"#
                );
            }
            None => {}
        }

        // Listening addresses.
        let mut listening = String::new();
        listening.push_str("\n========================================\n");
        for host in &self.host {
            listening.push_str(&format!(
                "  Listening on {}:{}\n",
                host.to_string().green(),
                self.port.to_string().green()
            ));
        }
        listening.push_str("========================================\n");
        sh_println!("{}", listening);
    }

    fn as_json(&self, fork: Option<&ForkPrintInfo>) -> Value {
        let mut wallet_description = HashMap::new();
        let mut available_accounts = Vec::with_capacity(self.genesis_accounts.len());
        let mut private_keys = Vec::with_capacity(self.genesis_accounts.len());

        for wallet in &self.genesis_accounts {
            available_accounts.push(format!("{:?}", wallet.address()));
            private_keys.push(format!("0x{}", hex::encode(wallet.credential().to_bytes())));
        }

        if let Some(ref gen) = self.account_generator {
            let phrase = gen.get_phrase().to_string();
            let derivation_path = gen.get_derivation_path().to_string();

            wallet_description.insert("derivation_path".to_string(), derivation_path);
            wallet_description.insert("mnemonic".to_string(), phrase);
        };

        if let Some(fork) = fork {
            json!({
              "available_accounts": available_accounts,
              "private_keys": private_keys,
              "endpoint": fork.network_rpc,
              "l1_block": fork.l1_block,
              "l2_block": fork.l2_block,
              "block_hash": fork.fork_block_hash,
              "chain_id": self.get_chain_id(),
              "wallet": wallet_description,
              "l1_gas_price": format!("{}", self.get_l1_gas_price()),
              "l2_gas_price": format!("{}", self.get_l2_gas_price()),
              "l1_pubdata_price": format!("{}", self.get_l1_pubdata_price()),
              "price_scale_factor": format!("{}", self.get_price_scale()),
              "limit_scale_factor": format!("{}", self.get_gas_limit_scale()),
              "fee_model_config_v2": fork.fee_model_config_v2,
            })
        } else {
            json!({
              "available_accounts": available_accounts,
              "private_keys": private_keys,
              "wallet": wallet_description,
              "chain_id": self.get_chain_id(),
              "l1_gas_price": format!("{}", self.get_l1_gas_price()),
              "l2_gas_price": format!("{}", self.get_l2_gas_price()),
              "l1_pubdata_price": format!("{}", self.get_l1_pubdata_price()),
              "price_scale_factor": format!("{}", self.get_price_scale()),
              "limit_scale_factor": format!("{}", self.get_gas_limit_scale()),
            })
        }
    }

    /// Sets the file path to write the anvil-zksync config info to.
    #[must_use]
    pub fn set_config_out(mut self, config_out: Option<String>) -> Self {
        self.config_out = config_out;
        self
    }

    /// Set the port for the test node
    #[must_use]
    pub fn with_port(mut self, port: Option<u16>) -> Self {
        if let Some(port) = port {
            self.port = port;
        }
        self
    }

    /// Get the port for the test node
    pub fn get_port(&self) -> u16 {
        self.port
    }

    /// Set the chain ID for the test node
    #[must_use]
    pub fn with_chain_id(mut self, chain_id: Option<u32>) -> Self {
        if let Some(chain_id) = chain_id {
            self.chain_id = Some(chain_id);
        }
        self
    }

    /// Get the chain ID for the test node
    pub fn get_chain_id(&self) -> u32 {
        self.chain_id.unwrap_or(TEST_NODE_NETWORK_ID)
    }

    /// Update the chain ID
    pub fn update_chain_id(&mut self, chain_id: Option<u32>) -> &mut Self {
        self.chain_id = chain_id;
        self
    }

    /// Set the system contracts configuration option
    #[must_use]
    pub fn with_system_contracts(mut self, option: Option<SystemContractsOptions>) -> Self {
        if let Some(option) = option {
            self.system_contracts_options = option;
        }
        self
    }

    /// Set the protocol version configuration option
    #[must_use]
    pub fn with_protocol_version(mut self, protocol_version: Option<ProtocolVersionId>) -> Self {
        self.protocol_version = protocol_version;
        self
    }

    /// Get the system contracts configuration option
    pub fn get_system_contracts(&self) -> SystemContractsOptions {
        self.system_contracts_options
    }

    /// Set the override bytecodes directory
    #[must_use]
    pub fn with_override_bytecodes_dir(mut self, dir: Option<String>) -> Self {
        if let Some(dir) = dir {
            self.override_bytecodes_dir = Some(dir);
        }
        self
    }

    /// Get the override bytecodes directory
    pub fn get_override_bytecodes_dir(&self) -> Option<&String> {
        self.override_bytecodes_dir.as_ref()
    }

    /// Set whether bytecode compression is enforced
    #[must_use]
    pub fn with_enforce_bytecode_compression(mut self, enforce: Option<bool>) -> Self {
        if let Some(enforce) = enforce {
            self.bytecode_compression = enforce;
        }
        self
    }

    /// Check if bytecode compression enforcement is enabled
    pub fn is_bytecode_compression_enforced(&self) -> bool {
        self.bytecode_compression
    }

    /// Enable or disable EVM emulation
    #[must_use]
    pub fn with_evm_emulator(mut self, enable: Option<bool>) -> Self {
        if let Some(enable) = enable {
            self.use_evm_emulator = enable;
        }
        self
    }

    /// Get the EVM emulation status
    pub fn is_evm_emulator_enabled(&self) -> bool {
        self.use_evm_emulator
    }

    /// Set the L1 gas price
    #[must_use]
    pub fn with_l1_gas_price(mut self, price: Option<u64>) -> Self {
        if let Some(price) = price {
            self.l1_gas_price = Some(price);
        }
        self
    }

    /// Get the L1 gas price
    pub fn get_l1_gas_price(&self) -> u64 {
        self.l1_gas_price.unwrap_or(DEFAULT_L1_GAS_PRICE)
    }

    /// Update the L1 gas price
    pub fn update_l1_gas_price(&mut self, price: Option<u64>) -> &mut Self {
        self.l1_gas_price = price;
        self
    }

    /// Set the L2 gas price
    #[must_use]
    pub fn with_l2_gas_price(mut self, price: Option<u64>) -> Self {
        if let Some(price) = price {
            self.l2_gas_price = Some(price);
        }
        self
    }

    /// Get the L2 gas price
    pub fn get_l2_gas_price(&self) -> u64 {
        self.l2_gas_price.unwrap_or(DEFAULT_L2_GAS_PRICE)
    }

    /// Update the L2 gas price
    pub fn update_l2_gas_price(&mut self, price: Option<u64>) -> &mut Self {
        self.l2_gas_price = price;
        self
    }

    /// Set the L1 pubdata price
    #[must_use]
    pub fn with_l1_pubdata_price(mut self, price: Option<u64>) -> Self {
        self.l1_pubdata_price = price;
        self
    }

    /// Get the L1 pubdata price
    pub fn get_l1_pubdata_price(&self) -> u64 {
        self.l1_pubdata_price.unwrap_or(DEFAULT_FAIR_PUBDATA_PRICE)
    }

    /// Update the L1 pubdata price
    pub fn update_l1_pubdata_price(&mut self, price: Option<u64>) -> &mut Self {
        self.l1_pubdata_price = price;
        self
    }

    /// Set the log level
    #[must_use]
    pub fn with_log_level(mut self, level: Option<LogLevel>) -> Self {
        if let Some(level) = level {
            self.log_level = level;
        }
        self
    }

    /// Get the log level
    pub fn get_log_level(&self) -> LogLevel {
        self.log_level
    }

    /// Gets the cache directory
    pub fn get_cache_dir(&self) -> &str {
        &self.cache_dir
    }

    /// Set the cache directory
    #[must_use]
    pub fn with_cache_dir(mut self, dir: Option<String>) -> Self {
        if let Some(dir) = dir {
            self.cache_dir = dir;
        }
        self
    }

    /// Set the cache configuration
    #[must_use]
    pub fn with_cache_config(mut self, config: Option<CacheConfig>) -> Self {
        if let Some(config) = config {
            self.cache_config = config;
        }
        self
    }

    /// Get the cache configuration
    pub fn get_cache_config(&self) -> &CacheConfig {
        &self.cache_config
    }

    /// Set the log file path
    #[must_use]
    pub fn with_log_file_path(mut self, path: Option<String>) -> Self {
        if let Some(path) = path {
            self.log_file_path = path;
        }
        self
    }

    /// Get the log file path
    pub fn get_log_file_path(&self) -> &str {
        &self.log_file_path
    }

    /// Applies the defaults for debug mode.
    #[must_use]
    pub fn with_debug_mode(mut self) -> Self {
        self.show_calls = ShowCalls::User;
        self.resolve_hashes = true;
        self.show_gas_details = ShowGasDetails::All;
        self
    }

    /// Set the visibility of call logs
    #[must_use]
    pub fn with_show_calls(mut self, show_calls: Option<ShowCalls>) -> Self {
        if let Some(show_calls) = show_calls {
            self.show_calls = show_calls;
        }
        self
    }

    /// Get the visibility of call logs
    pub fn get_show_calls(&self) -> ShowCalls {
        self.show_calls
    }

    /// Enable or disable resolving hashes
    #[must_use]
    pub fn with_resolve_hashes(mut self, resolve: Option<bool>) -> Self {
        if let Some(resolve) = resolve {
            self.resolve_hashes = resolve;
        }
        self
    }

    /// Sets the numeric verbosity derived from repeated `-v` flags
    #[must_use]
    pub fn with_verbosity_level(mut self, verbosity: u8) -> Self {
        self.verbosity = verbosity;
        self
    }

    /// Get the numeric verbosity derived from repeated `-v` flags
    pub fn get_verbosity_level(&self) -> u8 {
        self.verbosity
    }

    /// Enable or disable silent mode
    #[must_use]
    pub fn with_silent(mut self, silent: Option<bool>) -> Self {
        if let Some(silent) = silent {
            self.silent = silent;
        }
        self
    }

    /// Enable or disable printing node config on startup
    #[must_use]
    pub fn with_show_node_config(mut self, show_node_config: Option<bool>) -> Self {
        if let Some(show_node_config) = show_node_config {
            self.show_node_config = show_node_config;
        }
        self
    }

    // Enable or disable printing transactions and calls summary
    #[must_use]
    pub fn with_show_tx_summary(mut self, show_tx_summary: Option<bool>) -> Self {
        if let Some(show_tx_summary) = show_tx_summary {
            self.show_tx_summary = show_tx_summary;
        }
        self
    }
    /// Enable or disable logging events
    #[must_use]
    pub fn with_show_event_logs(mut self, show_event_logs: Option<bool>) -> Self {
        if let Some(show_event_logs) = show_event_logs {
            self.show_event_logs = show_event_logs;
        }
        self
    }

    /// Get the visibility of event logs
    pub fn get_show_event_logs(&self) -> bool {
        self.show_event_logs
    }

    // Enable or disable printing of `console.log` invocations to stdout
    #[must_use]
    pub fn with_disable_console_log(mut self, disable_console_log: Option<bool>) -> Self {
        if let Some(disable_console_log) = disable_console_log {
            self.disable_console_log = disable_console_log;
        }
        self
    }

    /// Check if resolving hashes is enabled
    pub fn is_resolve_hashes_enabled(&self) -> bool {
        self.resolve_hashes
    }

    /// Set the visibility of storage logs
    #[must_use]
    pub fn with_show_storage_logs(mut self, show_storage_logs: Option<ShowStorageLogs>) -> Self {
        if let Some(show_storage_logs) = show_storage_logs {
            self.show_storage_logs = show_storage_logs;
        }
        self
    }

    /// Get the visibility of storage logs
    pub fn get_show_storage_logs(&self) -> ShowStorageLogs {
        self.show_storage_logs
    }

    /// Set the detail level of VM execution logs
    #[must_use]
    pub fn with_vm_log_detail(mut self, detail: Option<ShowVMDetails>) -> Self {
        if let Some(detail) = detail {
            self.show_vm_details = detail;
        }
        self
    }

    /// Get the detail level of VM execution logs
    pub fn get_vm_log_detail(&self) -> ShowVMDetails {
        self.show_vm_details
    }

    /// Set the visibility of gas usage logs
    #[must_use]
    pub fn with_show_gas_details(mut self, show_gas_details: Option<ShowGasDetails>) -> Self {
        if let Some(show_gas_details) = show_gas_details {
            self.show_gas_details = show_gas_details;
        }
        self
    }

    /// Get the visibility of gas usage logs
    pub fn get_show_gas_details(&self) -> ShowGasDetails {
        self.show_gas_details
    }

    /// Set show outputs
    #[must_use]
    pub fn with_show_outputs(mut self, show_outputs: Option<bool>) -> Self {
        if let Some(show_outputs) = show_outputs {
            self.show_outputs = show_outputs;
        }
        self
    }

    /// Get show outputs
    pub fn get_show_outputs(&self) -> bool {
        self.show_outputs
    }

    /// Set the gas limit scale factor
    #[must_use]
    pub fn with_gas_limit_scale(mut self, scale: Option<f32>) -> Self {
        if let Some(scale) = scale {
            self.limit_scale_factor = Some(scale);
        }
        self
    }

    /// Get the gas limit scale factor
    pub fn get_gas_limit_scale(&self) -> f32 {
        self.limit_scale_factor
            .unwrap_or(DEFAULT_ESTIMATE_GAS_SCALE_FACTOR)
    }

    /// Update the gas limit scale factor
    pub fn update_gas_limit_scale(&mut self, scale: Option<f32>) -> &mut Self {
        self.limit_scale_factor = scale;
        self
    }

    /// Set the price scale factor
    #[must_use]
    pub fn with_price_scale(mut self, scale: Option<f64>) -> Self {
        if let Some(scale) = scale {
            self.price_scale_factor = Some(scale);
        }
        self
    }

    /// Get the price scale factor
    pub fn get_price_scale(&self) -> f64 {
        self.price_scale_factor
            .unwrap_or(DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR)
    }

    /// Updates the price scale factor
    pub fn update_price_scale(&mut self, scale: Option<f64>) -> &mut Self {
        self.price_scale_factor = scale;
        self
    }

    /// Sets the balance of the genesis accounts in the genesis block
    #[must_use]
    pub fn with_genesis_balance<U: Into<U256>>(mut self, balance: U) -> Self {
        self.genesis_balance = balance.into();
        self
    }

    /// Sets the genesis accounts.
    #[must_use]
    pub fn with_genesis_accounts(mut self, accounts: Vec<PrivateKeySigner>) -> Self {
        self.genesis_accounts = accounts;
        self
    }

    /// Sets the signer accounts
    #[must_use]
    pub fn with_signer_accounts(mut self, accounts: Vec<PrivateKeySigner>) -> Self {
        self.signer_accounts = accounts;
        self
    }

    /// Sets both the genesis accounts and the signer accounts
    /// so that `genesis_accounts == accounts`
    #[must_use]
    pub fn with_account_generator(mut self, generator: AccountGenerator) -> Self {
        let accounts = generator.gen();
        self.account_generator = Some(generator);
        self.with_signer_accounts(accounts.clone())
            .with_genesis_accounts(accounts)
    }

    /// Sets the genesis timestamp
    #[must_use]
    pub fn with_genesis_timestamp(mut self, timestamp: Option<u64>) -> Self {
        self.genesis_timestamp = timestamp;
        self
    }

    /// Returns the genesis timestamp to use
    pub fn get_genesis_timestamp(&self) -> u64 {
        self.genesis_timestamp
            .unwrap_or(NON_FORK_FIRST_BLOCK_TIMESTAMP)
    }

    /// Sets the init genesis (genesis.json)
    #[must_use]
    pub fn with_genesis(mut self, genesis: Option<Genesis>) -> Self {
        self.genesis = genesis;
        self
    }

    /// Sets whether to enable autoImpersonate
    #[must_use]
    pub fn with_auto_impersonate(mut self, enable_auto_impersonate: bool) -> Self {
        self.enable_auto_impersonate = enable_auto_impersonate;
        self
    }

    /// Set the offline mode
    #[must_use]
    pub fn with_offline(mut self, offline: Option<bool>) -> Self {
        if let Some(offline) = offline {
            self.offline = offline;
        }
        self
    }

    /// Get the offline mode status
    pub fn is_offline(&self) -> bool {
        self.offline
    }

    /// Sets the host the server will listen on
    #[must_use]
    pub fn with_host(mut self, host: Vec<IpAddr>) -> Self {
        self.host = if host.is_empty() {
            vec![IpAddr::V4(Ipv4Addr::LOCALHOST)]
        } else {
            host
        };
        self
    }
    /// Set the health check endpoint mode
    #[must_use]
    pub fn with_health_check_endpoint(mut self, health_check_endpoint: Option<bool>) -> Self {
        if let Some(health_check_endpoint) = health_check_endpoint {
            self.health_check_endpoint = health_check_endpoint;
        }
        self
    }

    /// Get the health check endpoint mode status
    pub fn is_health_check_endpoint_endpoint_enabled(&self) -> bool {
        self.health_check_endpoint
    }

    /// Set the block time
    #[must_use]
    pub fn with_block_time(mut self, block_time: Option<Duration>) -> Self {
        self.block_time = block_time;
        self
    }

    /// If set to `true` auto sealing will be disabled
    #[must_use]
    pub fn with_no_mining(mut self, no_mining: bool) -> Self {
        self.no_mining = no_mining;
        self
    }

    // Set transactions order in the mempool
    #[must_use]
    pub fn with_transaction_order(mut self, transaction_order: TransactionOrder) -> Self {
        self.transaction_order = transaction_order;
        self
    }

    /// Set allow_origin CORS header
    #[must_use]
    pub fn with_allow_origin(mut self, allow_origin: String) -> Self {
        self.allow_origin = allow_origin;
        self
    }

    /// Enable or disable CORS
    #[must_use]
    pub fn with_no_cors(mut self, no_cors: bool) -> Self {
        self.no_cors = no_cors;
        self
    }

    /// Set the state
    #[must_use]
    pub fn with_state(mut self, state: Option<PathBuf>) -> Self {
        self.state = state;
        self
    }

    /// Set the state dump path
    #[must_use]
    pub fn with_dump_state(mut self, dump_state: Option<PathBuf>) -> Self {
        self.dump_state = dump_state;
        self
    }

    /// Set the state dump interval
    #[must_use]
    pub fn with_state_interval(mut self, state_interval: Option<u64>) -> Self {
        self.state_interval = state_interval;
        self
    }

    /// Set preserve historical states
    #[must_use]
    pub fn with_preserve_historical_states(mut self, preserve_historical_states: bool) -> Self {
        self.preserve_historical_states = preserve_historical_states;
        self
    }

    /// Set the state to load
    #[must_use]
    pub fn with_load_state(mut self, load_state: Option<PathBuf>) -> Self {
        self.load_state = load_state;
        self
    }

    /// Set the L1 config
    #[must_use]
    pub fn with_l1_config(mut self, l1_config: Option<L1Config>) -> Self {
        self.l1_config = l1_config;
        self
    }

    /// Set the auto L1 execution
    #[must_use]
    pub fn with_auto_execute_l1(mut self, auto_execute_l1: Option<bool>) -> Self {
        self.auto_execute_l1 = auto_execute_l1.unwrap_or(false);
        self
    }
}