Skip to main content

neo_devpack_solidity/runtime/runtime_parts/runtime_impl/
config.rs

1use super::*;
2
3impl Default for RuntimeConfig {
4    fn default() -> Self {
5        Self {
6            // S2 fix — align the default gas budget with Neo N3 mainnet.
7            // `MaxTransactionSystemFee` on mainnet is 2000 GAS = 2×10^9 gas
8            // units; the previous 10M default was ~200× too tight, so any
9            // contract that wrote a handful of storage slots (now charged at
10            // the mainnet-aligned 100_000 gas/byte rate) exhausted the budget.
11            // 1_000_000_000 sits comfortably under the mainnet cap while
12            // leaving realistic headroom for storage-heavy contracts. Tests
13            // that explicitly assert a tight gas budget construct their own
14            // `RuntimeConfig` and are unaffected.
15            gas_limit: 1_000_000_000,
16            call_stack_limit: 1024,
17            memory_limit: 1024 * 1024,       // 1MB
18            storage_limit: 10 * 1024 * 1024, // 10MB
19            network_magic: 0x4F454E,         // "NEO" magic
20            enable_debugging: false,
21            enable_tracing: false,
22            strict_mode: true,
23            // Target Neo N3 node version. v3.10.0 is the current MainNet/T5
24            // TestNet release (Gorgon-hardfork preparation; v3.10.0 itself
25            // activates NO hardfork, so opcode/syscall/gas/NEF stay
26            // consensus-compatible with v3.7.x). This field is informational
27            // metadata only — there are zero runtime consumers (no version-
28            // gated logic, no manifest emission, no syscall return reads it).
29            neo_version: "3.10.0".to_string(),
30            contract_account: "0x0000000000000000000000000000000000000000".to_string(),
31            default_block_height: 0,
32            // Task #105 — 1_704_067_200 = 2024-01-01T00:00:00Z. Using 0
33            // produced an unrealistic `block.timestamp == 0` whenever a
34            // contract ran without an explicit `override_timestamp`, which
35            // made timestamp-sensitive Solidity (deadlines, `require(now >=
36            // x)`, TWAP checks, etc.) trivially passable/rejectable against
37            // any positive constant. A pinned realistic epoch is the Neo
38            // MainNet-genesis-equivalent fallback.
39            default_timestamp: 1_704_067_200,
40        }
41    }
42}
43
44impl RuntimeConfig {
45    /// Create a new builder
46    pub fn builder() -> RuntimeConfigBuilder {
47        RuntimeConfigBuilder::default()
48    }
49
50    /// Create config for testing with debugging enabled
51    pub fn for_testing() -> Self {
52        Self {
53            enable_debugging: true,
54            enable_tracing: true,
55            strict_mode: false,
56            ..Default::default()
57        }
58    }
59}
60
61/// Builder for RuntimeConfig
62#[derive(Debug, Clone, Default)]
63pub struct RuntimeConfigBuilder {
64    config: RuntimeConfig,
65}
66
67impl RuntimeConfigBuilder {
68    pub fn gas_limit(mut self, limit: u64) -> Self {
69        self.config.gas_limit = limit;
70        self
71    }
72
73    pub fn debugging(mut self, enabled: bool) -> Self {
74        self.config.enable_debugging = enabled;
75        self
76    }
77
78    pub fn tracing(mut self, enabled: bool) -> Self {
79        self.config.enable_tracing = enabled;
80        self
81    }
82
83    pub fn build(self) -> RuntimeConfig {
84        self.config
85    }
86}