11//! Generic VRF implementation that can work with different transcript types
22
3- use core:: marker:: PhantomData ;
43use secp256kfun:: { KeyPair , Scalar , prelude:: * } ;
54use sigma_fun:: {
65 CompactProof , FiatShamir , ProverTranscript , Transcript ,
@@ -15,12 +14,23 @@ use sigma_fun::{
1514#[ cfg_attr(
1615 feature = "serde" ,
1716 derive( serde:: Serialize , serde:: Deserialize ) ,
18- serde( bound( serialize = "" , deserialize = "" ) )
17+ serde( bound(
18+ deserialize = "L: ArrayLength<u8>, CompactProof<Scalar<Public, Zero>, L>: serde::Deserialize<'de>" ,
19+ serialize = "L: ArrayLength<u8>, CompactProof<Scalar<Public, Zero>, L>: serde::Serialize" ,
20+ ) )
21+ ) ]
22+ #[ cfg_attr(
23+ feature = "bincode" ,
24+ derive( bincode:: Encode , bincode:: Decode ) ,
25+ bincode(
26+ encode_bounds = "L: ArrayLength<u8>, CompactProof<Scalar<Public, Zero>, L>: bincode::Encode" ,
27+ decode_bounds = "L: ArrayLength<u8>, CompactProof<Scalar<Public, Zero>, L>: bincode::Decode<__Context>" ,
28+ borrow_decode_bounds = "L: ArrayLength<u8>, CompactProof<Scalar<Public, Zero>, L>: bincode::BorrowDecode<'__de, __Context>"
29+ )
1930) ]
2031pub struct VrfProof < L = U16 >
2132where
22- L : ArrayLength < u8 > + IsLessOrEqual < U32 > ,
23- <L as IsLessOrEqual < U32 > >:: Output : NonZero ,
33+ L : ArrayLength < u8 > ,
2434{
2535 /// The VRF output point.
2636 ///
@@ -30,65 +40,16 @@ where
3040 pub proof : CompactProof < Scalar < Public , Zero > , L > ,
3141}
3242
33- #[ cfg( feature = "bincode" ) ]
34- impl < L > bincode:: Encode for VrfProof < L >
35- where
36- L : ArrayLength < u8 > + IsLessOrEqual < U32 > ,
37- <L as IsLessOrEqual < U32 > >:: Output : NonZero ,
38- {
39- fn encode < E : bincode:: enc:: Encoder > (
40- & self ,
41- encoder : & mut E ,
42- ) -> Result < ( ) , bincode:: error:: EncodeError > {
43- self . gamma . encode ( encoder) ?;
44- self . proof . encode ( encoder) ?;
45- Ok ( ( ) )
46- }
47- }
48-
49- #[ cfg( feature = "bincode" ) ]
50- impl < L , Context > bincode:: Decode < Context > for VrfProof < L >
51- where
52- L : ArrayLength < u8 > + IsLessOrEqual < U32 > ,
53- <L as IsLessOrEqual < U32 > >:: Output : NonZero ,
54- {
55- fn decode < D : bincode:: de:: Decoder < Context = Context > > (
56- decoder : & mut D ,
57- ) -> Result < Self , bincode:: error:: DecodeError > {
58- let gamma = Point :: decode ( decoder) ?;
59- let proof = CompactProof :: < Scalar < Public , Zero > , L > :: decode ( decoder) ?;
60- Ok ( VrfProof { gamma, proof } )
61- }
62- }
63-
64- #[ cfg( feature = "bincode" ) ]
65- impl < ' a , L , Context > bincode:: BorrowDecode < ' a , Context > for VrfProof < L >
66- where
67- L : ArrayLength < u8 > + IsLessOrEqual < U32 > ,
68- <L as IsLessOrEqual < U32 > >:: Output : NonZero ,
69- {
70- fn borrow_decode < D : bincode:: de:: BorrowDecoder < ' a , Context = Context > > (
71- decoder : & mut D ,
72- ) -> Result < Self , bincode:: error:: DecodeError > {
73- <Self as bincode:: Decode < Context > >:: decode ( decoder)
74- }
75- }
76-
7743/// Verified random output that ensures gamma has been verified
7844#[ derive( Debug , Clone ) ]
7945pub struct VerifiedRandomOutput {
8046 pub gamma : Point ,
8147}
8248
8349/// Generic VRF implementation
84- pub struct Vrf < T , ChallengeLength = U16 >
85- where
86- ChallengeLength : ArrayLength < u8 > + IsLessOrEqual < U32 > ,
87- <ChallengeLength as IsLessOrEqual < U32 > >:: Output : NonZero ,
88- {
50+ pub struct Vrf < T , ChallengeLength = U16 > {
8951 dleq : crate :: VrfDleq < ChallengeLength > ,
9052 pub transcript : T ,
91- _phantom : PhantomData < ChallengeLength > ,
9253}
9354
9455impl < T : Clone , ChallengeLength > Vrf < T , ChallengeLength >
10364 Self {
10465 dleq : Eq :: new ( DLG :: default ( ) , DL :: default ( ) ) ,
10566 transcript,
106- _phantom : PhantomData ,
10767 }
10868 }
10969}
0 commit comments