-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathAccumulator.h
148 lines (129 loc) · 4.11 KB
/
Accumulator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* @file Accumulator.h
*
* @brief Accumulator and AccumulatorWitness classes for the Zerocoin library.
*
* @author Ian Miers, Christina Garman and Matthew Green
* @date June 2013
*
* @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green
* @license This project is released under the MIT license.
**/
#ifndef ACCUMULATOR_H_
#define ACCUMULATOR_H_
namespace libzerocoin {
/**
* \brief Implementation of the RSA-based accumulator.
**/
class Accumulator {
public:
/**
* @brief Construct an Accumulator from a stream.
* @param p An AccumulatorAndProofParams object containing global parameters
* @param d the denomination of coins we are accumulating
* @throw Zerocoin exception in case of invalid parameters
**/
template<typename Stream>
Accumulator(const AccumulatorAndProofParams* p, Stream& strm): params(p) {
strm >> *this;
}
template<typename Stream>
Accumulator(const Params* p, Stream& strm) {
strm >> *this;
this->params = &(p->accumulatorParams);
}
/**
* @brief Construct an Accumulator from a Params object.
* @param p A Params object containing global parameters
* @param d the denomination of coins we are accumulating
* @throw Zerocoin exception in case of invalid parameters
**/
Accumulator(const AccumulatorAndProofParams* p, const CoinDenomination d = ZQ_LOVELACE);
Accumulator(const Params* p, const CoinDenomination d = ZQ_LOVELACE);
/**
* Accumulate a coin into the accumulator. Validates
* the coin prior to accumulation.
*
* @param coin A PublicCoin to accumulate.
*
* @throw Zerocoin exception if the coin is not valid.
*
**/
void accumulate(const PublicCoin &coin);
const CoinDenomination getDenomination() const;
/** Get the accumulator result
*
* @return a Bignum containing the result.
*/
const Bignum& getValue() const;
// /**
// * Used to set the accumulator value
// *
// * Use this to handle accumulator checkpoints
// * @param b the value to set the accumulator to.
// * @throw A ZerocoinException if the accumulator value is invalid.
// */
// void setValue(Bignum &b); // shouldn't this be a constructor?
/** Used to accumulate a coin
*
* @param c the coin to accumulate
* @return a refrence to the updated accumulator.
*/
Accumulator& operator +=(const PublicCoin& c);
bool operator==(const Accumulator rhs) const;
IMPLEMENT_SERIALIZE
(
READWRITE(value);
READWRITE(denomination);
)
private:
const AccumulatorAndProofParams* params;
Bignum value;
// Denomination is stored as an INT because storing
// and enum raises amigiuities in the serialize code //FIXME if possible
int denomination;
};
/**A witness that a PublicCoin is in the accumulation of a set of coins
*
*/
class AccumulatorWitness {
public:
template<typename Stream>
AccumulatorWitness(const Params* p, Stream& strm): params(p) {
strm >> *this;
}
/** Construct's a witness. You must add all elements after the witness
* @param p pointer to params
* @param checkpoint the last known accumulator value before the element was added
* @param coin the coin we want a witness to
*/
AccumulatorWitness(const Params* p, const Accumulator& checkpoint, const PublicCoin coin);
/** Adds element to the set whose's accumulation we are proving coin is a member of
*
* @param c the coin to add
*/
void AddElement(const PublicCoin& c);
/**
*
* @return the value of the witness
*/
const Bignum& getValue() const;
/** Checks that this is a witness to the accumulation of coin
* @param a the accumulator we are checking against.
* @param publicCoin the coin we're providing a witness for
* @return True if the witness computation validates
*/
bool VerifyWitness(const Accumulator& a, const PublicCoin &publicCoin) const;
/**
* Adds rhs to the set whose's accumulation ware proving coin is a member of
* @param rhs the PublicCoin to add
* @return
*/
AccumulatorWitness& operator +=(const PublicCoin& rhs);
private:
const Params* params;
Accumulator witness;
const PublicCoin element;
};
} /* namespace libzerocoin */
#endif /* ACCUMULATOR_H_ */