vb_accumulator/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2#![allow(non_snake_case)]
3
4//! # Accumulators, based on bilinear map (pairings) and without them
5//!
6//! ## vb_accumulator
7//! Dynamic Positive and Universal accumulators according to the paper: [Dynamic Universal Accumulator with Batch Update over Bilinear Groups](https://eprint.iacr.org/2020/777)
8//!
9//! Implements
10//! - a dynamic positive accumulator [`PositiveAccumulator`], that supports membership proofs.
11//! - a dynamic universal accumulator [`UniversalAccumulator`], that supports membership and non-membership proofs.
12//! - a zero knowledge proof of membership and non-membership in the accumulators with [`ProofProtocol`] as described in the paper.
13//!   These are essentially proofs of knowledge of a weak-BB signature
14//! - an alternate and more efficient protocol of zero knowledge proof of membership and non-membership based on a more
15//!   efficient protocol for proving knowledge of a weak-BB signature. This isn't described in the paper.
16//! - keyed verification proofs of membership and non-membership where the verifier knows the secret key. Such accumulator don't need pairings
17//!
18//! Allows
19//! - single and batch updates (additions, removals or both) to the accumulators.
20//! - single and batch updates to the witness.
21//!
22//! Both accumulators implement that trait [`Accumulator`] that contains the common functionality.
23//! Both [`MembershipWitness`] and [`NonMembershipWitness`] can be updated either using secret key or using public
24//! info published by accumulator manager called [`Omega`].
25//! Most of the update logic is in the trait [`Witness`] which is implemented by both [`MembershipWitness`]
26//! and [`NonMembershipWitness`].
27//! The implementation tries to use the same variable names as the paper and thus violate Rust's naming conventions at places.
28//!
29//! ## kb_accumulator
30//! Dynamic Positive and Universal accumulators according to the paper: [Efficient Constructions of Pairing Based Accumulators](https://eprint.iacr.org/2021/638)
31//!
32//! Implements
33//! - a dynamic positive accumulator [`KBPositiveAccumulator`], that supports membership proofs. Based on construction 2 in the paper.
34//! - a dynamic universal accumulator [`KBUniversalAccumulator`], that supports membership and non-membership proofs. Based on construction 3 in the paper
35//! - zero knowledge proofs of membership and non-membership in the accumulators. These are essentially proofs of knowledge of a
36//!   BB signature and weak-BB signature.
37//! - an alternate and more efficient protocol for membership and non-membership proofs
38//! - keyed verification proofs of membership and non-membership where the verifier knows the secret key. Such accumulator don't need pairings
39//!
40//! Allows batch updates to the accumulator and the witness using the techniques from `vb_accumulator`
41//!
42//! The implementation uses type-3 pairings compared to type-1 in the paper.
43//!
44//! [`Accumulator`]: crate::positive::Accumulator
45//! [`PositiveAccumulator`]: crate::positive::PositiveAccumulator
46//! [`UniversalAccumulator`]: crate::universal::UniversalAccumulator
47//! [`MembershipWitness`]: crate::witness::MembershipWitness
48//! [`NonMembershipWitness`]: crate::witness::NonMembershipWitness
49//! [`Witness`]: crate::witness::Witness
50//! [`Omega`]: crate::batch_utils::Omega
51//! [`ProofProtocol`]: crate::proofs::ProofProtocol
52//! [`KBPositiveAccumulator`]: crate::kb_positive_accumulator::adaptive_accumulator::KBPositiveAccumulator
53//! [`KBUniversalAccumulator`]: crate::kb_universal_accumulator::accumulator::KBUniversalAccumulator
54
55#[macro_use]
56pub mod utils;
57pub mod batch_utils;
58pub mod error;
59pub mod kb_positive_accumulator;
60pub mod kb_universal_accumulator;
61pub mod persistence;
62pub mod positive;
63pub mod proofs;
64pub mod proofs_cdh;
65pub mod proofs_keyed_verification;
66pub mod setup;
67pub mod setup_keyed_verification;
68#[cfg(test)]
69mod tests;
70pub mod threshold;
71pub mod universal;
72pub mod universal_init_constants;
73pub mod witness;
74
75pub mod prelude {
76    pub use crate::{
77        batch_utils::Omega,
78        error::VBAccumulatorError,
79        positive::{Accumulator, PositiveAccumulator},
80        proofs::*,
81        setup::*,
82        universal::UniversalAccumulator,
83        witness::{MembershipWitness, NonMembershipWitness, Witness},
84    };
85}
86
87#[cfg(test)]
88#[macro_use]
89pub mod serialization_test {
90    #[macro_export]
91    macro_rules! test_serialization {
92        ($obj_type:ty, $obj: expr) => {
93            let mut serz = vec![];
94            CanonicalSerialize::serialize_compressed(&$obj, &mut serz).unwrap();
95            let deserz: $obj_type =
96                CanonicalDeserialize::deserialize_compressed(&serz[..]).unwrap();
97            assert_eq!(deserz, $obj);
98
99            let mut serz = vec![];
100            $obj.serialize_uncompressed(&mut serz).unwrap();
101            let deserz: $obj_type =
102                CanonicalDeserialize::deserialize_uncompressed(&serz[..]).unwrap();
103            assert_eq!(deserz, $obj);
104
105            // Test JSON serialization
106            let ser = serde_json::to_string(&$obj).unwrap();
107            let deser = serde_json::from_str::<$obj_type>(&ser).unwrap();
108            assert_eq!($obj, deser);
109
110            // Test Message Pack serialization
111            let ser = rmp_serde::to_vec_named(&$obj).unwrap();
112            let deser = rmp_serde::from_slice::<$obj_type>(&ser).unwrap();
113            assert_eq!($obj, deser);
114        };
115    }
116}