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
//! Configuration constants for nalloc.
//!
//! This module centralizes all tunable parameters and magic numbers
//! to make the allocator easily configurable.
// ============================================================================
// Arena Sizes
// ============================================================================
/// Size of the Witness Arena in bytes.
/// Used for private ZK inputs requiring secure wiping.
pub const WITNESS_ARENA_SIZE: usize = 128 * 1024 * 1024; // 128 MB
/// Size of the Polynomial Arena in bytes.
/// Used for FFT/NTT coefficient vectors - needs to be large for complex circuits.
pub const POLY_ARENA_SIZE: usize = 1024 * 1024 * 1024; // 1 GB
/// Size of the Scratch Arena in bytes.
/// Used for temporary computation buffers.
pub const SCRATCH_ARENA_SIZE: usize = 256 * 1024 * 1024; // 256 MB
// ============================================================================
// Allocation Thresholds
// ============================================================================
/// Allocations larger than this threshold go to the Polynomial Arena.
/// Smaller allocations go to the Scratch Arena via GlobalAlloc.
pub const LARGE_ALLOC_THRESHOLD: usize = 1024 * 1024; // 1 MB
// ============================================================================
// Alignment Constants
// ============================================================================
/// Cache line size for SIMD-friendly FFT/NTT operations.
/// 64 bytes is optimal for AVX-512 and most modern CPUs.
pub const CACHE_LINE_ALIGN: usize = 64;
/// Page alignment for huge vector allocations.
/// 4KB works across Linux, macOS, and Windows.
pub const PAGE_ALIGN: usize = 4096;
/// Default minimum alignment for all allocations.
pub const DEFAULT_ALIGN: usize = 8;
/// 2MB huge page size (Linux).
pub const HUGE_PAGE_2MB: usize = 2 * 1024 * 1024;
/// 1GB huge page size (Linux, requires explicit kernel config).
pub const HUGE_PAGE_1GB: usize = 1024 * 1024 * 1024;
// ============================================================================
// Security Constants
// ============================================================================
/// Pattern used for memory poisoning in debug builds.
/// 0xDE is a distinctive pattern that helps identify use-after-free.
pub const POISON_PATTERN: u8 = 0xDE;
/// Secure wipe pattern (zero is standard for cryptographic applications).
pub const SECURE_WIPE_PATTERN: u8 = 0x00;
// ============================================================================
// Timeout and Retry Constants
// ============================================================================
/// Maximum number of CAS retries before giving up (for extreme contention).
/// On CI runners with 2 CPUs and 8 concurrent threads the initialising thread
/// can be starved, so we allow many more iterations. Each outer loop now also
/// calls `thread::yield_now()` every 10 iterations so the OS can schedule the
/// thread that is actually doing the initialisation work.
pub const MAX_CAS_RETRIES: usize = 50_000;
/// Spin loop hint iterations before each state check.
pub const SPIN_ITERATIONS: usize = 32;
// ============================================================================
// Guard Page Constants
// ============================================================================
/// Size of guard pages (usually one page).
pub const GUARD_PAGE_SIZE: usize = PAGE_ALIGN;