4 * @brief Accumulator and AccumulatorWitness classes for the Zerocoin library.
6 * @author Ian Miers, Christina Garman and Matthew Green
9 * @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green
10 * @license This project is released under the MIT license.
12 #ifndef ACCUMULATOR_H_
13 #define ACCUMULATOR_H_
15 namespace libzerocoin {
17 * \brief Implementation of the RSA-based accumulator.
24 * @brief Construct an Accumulator from a stream.
25 * @param p An AccumulatorAndProofParams object containing global parameters
26 * @param d the denomination of coins we are accumulating
27 * @throw Zerocoin exception in case of invalid parameters
29 template<typename Stream>
30 Accumulator(const AccumulatorAndProofParams* p, Stream& strm): params(p) {
34 template<typename Stream>
35 Accumulator(const Params* p, Stream& strm) {
37 this->params = &(p->accumulatorParams);
41 * @brief Construct an Accumulator from a Params object.
42 * @param p A Params object containing global parameters
43 * @param d the denomination of coins we are accumulating
44 * @throw Zerocoin exception in case of invalid parameters
46 Accumulator(const AccumulatorAndProofParams* p, const CoinDenomination d = ZQ_PEDERSEN);
48 Accumulator(const Params* p, const CoinDenomination d = ZQ_PEDERSEN);
51 * Accumulate a coin into the accumulator. Validates
52 * the coin prior to accumulation.
54 * @param coin A PublicCoin to accumulate.
56 * @throw Zerocoin exception if the coin is not valid.
59 void accumulate(const PublicCoin &coin);
61 const CoinDenomination getDenomination() const;
62 /** Get the accumulator result
64 * @return a Bignum containing the result.
66 const Bignum& getValue() const;
70 // * Used to set the accumulator value
72 // * Use this to handle accumulator checkpoints
73 // * @param b the value to set the accumulator to.
74 // * @throw A ZerocoinException if the accumulator value is invalid.
76 // void setValue(Bignum &b); // shouldn't this be a constructor?
78 /** Used to accumulate a coin
80 * @param c the coin to accumulate
81 * @return a refrence to the updated accumulator.
83 Accumulator& operator +=(const PublicCoin& c);
84 bool operator==(const Accumulator rhs) const;
89 READWRITE(denomination);
92 const AccumulatorAndProofParams* params;
94 // Denomination is stored as an INT because storing
95 // and enum raises amigiuities in the serialize code //FIXME if possible
99 /**A witness that a PublicCoin is in the accumulation of a set of coins
102 class AccumulatorWitness {
104 template<typename Stream>
105 AccumulatorWitness(const Params* p, Stream& strm): params(p) {
109 /** Construct's a witness. You must add all elements after the witness
110 * @param p pointer to params
111 * @param checkpoint the last known accumulator value before the element was added
112 * @param coin the coin we want a witness to
114 AccumulatorWitness(const Params* p, const Accumulator& checkpoint, const PublicCoin coin);
116 /** Adds element to the set whose's accumulation we are proving coin is a member of
118 * @param c the coin to add
120 void AddElement(const PublicCoin& c);
124 * @return the value of the witness
126 const Bignum& getValue() const;
128 /** Checks that this is a witness to the accumulation of coin
129 * @param a the accumulator we are checking against.
130 * @param publicCoin the coin we're providing a witness for
131 * @return True if the witness computation validates
133 bool VerifyWitness(const Accumulator& a, const PublicCoin &publicCoin) const;
136 * Adds rhs to the set whose's accumulation ware proving coin is a member of
137 * @param rhs the PublicCoin to add
140 AccumulatorWitness& operator +=(const PublicCoin& rhs);
142 const Params* params;
144 const PublicCoin element;
147 } /* namespace libzerocoin */
148 #endif /* ACCUMULATOR_H_ */