4
4
use ark_ec:: { CurveGroup , PrimeGroup } ;
5
5
use ark_ff:: PrimeField ;
6
6
use ark_std:: UniformRand ;
7
- use nimue:: codecs:: ark :: * ;
7
+ use nimue:: codecs:: arkworks_algebra :: * ;
8
8
9
9
/// Extend the IO pattern with the Schnorr protocol.
10
- trait SchnorrIOPattern < G : CurveGroup > {
10
+ trait SchnorrDomainSeparator < G : CurveGroup > {
11
11
/// Adds the entire Schnorr protocol to the IO pattern (statement and proof).
12
12
fn add_schnorr_io ( self ) -> Self ;
13
13
}
14
14
15
- impl < G , H , U > SchnorrIOPattern < G > for IOPattern < H , U >
15
+ impl < G , H , U > SchnorrDomainSeparator < G > for DomainSeparator < H , U >
16
16
where
17
17
G : CurveGroup ,
18
18
U : Unit ,
19
- H : DuplexInterface < U > ,
20
- IOPattern < H , U > : GroupIOPattern < G > + ByteIOPattern ,
19
+ H : DuplexSpongeInterface < U > ,
20
+ DomainSeparator < H , U > : GroupDomainSeparator < G > + ByteDomainSeparator ,
21
21
{
22
22
fn add_schnorr_io ( self ) -> Self {
23
23
self . add_points ( 1 , "generator (P)" )
@@ -39,15 +39,15 @@ fn keygen<G: CurveGroup>() -> (G::ScalarField, G) {
39
39
}
40
40
41
41
/// The prove algorithm takes as input
42
- /// - the prover state `ProverTranscript `, that has access to a random oracle `H` and can absorb/squeeze elements from the group `G`.
42
+ /// - the prover state `ProverState `, that has access to a random oracle `H` and can absorb/squeeze elements from the group `G`.
43
43
/// - The generator `P` in the group.
44
44
/// - the secret key $x \in \mathbb{Z}_p$
45
45
/// It returns a zero-knowledge proof of knowledge of `x` as a sequence of bytes.
46
46
#[ allow( non_snake_case) ]
47
47
fn prove < G , H , U > (
48
48
// the hash function `H` works over bytes.
49
49
// Algebraic hashes over a particular domain can be denoted with an additional type argument implementing `nimue::Unit`.
50
- merlin : & mut ProverTranscript < H , U > ,
50
+ merlin : & mut ProverPrivateState < H , U > ,
51
51
// the generator
52
52
P : G ,
53
53
// the secret key
@@ -56,11 +56,11 @@ fn prove<G, H, U>(
56
56
where
57
57
U : Unit ,
58
58
G :: BaseField : PrimeField ,
59
- H : DuplexInterface < U > ,
59
+ H : DuplexSpongeInterface < U > ,
60
60
G : CurveGroup ,
61
- ProverTranscript < H , U > : GroupWriter < G > + FieldWriter < G :: BaseField > + ByteChallenges ,
61
+ ProverPrivateState < H , U > : ProverMessageGroup < G > + ProverMessageField < G :: BaseField > + VerifierMessageBytes ,
62
62
{
63
- // `ProverTranscript ` types implement a cryptographically-secure random number generator that is tied to the protocol transcript
63
+ // `ProverState ` types implement a cryptographically-secure random number generator that is tied to the protocol transcript
64
64
// and that can be accessed via the `rng()` function.
65
65
let k = G :: ScalarField :: rand ( merlin. rng ( ) ) ;
66
66
let K = P * k;
@@ -79,18 +79,18 @@ where
79
79
merlin. add_scalars ( & [ r_q] ) ?;
80
80
81
81
// Output the current protocol transcript as a sequence of bytes.
82
- Ok ( merlin. transcript ( ) )
82
+ Ok ( merlin. narg_string ( ) )
83
83
}
84
84
85
85
/// The verify algorithm takes as input
86
- /// - the verifier state `VerifierTranscript `, that has access to a random oracle `H` and can deserialize/squeeze elements from the group `G`.
86
+ /// - the verifier state `VerifierState `, that has access to a random oracle `H` and can deserialize/squeeze elements from the group `G`.
87
87
/// - the secret key `witness`
88
88
/// It returns a zero-knowledge proof of knowledge of `witness` as a sequence of bytes.
89
89
#[ allow( non_snake_case) ]
90
90
fn verify < ' a , G , H , U > (
91
91
// `ArkGroupMelin` contains the veirifier state, including the messages currently read. In addition, it is aware of the group `G`
92
92
// from which it can serialize/deserialize elements.
93
- arthur : & mut VerifierTranscript < ' a , H , U > ,
93
+ arthur : & mut VerifierState < ' a , H , U > ,
94
94
// The group generator `P``
95
95
P : G ,
96
96
// The public key `X`
@@ -100,8 +100,8 @@ where
100
100
U : Unit ,
101
101
G :: BaseField : PrimeField ,
102
102
G : CurveGroup ,
103
- H : DuplexInterface < U > ,
104
- VerifierTranscript < ' a , H , U > : GroupReader < G > + FieldReader < G :: BaseField > + ByteChallenges ,
103
+ H : DuplexSpongeInterface < U > ,
104
+ VerifierState < ' a , H , U > : DeserializeGroup < G > + DeserializeField < G :: BaseField > + VerifierMessageBytes ,
105
105
{
106
106
// Read the protocol from the transcript:
107
107
let [ K ] = arthur. next_points ( ) ?;
@@ -137,15 +137,15 @@ fn main() {
137
137
// type U = ark_bls12_381::Fq;
138
138
139
139
// Set up the IO for the protocol transcript with domain separator "nimue::examples::schnorr"
140
- let io = IOPattern :: < H , U > :: new ( "nimue::examples::schnorr" ) ;
141
- let io = SchnorrIOPattern :: < G > :: add_schnorr_io ( io ) ;
140
+ let domain_separator = DomainSeparator :: < H , U > :: new ( "nimue::examples::schnorr" ) ;
141
+ let domain_separator = SchnorrDomainSeparator :: < G > :: add_schnorr_io ( domain_separator ) ;
142
142
143
143
// Set up the elements to prove
144
144
let P = G :: generator ( ) ;
145
145
let ( x, X ) = keygen ( ) ;
146
146
147
147
// Create the prover transcript, add the statement to it, and then invoke the prover.
148
- let mut merlin = io . to_merlin ( ) ;
148
+ let mut merlin = domain_separator . to_merlin ( ) ;
149
149
merlin. public_points ( & [ P , X ] ) . unwrap ( ) ;
150
150
merlin. ratchet ( ) . unwrap ( ) ;
151
151
let proof = prove ( & mut merlin, P , x) . expect ( "Invalid proof" ) ;
@@ -154,7 +154,7 @@ fn main() {
154
154
println ! ( "Here's a Schnorr signature:\n {}" , hex:: encode( proof) ) ;
155
155
156
156
// Verify the proof: create the verifier transcript, add the statement to it, and invoke the verifier.
157
- let mut arthur = VerifierTranscript :: < H , U > :: new ( & io , & proof) ;
157
+ let mut arthur = VerifierState :: < H , U > :: new ( & domain_separator , & proof) ;
158
158
arthur. public_points ( & [ P , X ] ) . unwrap ( ) ;
159
159
arthur. ratchet ( ) . unwrap ( ) ;
160
160
verify ( & mut arthur, P , X ) . expect ( "Invalid proof" ) ;
0 commit comments