11//! Defines a `TranscriptProtocol` trait for using a Merlin transcript.
22
3- use byteorder:: { ByteOrder , LittleEndian } ;
43use curve25519_dalek:: ristretto:: CompressedRistretto ;
54use curve25519_dalek:: scalar:: Scalar ;
65use merlin:: Transcript ;
76
87use errors:: ProofError ;
98
109pub trait TranscriptProtocol {
11- /// Commit a domain separator for an `n`-bit, `m`-party range proof.
10+ /// Append a domain separator for an `n`-bit, `m`-party range proof.
1211 fn rangeproof_domain_sep ( & mut self , n : u64 , m : u64 ) ;
1312
14- /// Commit a domain separator for a length-`n` inner product proof.
13+ /// Append a domain separator for a length-`n` inner product proof.
1514 fn innerproduct_domain_sep ( & mut self , n : u64 ) ;
1615
17- /// Commit a domain separator for a constraint system.
16+ /// Append a domain separator for a constraint system.
1817 fn r1cs_domain_sep ( & mut self ) ;
1918
20- /// Commit a 64-bit integer .
21- fn commit_u64 ( & mut self , label : & ' static [ u8 ] , n : u64 ) ;
19+ /// Append a `scalar` with the given `label` .
20+ fn append_scalar ( & mut self , label : & ' static [ u8 ] , scalar : & Scalar ) ;
2221
23- /// Commit a `scalar ` with the given `label`.
24- fn commit_scalar ( & mut self , label : & ' static [ u8 ] , scalar : & Scalar ) ;
22+ /// Append a `point ` with the given `label`.
23+ fn append_point ( & mut self , label : & ' static [ u8 ] , point : & CompressedRistretto ) ;
2524
26- /// Commit a `point` with the given `label`.
27- fn commit_point ( & mut self , label : & ' static [ u8 ] , point : & CompressedRistretto ) ;
28-
29- /// Check that a point is not the identity, then commit it to the
25+ /// Check that a point is not the identity, then append it to the
3026 /// transcript. Otherwise, return an error.
31- fn validate_and_commit_point (
27+ fn validate_and_append_point (
3228 & mut self ,
3329 label : & ' static [ u8 ] ,
3430 point : & CompressedRistretto ,
@@ -38,41 +34,31 @@ pub trait TranscriptProtocol {
3834 fn challenge_scalar ( & mut self , label : & ' static [ u8 ] ) -> Scalar ;
3935}
4036
41- fn le_u64 ( value : u64 ) -> [ u8 ; 8 ] {
42- let mut value_bytes = [ 0u8 ; 8 ] ;
43- LittleEndian :: write_u64 ( & mut value_bytes, value) ;
44- value_bytes
45- }
46-
4737impl TranscriptProtocol for Transcript {
4838 fn rangeproof_domain_sep ( & mut self , n : u64 , m : u64 ) {
49- self . commit_bytes ( b"dom-sep" , b"rangeproof v1" ) ;
50- self . commit_bytes ( b"n" , & le_u64 ( n ) ) ;
51- self . commit_bytes ( b"m" , & le_u64 ( m ) ) ;
39+ self . append_message ( b"dom-sep" , b"rangeproof v1" ) ;
40+ self . append_u64 ( b"n" , n ) ;
41+ self . append_u64 ( b"m" , m ) ;
5242 }
5343
5444 fn innerproduct_domain_sep ( & mut self , n : u64 ) {
55- self . commit_bytes ( b"dom-sep" , b"ipp v1" ) ;
56- self . commit_bytes ( b"n" , & le_u64 ( n ) ) ;
45+ self . append_message ( b"dom-sep" , b"ipp v1" ) ;
46+ self . append_u64 ( b"n" , n ) ;
5747 }
5848
5949 fn r1cs_domain_sep ( & mut self ) {
60- self . commit_bytes ( b"dom-sep" , b"r1cs v1" ) ;
61- }
62-
63- fn commit_u64 ( & mut self , label : & ' static [ u8 ] , n : u64 ) {
64- self . commit_bytes ( label, & le_u64 ( n) ) ;
50+ self . append_message ( b"dom-sep" , b"r1cs v1" ) ;
6551 }
6652
67- fn commit_scalar ( & mut self , label : & ' static [ u8 ] , scalar : & Scalar ) {
68- self . commit_bytes ( label, scalar. as_bytes ( ) ) ;
53+ fn append_scalar ( & mut self , label : & ' static [ u8 ] , scalar : & Scalar ) {
54+ self . append_message ( label, scalar. as_bytes ( ) ) ;
6955 }
7056
71- fn commit_point ( & mut self , label : & ' static [ u8 ] , point : & CompressedRistretto ) {
72- self . commit_bytes ( label, point. as_bytes ( ) ) ;
57+ fn append_point ( & mut self , label : & ' static [ u8 ] , point : & CompressedRistretto ) {
58+ self . append_message ( label, point. as_bytes ( ) ) ;
7359 }
7460
75- fn validate_and_commit_point (
61+ fn validate_and_append_point (
7662 & mut self ,
7763 label : & ' static [ u8 ] ,
7864 point : & CompressedRistretto ,
@@ -82,7 +68,7 @@ impl TranscriptProtocol for Transcript {
8268 if point. is_identity ( ) {
8369 Err ( ProofError :: VerificationError )
8470 } else {
85- Ok ( self . commit_bytes ( label, point. as_bytes ( ) ) )
71+ Ok ( self . append_message ( label, point. as_bytes ( ) ) )
8672 }
8773 }
8874
0 commit comments