1
+ #[ cfg( all( feature = "singlethreaded" , feature = "multithreaded" ) ) ]
2
+ compile_error ! ( "feature_a and feature_b cannot be enabled simultaneously" ) ;
3
+
1
4
pub mod constants;
2
5
mod errors;
3
6
mod prover;
4
7
mod serialization;
5
8
mod trusted_setup;
6
9
mod verifier;
10
+ #[ macro_use]
11
+ pub ( crate ) mod macros;
7
12
8
13
pub use bls12_381:: fixed_base_msm:: UsePrecomp ;
9
14
// Exported types
@@ -54,9 +59,12 @@ pub type CellIndex = kzg_multi_open::CosetIndex;
54
59
55
60
use constants:: { BYTES_PER_BLOB , BYTES_PER_CELL , BYTES_PER_COMMITMENT } ;
56
61
use prover:: ProverContext ;
62
+ use verifier:: VerifierContext ;
63
+
64
+ #[ cfg( feature = "multithreaded" ) ]
57
65
use rayon:: ThreadPool ;
66
+ #[ cfg( feature = "multithreaded" ) ]
58
67
use std:: sync:: Arc ;
59
- use verifier:: VerifierContext ;
60
68
61
69
/// ThreadCount indicates whether we want to use a single thread or multiple threads
62
70
#[ derive( Debug , Copy , Clone ) ]
@@ -65,19 +73,23 @@ pub enum ThreadCount {
65
73
Single ,
66
74
/// Initializes the threadpool with the number of threads
67
75
/// denoted by this enum variant.
76
+ #[ cfg( feature = "multithreaded" ) ]
68
77
Multi ( usize ) ,
69
78
/// Initializes the threadpool with a sensible default number of
70
79
/// threads. This is currently set to `RAYON_NUM_THREADS`.
80
+ #[ cfg( feature = "multithreaded" ) ]
71
81
SensibleDefault ,
72
82
}
73
83
74
84
impl From < ThreadCount > for usize {
75
85
fn from ( value : ThreadCount ) -> Self {
76
86
match value {
77
87
ThreadCount :: Single => 1 ,
88
+ #[ cfg( feature = "multithreaded" ) ]
78
89
ThreadCount :: Multi ( num_threads) => num_threads,
79
90
// Setting this to `0` will tell ThreadPool to use
80
91
// `RAYON_NUM_THREADS`.
92
+ #[ cfg( feature = "multithreaded" ) ]
81
93
ThreadCount :: SensibleDefault => 0 ,
82
94
}
83
95
}
@@ -86,29 +98,37 @@ impl From<ThreadCount> for usize {
86
98
/// The context that will be used to create and verify opening proofs.
87
99
#[ derive( Debug ) ]
88
100
pub struct DASContext {
101
+ #[ cfg( feature = "multithreaded" ) ]
89
102
thread_pool : Arc < ThreadPool > ,
90
103
pub prover_ctx : ProverContext ,
91
104
pub verifier_ctx : VerifierContext ,
92
105
}
93
106
107
+ #[ cfg( feature = "multithreaded" ) ]
94
108
impl Default for DASContext {
95
109
fn default ( ) -> Self {
96
110
let trusted_setup = TrustedSetup :: default ( ) ;
97
111
const DEFAULT_NUM_THREADS : ThreadCount = ThreadCount :: Single ;
98
112
DASContext :: with_threads ( & trusted_setup, DEFAULT_NUM_THREADS , UsePrecomp :: No )
99
113
}
100
114
}
115
+ #[ cfg( not( feature = "multithreaded" ) ) ]
116
+ impl Default for DASContext {
117
+ fn default ( ) -> Self {
118
+ let trusted_setup = TrustedSetup :: default ( ) ;
119
+
120
+ DASContext :: new ( & trusted_setup, UsePrecomp :: No )
121
+ }
122
+ }
101
123
102
124
impl DASContext {
125
+ #[ cfg( feature = "multithreaded" ) ]
103
126
pub fn with_threads (
104
127
trusted_setup : & TrustedSetup ,
105
128
num_threads : ThreadCount ,
106
- // This parameter indicates whether we should allocate memory
107
- // in order to speed up proof creation. Heuristics show that
108
- // if pre-computations are desired, one should set the
109
- // width value to `8` for optimal storage and performance tradeoffs.
110
129
use_precomp : UsePrecomp ,
111
130
) -> Self {
131
+ #[ cfg( feature = "multithreaded" ) ]
112
132
let thread_pool = std:: sync:: Arc :: new (
113
133
rayon:: ThreadPoolBuilder :: new ( )
114
134
. num_threads ( num_threads. into ( ) )
@@ -117,12 +137,28 @@ impl DASContext {
117
137
) ;
118
138
119
139
DASContext {
140
+ #[ cfg( feature = "multithreaded" ) ]
120
141
thread_pool,
121
142
prover_ctx : ProverContext :: new ( trusted_setup, use_precomp) ,
122
143
verifier_ctx : VerifierContext :: new ( trusted_setup) ,
123
144
}
124
145
}
125
146
147
+ #[ cfg( not( feature = "multithreaded" ) ) ]
148
+ pub fn new (
149
+ trusted_setup : & TrustedSetup ,
150
+ // This parameter indicates whether we should allocate memory
151
+ // in order to speed up proof creation. Heuristics show that
152
+ // if pre-computations are desired, one should set the
153
+ // width value to `8` for optimal storage and performance tradeoffs.
154
+ use_precomp : UsePrecomp ,
155
+ ) -> Self {
156
+ DASContext {
157
+ prover_ctx : ProverContext :: new ( trusted_setup, use_precomp) ,
158
+ verifier_ctx : VerifierContext :: new ( trusted_setup) ,
159
+ }
160
+ }
161
+
126
162
pub fn prover_ctx ( & self ) -> & ProverContext {
127
163
& self . prover_ctx
128
164
}
0 commit comments