You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/iopattern.rs
+32-28
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,31 @@ use super::hash::{DuplexHash, Unit};
14
14
/// and as such is the only forbidden characted in labels.
15
15
constSEP_BYTE:&str = "\0";
16
16
17
+
/// The IO Pattern of an interactive protocol.
18
+
///
19
+
/// An IO pattern is a string that specifies the protocol in a simple,
20
+
/// non-ambiguous, human-readable format. A typical example is the following:
21
+
///
22
+
/// ```text
23
+
/// domain-separator A32generator A32public-key R A32commitment S32challenge A32response
24
+
/// ```
25
+
/// The domain-separator is a user-specified string uniquely identifying the end-user application (to avoid cross-protocol attacks).
26
+
/// The letter `A` indicates the absorption of a public input (an `ABSORB`), while the letter `S` indicates the squeezing (a `SQUEEZE`) of a challenge.
27
+
/// The letter `R` indicates a ratcheting operation: ratcheting means invoking the hash function even on an incomplete block.
28
+
/// It provides forward secrecy and allows it to start from a clean rate.
29
+
/// After the operation type, is the number of elements in base 10 that are being absorbed/squeezed.
30
+
/// Then, follows the label associated with the element being absorbed/squeezed. This often comes from the underlying description of the protocol. The label cannot start with a digit or contain the NULL byte.
31
+
32
+
#[derive(Clone)]
33
+
pubstructIOPattern<H = crate::DefaultHash,U = u8>
34
+
where
35
+
U:Unit,
36
+
H:DuplexHash<U>,
37
+
{
38
+
io:String,
39
+
_hash:PhantomData<(H,U)>,
40
+
}
41
+
17
42
/// Sponge operations.
18
43
#[derive(Clone,Copy,PartialEq,Eq,Debug)]
19
44
pub(crate)enumOp{
@@ -46,34 +71,6 @@ impl Op {
46
71
}
47
72
}
48
73
49
-
/// The IO Pattern of an interactive protocol.
50
-
///
51
-
/// An IO Pattern is a string denoting a
52
-
/// sequence of operations to be performed on a [`crate::DuplexHash`].
53
-
/// The IO Pattern is prepended by a domain separator, a NULL-terminated string
54
-
/// that is used to prevent collisions between different protocols.
55
-
/// Each operation (absorb, squeeze, ratchet) is identified by a
56
-
/// single character, followed by the number of units (bytes, or field elements)
57
-
/// to be absorbed/squeezed, and a NULL-terminated label identifying the element.
Copy file name to clipboardexpand all lines: src/lib.rs
+10-4
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,17 @@
22
22
//! - **Private randomness generation**.
23
23
//! It is vital to avoid providing two different challenges for the same prover message. We do our best to avoid it by tying down the prover randomness to the protocol transcript, without making the proof deterministic.
24
24
//!
25
-
//! # Intuition
25
+
//! # Overview
26
+
//!
27
+
//! The library does three things:
28
+
//!
29
+
//! - Assist in the construction of a protocol transcript for a public-coin zero-knowledge proof ([Arthur]),
30
+
//! - Assist in the deserialization and verification of a public-coin protocol ([Merlin]).
26
31
//!
27
32
//! The basic idea behind Nimue is that prover and verifier "commit" to the protocol before running the actual protocol.
28
-
//! This preprocessing step, where the input/output of the prover, generates an "IV" that is used to initialize the hash function for the Fiat-Shamir heuristic.
29
-
//! From here, prover just proceeds with concatenation, without ever worrying
33
+
//! They a string encoding the sequence of messages sent from the prover and the verifier (the [IOPattern]), which is used as an "IV" to initialize the hash function for the Fiat-Shamir heuristic.
34
+
//!
35
+
//! There are prover just proceeds with concatenation, without ever worrying
30
36
//! about encoding length and special flags to embed in the hash function.
31
37
//! This allows for
32
38
//! better preprocessing,
@@ -48,7 +54,7 @@
48
54
//! An [`IOPattern`] is a UTF8-encoded string wrapper. Absorptions are denoted as `format!(A{}, length)` and
49
55
//! squeezes as `format!(S{}, length)`. A label is added at the end of the string, meant to describe the *type* and
50
56
//! *the variable* as used in the protocol. Operations are separated by a NULL byte and therefore labels cannot contain
51
-
//! NULL bytes themselves, nor start with an ASCII digit.x
57
+
//! NULL bytes themselves, nor start with an ASCII digit.
//! The type constraint on [`crate::Arthur`] hints the compiler that we are going to be absorbing elements from the group `G` and squeezing challenges in the scalar field `G::ScalarField`. Similarly, we could have been squeezing out bytes.
32
+
//!
33
+
//! ```rust
34
+
//! # use ark_ec::CurveGroup;
35
+
//! # use ark_std::UniformRand;
36
+
//! # use ark_ff::PrimeField;
37
+
//! # use nimue::{IOPattern, Arthur, DuplexHash, ProofResult};
38
+
//! # use nimue::plugins::ark::*;
39
+
//!
40
+
//! fn prove<G>(
41
+
//! arthur: &mut Arthur,
42
+
//! x: G::ScalarField,
43
+
//! ) -> ProofResult<&[u8]>
44
+
//! where
45
+
//! G: CurveGroup,
46
+
//! Arthur: GroupWriter<G> + ByteChallenges,
47
+
//! {
48
+
//! let k = G::ScalarField::rand(arthur.rng());
49
+
//! arthur.add_points(&[G::generator() * k])?;
50
+
//! let c_bytes = arthur.challenge_bytes::<16>()?;
51
+
//! let c = G::ScalarField::from_le_bytes_mod_order(&c_bytes);
52
+
//! arthur.add_scalars(&[k + c * x])?;
53
+
//! Ok(arthur.transcript())
54
+
//! }
55
+
//! ```
56
+
/// Add public elements (field or group elements) to the protocol transcript.
0 commit comments