代码拉取完成,页面将自动刷新
/**
* @file Accumulator.cpp
*
* @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.
**/
#include <sstream>
#include "Accumulator.h"
namespace libzerocoin {
//Accumulator class
Accumulator::Accumulator(const AccumulatorAndProofParams* p, const CoinDenomination d): params(p), denonination(d) {
if (!(params->initialized)){
throw ZerocoinException("Invalid parameters for accumulator");
}
this->value = this->params->accumulatorBase;
}
void Accumulator::accumulate(const PublicCoin& coin) {
// Make sure we're initialized
if(!(this->value)){
throw ZerocoinException("Accumulator is not initialized");
}
if(this->denonination != coin.getDenomination()){
std::stringstream msg;
msg << "Wrong denomination for coin. Expected coins of denomination: " <<
this->denonination << ". Instead, got a coin of denomination: " <<
coin.getDenomination() << std::ends;
throw std::invalid_argument(msg.str());
}
if(coin.validate()){
// Compute new accumulator = "old accumulator"^{element} mod N
this->value = this->value.pow_mod(coin.getValue(), this->params->accumulatorModulus);
}else{
throw std::invalid_argument("Coin is not valid");
}
}
const CoinDenomination Accumulator::getDenomination() const {
return static_cast<CoinDenomination> (this->denonination);
}
const Bignum& Accumulator::getValue() const {
return this->value;
}
Accumulator& Accumulator::operator += (const PublicCoin& c) {
this->accumulate(c);
return *this;
}
bool Accumulator::operator == (const Accumulator rhs) const{
return this->value == rhs.value;
}
//AccumulatorWitness class
AccumulatorWitness::AccumulatorWitness(const Params* p,
const Accumulator& checkpoint, const PublicCoin coin): params(p), witness(checkpoint), element(coin) {
}
void AccumulatorWitness::AddElement(const PublicCoin& c) {
if(element != c){
witness += c;
}
}
const Bignum& AccumulatorWitness::getValue() const{
return this->witness.getValue();
}
bool AccumulatorWitness::VerifyWitness(const Accumulator& a) const {
Accumulator temp(witness);
temp += element;
return temp == a;
}
AccumulatorWitness& AccumulatorWitness::operator +=(
const PublicCoin& rhs) {
this->AddElement(rhs);
return *this;
}
} /* namespace libzerocoin */
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。