@@ -7,6 +7,7 @@ use crate::error::{Error, Result};
7
7
use crate :: hasher:: { Domain , HashFunction , Hasher } ;
8
8
use crate :: hvh_post;
9
9
use crate :: merkle:: MerkleTree ;
10
+ use crate :: parameter_cache:: ParameterSetIdentifier ;
10
11
use crate :: proof:: ProofScheme ;
11
12
use crate :: vdf:: Vdf ;
12
13
@@ -22,6 +23,16 @@ pub struct PublicParams<T: Domain, V: Vdf<T>> {
22
23
pub post_periods_count : usize ,
23
24
}
24
25
26
+ impl < T : Domain , V : Vdf < T > > ParameterSetIdentifier for PublicParams < T , V > {
27
+ fn parameter_set_identifier ( & self ) -> String {
28
+ format ! (
29
+ "beacon_post::PublicParams{{pub_params_hvh_post: {}, post_periods_count: {}" ,
30
+ self . pub_params_hvh_post. parameter_set_identifier( ) ,
31
+ self . post_periods_count
32
+ )
33
+ }
34
+ }
35
+
25
36
#[ derive( Clone , Debug ) ]
26
37
pub struct PublicInputs < T : Domain > {
27
38
/// The root hashes of the merkle trees of the sealed sectors.
@@ -48,7 +59,7 @@ impl<'a, H: 'a + Hasher> PrivateInputs<'a, H> {
48
59
}
49
60
}
50
61
51
- /// Bacon -PoSt
62
+ /// Beacon -PoSt
52
63
/// This is one construction of a Proof-of-Spacetime.
53
64
/// It currently only supports proving over a single sector.
54
65
#[ derive( Clone , Debug ) ]
@@ -60,33 +71,23 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> Proof<'a, H, V> {
60
71
}
61
72
}
62
73
63
- #[ derive( Clone , Debug ) ]
64
- pub struct BaconPost < H : Hasher , V : Vdf < H :: Domain > > {
74
+ #[ derive( Clone , Debug , Default ) ]
75
+ pub struct BeaconPoSt < H : Hasher , V : Vdf < H :: Domain > > {
65
76
_t : PhantomData < H > ,
66
77
_v : PhantomData < V > ,
67
- beacon : Beacon ,
68
78
}
69
79
70
80
#[ derive( Clone , Debug , Default ) ]
71
81
struct Beacon {
72
82
count : usize ,
73
83
}
74
- impl < H : Hasher , V : Vdf < H :: Domain > > Default for BaconPost < H , V > {
75
- fn default ( ) -> Self {
76
- BaconPost {
77
- _t : PhantomData ,
78
- _v : PhantomData ,
79
- beacon : Default :: default ( ) ,
80
- }
81
- }
82
- }
83
84
84
85
impl Beacon {
85
86
pub fn get < T : Domain > ( & mut self , t : usize ) -> T {
86
87
// TODO: actual beacon
87
88
88
89
if self . count < t {
89
- // sleep a bit, to simulate dely
90
+ // sleep a bit, to simulate delay
90
91
thread:: sleep ( time:: Duration :: from_millis ( 10 ) ) ;
91
92
self . count += 1 ;
92
93
}
@@ -97,16 +98,24 @@ impl Beacon {
97
98
}
98
99
}
99
100
100
- impl < ' a , H : Hasher + ' a , V : Vdf < H :: Domain > > BaconPost < H , V > {
101
- pub fn setup ( & self , sp : & SetupParams < H :: Domain , V > ) -> Result < PublicParams < H :: Domain , V > > {
101
+ impl < ' a , H : Hasher , V : Vdf < H :: Domain > > ProofScheme < ' a > for BeaconPoSt < H , V >
102
+ where
103
+ H : ' a ,
104
+ {
105
+ type PublicParams = PublicParams < H :: Domain , V > ;
106
+ type SetupParams = SetupParams < H :: Domain , V > ;
107
+ type PublicInputs = PublicInputs < H :: Domain > ;
108
+ type PrivateInputs = PrivateInputs < ' a , H > ;
109
+ type Proof = Proof < ' a , H , V > ;
110
+
111
+ fn setup ( sp : & SetupParams < H :: Domain , V > ) -> Result < PublicParams < H :: Domain , V > > {
102
112
Ok ( PublicParams {
103
113
pub_params_hvh_post : hvh_post:: HvhPost :: < H , V > :: setup ( & sp. setup_params_hvh_post ) ?,
104
114
post_periods_count : sp. post_periods_count ,
105
115
} )
106
116
}
107
117
108
- pub fn prove < ' b > (
109
- & mut self ,
118
+ fn prove < ' b > (
110
119
pub_params : & ' b PublicParams < H :: Domain , V > ,
111
120
pub_inputs : & ' b PublicInputs < H :: Domain > ,
112
121
priv_inputs : & ' b PrivateInputs < ' a , H > ,
@@ -125,10 +134,12 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
125
134
126
135
let mut proofs_hvh_post = Vec :: with_capacity ( post_periods_count) ;
127
136
137
+ let mut beacon = Beacon :: default ( ) ;
138
+
128
139
// First (t = 0)
129
140
{
130
- // Run Bacon
131
- let r = self . beacon . get :: < H :: Domain > ( 0 ) ;
141
+ // Run Beacon
142
+ let r = beacon. get :: < H :: Domain > ( 0 ) ;
132
143
133
144
// Generate challenges
134
145
let challenges = derive_challenges :: < H > ( challenge_count, 0 , & [ ] , r. as_ref ( ) ) ;
@@ -151,8 +162,8 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
151
162
152
163
// The rest (t = 1..post_periods_count)
153
164
for t in 1 ..post_periods_count {
154
- // Run Bacon
155
- let r = self . beacon . get :: < H :: Domain > ( t) ;
165
+ // Run Beacon
166
+ let r = beacon. get :: < H :: Domain > ( t) ;
156
167
let x = extract_post_input :: < H , V > ( & proofs_hvh_post[ t - 1 ] ) ;
157
168
158
169
// Generate challenges
@@ -178,8 +189,7 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
178
189
Ok ( Proof ( proofs_hvh_post) )
179
190
}
180
191
181
- pub fn verify (
182
- & mut self ,
192
+ fn verify (
183
193
pub_params : & PublicParams < H :: Domain , V > ,
184
194
pub_inputs : & PublicInputs < H :: Domain > ,
185
195
proof : & Proof < H , V > ,
@@ -189,9 +199,11 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
189
199
190
200
// HVH Post Verification
191
201
202
+ let mut beacon = Beacon :: default ( ) ;
203
+
192
204
// First (t = 0)
193
205
{
194
- let r = self . beacon . get :: < H :: Domain > ( 0 ) ;
206
+ let r = beacon. get :: < H :: Domain > ( 0 ) ;
195
207
// Generate challenges
196
208
let challenges = derive_challenges :: < H > ( challenge_count, 0 , & [ ] , r. as_ref ( ) ) ;
197
209
@@ -213,7 +225,7 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
213
225
// The rest (t = 1..post_periods_count)
214
226
for t in 1 ..post_periods_count {
215
227
// Generate challenges
216
- let r = self . beacon . get :: < H :: Domain > ( t) ;
228
+ let r = beacon. get :: < H :: Domain > ( t) ;
217
229
let x = extract_post_input :: < H , V > ( & proof. 0 [ t - 1 ] ) ;
218
230
219
231
let challenges = derive_challenges :: < H > ( challenge_count, t, x. as_ref ( ) , r. as_ref ( ) ) ;
@@ -238,7 +250,7 @@ impl<'a, H: Hasher + 'a, V: Vdf<H::Domain>> BaconPost<H, V> {
238
250
}
239
251
240
252
fn extract_post_input < H : Hasher , V : Vdf < H :: Domain > > ( proof : & hvh_post:: Proof < H , V > ) -> H :: Domain {
241
- let leafs: Vec < u8 > = proof. proofs_porep . iter ( ) . fold ( Vec :: new ( ) , |mut acc, p| {
253
+ let leafs: Vec < u8 > = proof. porep_proofs . iter ( ) . fold ( Vec :: new ( ) , |mut acc, p| {
242
254
acc. extend ( p. leafs ( ) . into_iter ( ) . fold (
243
255
Vec :: new ( ) ,
244
256
|mut inner_acc : Vec < u8 > , leaf : & H :: Domain | {
@@ -277,7 +289,7 @@ mod tests {
277
289
use crate :: vdf_sloth;
278
290
279
291
#[ test]
280
- fn test_bacon_post_basics ( ) {
292
+ fn test_beacon_post_basics ( ) {
281
293
let rng = & mut XorShiftRng :: from_seed ( [ 0x3dbe6259 , 0x8d313d76 , 0x3237db17 , 0xe5bc0654 ] ) ;
282
294
283
295
let sp = SetupParams :: < PedersenDomain , vdf_sloth:: Sloth > {
@@ -294,9 +306,7 @@ mod tests {
294
306
post_periods_count : 3 ,
295
307
} ;
296
308
297
- let mut bacon_post = BaconPost :: < PedersenHasher , vdf_sloth:: Sloth > :: default ( ) ;
298
-
299
- let pub_params = bacon_post. setup ( & sp) . unwrap ( ) ;
309
+ let pub_params = BeaconPoSt :: < PedersenHasher , vdf_sloth:: Sloth > :: setup ( & sp) . unwrap ( ) ;
300
310
301
311
let data0: Vec < u8 > = ( 0 ..1024 )
302
312
. flat_map ( |_| fr_into_bytes :: < Bls12 > ( & rng. gen ( ) ) )
@@ -314,16 +324,14 @@ mod tests {
314
324
commitments : vec ! [ tree0. root( ) , tree1. root( ) ] ,
315
325
} ;
316
326
317
- let priv_inputs = PrivateInputs {
327
+ let priv_inputs = PrivateInputs :: < PedersenHasher > {
318
328
trees : & [ & tree0, & tree1] ,
319
329
replicas : & [ & data0, & data1] ,
320
330
_h : PhantomData ,
321
331
} ;
322
332
323
- let proof = bacon_post
324
- . prove ( & pub_params, & pub_inputs, & priv_inputs)
325
- . unwrap ( ) ;
333
+ let proof = BeaconPoSt :: prove ( & pub_params, & pub_inputs, & priv_inputs) . unwrap ( ) ;
326
334
327
- assert ! ( bacon_post . verify( & pub_params, & pub_inputs, & proof) . unwrap( ) ) ;
335
+ assert ! ( BeaconPoSt :: verify( & pub_params, & pub_inputs, & proof) . unwrap( ) ) ;
328
336
}
329
337
}
0 commit comments