1- //! # Elliptic Curve VRFs.
1+ //! # Elliptic Curve VRF-AD
22//!
33//! This library provides flexible and efficient implementations of Verifiable
44//! Random Functions with Additional Data (VRF-AD), a cryptographic construct
88//! It leverages the [Arkworks](https://github.com/arkworks-rs) framework and
99//! supports customization of scheme parameters.
1010//!
11- //! Supported VRFs:
11+ //! ### Supported VRFs
12+ //!
1213//! - **IETF VRF**: Complies with ECVRF described in [RFC9381](https://datatracker.ietf.org/doc/rfc9381).
1314//! - **Pedersen VRF**: Described in [BCHSV23](https://eprint.iacr.org/2023/002).
1415//! - **Ring VRF**: A zero-knowledge-based inspired by [BCHSV23](https://eprint.iacr.org/2023/002).
16+ //!
17+ //! ### Schemes Specifications
18+ //!
19+ //! - [VRF Schemes Details](https://github.com/davxy/bandersnatch-vrfs-spec)
20+ //! - [Ring VRF ZK Proof](https://github.com/davxy/ring-proof-spec)
21+ //!
22+ //! ### Built-In suites
23+ //!
24+ //! The library conditionally includes the following pre-configured suites (see features section):
25+ //!
26+ //! - **Ed25519-SHA-512-TAI**: Supports IETF and Pedersen VRFs.
27+ //! - **Secp256r1-SHA-256-TAI**: Supports IETF and Pedersen VRFs.
28+ //! - **Bandersnatch** (_Edwards curve on BLS12-381_): Supports IETF, Pedersen, and Ring VRFs.
29+ //! - **JubJub** (_Edwards curve on BLS12-381_): Supports IETF, Pedersen, and Ring VRFs.
30+ //! - **Baby-JubJub** (_Edwards curve on BN254_): Supports IETF, Pedersen, and Ring VRFs.
31+ //!
32+ //! ### Basic Usage
33+ //!
34+ //! ```rust,ignore
35+ //! use ark_ec_vrfs::suites::bandersnatch::*;
36+ //! let secret = Secret::from_seed(b"example seed");
37+ //! let public = secret.public();
38+ //! let input = Input::new(b"example input").unwrap();
39+ //! let output = secret.output(input);
40+ //! let aux_data = b"optional aux data";
41+ //! ```
42+ //! #### IETF-VRF
43+ //!
44+ //! _Prove_
45+ //! ```rust,ignore
46+ //! use ark_ec_vrfs::ietf::Prover;
47+ //! let proof = secret.prove(input, output, aux_data);
48+ //! ```
49+ //!
50+ //! _Verify_
51+ //! ```rust,ignore
52+ //! use ark_ec_vrfs::ietf::Verifier;
53+ //! let result = public.verify(input, output, aux_data, &proof);
54+ //! ```
55+ //!
56+ //! #### Ring-VRF
57+ //!
58+ //! _Ring construction_
59+ //! ```rust,ignore
60+ //! const RING_SIZE: usize = 100;
61+ //! let prover_key_index = 3;
62+ //! // Construct an example ring with dummy keys
63+ //! let mut ring = (0..RING_SIZE).map(|i| Secret::from_seed(&i.to_le_bytes()).public().0).collect();
64+ //! // Patch the ring with the public key of the prover
65+ //! ring[prover_key_index] = public.0;
66+ //! // Any key can be replaced with the padding point
67+ //! ring[0] = RingContext::padding_point();
68+ //! ```
69+ //!
70+ //! _Ring parameters construction_
71+ //! ```rust,ignore
72+ //! let ring_ctx = RingContext::from_seed(RING_SIZE, b"example seed");
73+ //! ```
74+ //!
75+ //! _Prove_
76+ //! ```rust,ignore
77+ //! use ark_ec_vrfs::ring::Prover;
78+ //! let prover_key = ring_ctx.prover_key(&ring);
79+ //! let prover = ring_ctx.prover(prover_key, prover_key_index);
80+ //! let proof = secret.prove(input, output, aux_data, &prover);
81+ //! ```
82+ //!
83+ //! _Verify_
84+ //! ```rust,ignore
85+ //! use ark_ec_vrfs::ring::Verifier;
86+ //! let verifier_key = ring_ctx.verifier_key(&ring);
87+ //! let verifier = ring_ctx.verifier(verifier_key);
88+ //! let result = Public::verify(input, output, aux_data, &proof, &verifier);
89+ //! ```
90+ //!
91+ //! _Verifier key from commitment_
92+ //! ```rust,ignore
93+ //! let ring_commitment = ring_ctx.verifier_key().commitment();
94+ //! let verifier_key = ring_ctx.verifier_key_from_commitment(ring_commitment);
95+ //! ```
96+ //!
97+ //! ## Features
98+ //!
99+ //! - `default`: `std`
100+ //! - `full`: Enables all features listed below except `secret-split`, `parallel`, `asm`, `rfc-6979`, `test-vectors`.
101+ //! - `secret-split`: Point scalar multiplication with secret split. Secret scalar is split into the sum
102+ //! of two scalars, which randomly mutate but retain the same sum. Incurs 2x penalty in some internal
103+ //! sensible scalar multiplications, but provides side channel defenses.
104+ //! - `ring`: Ring-VRF for the curves supporting it.
105+ //! - `rfc-6979`: Support for nonce generation according to RFC-9381 section 5.4.2.1.
106+ //! - `test-vectors`: Deterministic ring-vrf proof. Useful for reproducible test vectors generation.
107+ //!
108+ //! ### Curves
109+ //!
110+ //! - `ed25519`
111+ //! - `jubjub`
112+ //! - `bandersnatch`
113+ //! - `baby-jubjub`
114+ //! - `secp256r1`
115+ //!
116+ //! ### Arkworks optimizations
117+ //!
118+ //! - `parallel`: Parallel execution where worth using `rayon`.
119+ //! - `asm`: Assembly implementation of some low level operations.
120+ //!
121+ //! ## License
122+ //!
123+ //! Distributed under the [MIT License](./LICENSE).
15124
16125#![ cfg_attr( not( feature = "std" ) , no_std) ]
17126#![ deny( unsafe_code) ]
18127
19- use zeroize:: Zeroize ;
20-
21128use ark_ec:: { AffineRepr , CurveGroup } ;
22129use ark_ff:: { One , PrimeField , Zero } ;
23130use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize } ;
24131use ark_std:: vec:: Vec ;
25132
26133use digest:: Digest ;
134+ use zeroize:: Zeroize ;
27135
28136pub mod codec;
29137pub mod ietf;
@@ -37,8 +145,9 @@ pub mod ring;
37145#[ cfg( test) ]
38146mod testing;
39147
40- // Re-export stuff that may be useful downstream.
41- #[ doc( hidden) ]
148+ use codec:: Codec ;
149+
150+ /// Re-export stuff that may be useful downstream.
42151pub mod reexports {
43152 pub use ark_ec;
44153 pub use ark_ff;
@@ -47,15 +156,13 @@ pub mod reexports {
47156}
48157
49158pub type AffinePoint < S > = <S as Suite >:: Affine ;
50-
51159pub type BaseField < S > = <AffinePoint < S > as AffineRepr >:: BaseField ;
52160pub type ScalarField < S > = <AffinePoint < S > as AffineRepr >:: ScalarField ;
53161pub type CurveConfig < S > = <AffinePoint < S > as AffineRepr >:: Config ;
54162
55163pub type HashOutput < S > = digest:: Output < <S as Suite >:: Hasher > ;
56164
57- pub use codec:: Codec ;
58-
165+ /// Overarching errors.
59166#[ derive( Debug ) ]
60167pub enum Error {
61168 /// Verification error
@@ -242,7 +349,7 @@ impl<S: Suite> Secret<S> {
242349
243350 /// Get the VRF output point relative to input.
244351 pub fn output ( & self , input : Input < S > ) -> Output < S > {
245- Output ( ( input. 0 * self . scalar ) . into_affine ( ) )
352+ Output ( smul ! ( input. 0 , self . scalar) . into_affine ( ) )
246353 }
247354}
248355
@@ -289,6 +396,7 @@ impl<S: Suite> Output<S> {
289396 }
290397}
291398
399+ /// Type aliases for the given suite.
292400#[ macro_export]
293401macro_rules! suite_types {
294402 ( $suite: ident) => {
0 commit comments