22// Parts of the project are originally copyright © Meta Platforms, Inc.
33// SPDX-License-Identifier: Apache-2.0
44
5- use crate :: block_info:: Round ;
5+ use crate :: { block_info:: Round , on_chain_config :: OnChainConfig } ;
66use aptos_crypto:: HashValue ;
7+ use aptos_crypto_derive:: SilentDebug ;
8+ use aptos_dkg:: { weighted_vuf, weighted_vuf:: traits:: WeightedVUF } ;
9+ use once_cell:: sync:: OnceCell ;
710use serde:: { Deserialize , Serialize } ;
811
12+ pub type WVUF = weighted_vuf:: pinkas:: PinkasWUF ;
13+ pub type WvufPP = <WVUF as WeightedVUF >:: PublicParameters ;
14+ pub type PK = <WVUF as WeightedVUF >:: PubKey ;
15+ pub type SKShare = <WVUF as WeightedVUF >:: SecretKeyShare ;
16+ pub type PKShare = <WVUF as WeightedVUF >:: PubKeyShare ;
17+ pub type ASK = <WVUF as WeightedVUF >:: AugmentedSecretKeyShare ;
18+ pub type APK = <WVUF as WeightedVUF >:: AugmentedPubKeyShare ;
19+ pub type ProofShare = <WVUF as WeightedVUF >:: ProofShare ;
20+ pub type Delta = <WVUF as WeightedVUF >:: Delta ;
21+ pub type Evaluation = <WVUF as WeightedVUF >:: Evaluation ;
22+ pub type Proof = <WVUF as WeightedVUF >:: Proof ;
23+
924#[ derive( Clone , Serialize , Deserialize , Debug , PartialEq , Eq , Hash ) ]
1025pub struct RandMetadataToSign {
1126 pub epoch : u64 ,
@@ -79,6 +94,10 @@ impl Randomness {
7994 pub fn randomness ( & self ) -> & [ u8 ] {
8095 & self . randomness
8196 }
97+
98+ pub fn randomness_cloned ( & self ) -> Vec < u8 > {
99+ self . randomness . clone ( )
100+ }
82101}
83102
84103impl Default for Randomness {
@@ -91,3 +110,50 @@ impl Default for Randomness {
91110 }
92111 }
93112}
113+
114+ #[ derive( Clone , Debug , Default , Eq , PartialEq , Serialize , Deserialize ) ]
115+ pub struct PerBlockRandomness {
116+ pub epoch : u64 ,
117+ pub round : u64 ,
118+ pub seed : Option < Vec < u8 > > ,
119+ }
120+
121+ impl OnChainConfig for PerBlockRandomness {
122+ const MODULE_IDENTIFIER : & ' static str = "randomness" ;
123+ const TYPE_IDENTIFIER : & ' static str = "PerBlockRandomness" ;
124+ }
125+
126+ #[ derive( Clone , SilentDebug ) ]
127+ pub struct RandKeys {
128+ // augmented secret / public key share of this validator, obtained from the DKG transcript of last epoch
129+ pub ask : ASK ,
130+ pub apk : APK ,
131+ // certified augmented public key share of all validators,
132+ // obtained from all validators in the new epoch,
133+ // which necessary for verifying randomness shares
134+ pub certified_apks : Vec < OnceCell < APK > > ,
135+ // public key share of all validators, obtained from the DKG transcript of last epoch
136+ pub pk_shares : Vec < PKShare > ,
137+ }
138+
139+ impl RandKeys {
140+ pub fn new ( ask : ASK , apk : APK , pk_shares : Vec < PKShare > , num_validators : usize ) -> Self {
141+ let certified_apks = vec ! [ OnceCell :: new( ) ; num_validators] ;
142+
143+ Self {
144+ ask,
145+ apk,
146+ certified_apks,
147+ pk_shares,
148+ }
149+ }
150+
151+ pub fn add_certified_apk ( & self , index : usize , apk : APK ) -> anyhow:: Result < ( ) > {
152+ assert ! ( index < self . certified_apks. len( ) ) ;
153+ if self . certified_apks [ index] . get ( ) . is_some ( ) {
154+ return Ok ( ( ) ) ;
155+ }
156+ self . certified_apks [ index] . set ( apk) . unwrap ( ) ;
157+ Ok ( ( ) )
158+ }
159+ }
0 commit comments