Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching Sigma Generator creation #516

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2424,7 +2424,7 @@ bool CheckInputs(const CTransaction &tx, CValidationState &state, const CCoinsVi
CDataStream serializedCoinSpend((const char *)&*(txin.scriptSig.begin() + 1),
(const char *)&*txin.scriptSig.end(),
SER_NETWORK, PROTOCOL_VERSION);
sigma::CoinSpend newSpend(sigma::SigmaParams, serializedCoinSpend);
sigma::CoinSpend newSpend(sigma::Params::get_default(), serializedCoinSpend);
uint64_t denom = newSpend.getIntDenomination();
totalInputValue += denom;
}
Expand Down
2 changes: 2 additions & 0 deletions src/secp256k1/include/GroupElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class GroupElement final {

std::size_t hash() const;

void set_base_g();

friend class MultiExponent;
private:
// Returns the secp object inside it.
Expand Down
4 changes: 4 additions & 0 deletions src/secp256k1/src/cpp/GroupElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,8 @@ const void* GroupElement::get_value() const {
return g_;
}

void GroupElement::set_base_g() {
secp256k1_gej_set_ge(reinterpret_cast<secp256k1_gej *>(g_), &secp256k1_ge_const_g);
}

} // namespace secp_primitives
16 changes: 14 additions & 2 deletions src/sigma/params.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "chainparams.h"
#include "params.h"

namespace sigma {
Expand All @@ -8,8 +9,19 @@ Params* Params::get_default() {
return instance;
else {
//fixing generator G;
GroupElement g("9216064434961179932092223867844635691966339998754536116709681652691785432045",
"33986433546870000256104618635743654523665060392313886665479090285075695067131");
GroupElement g;

if(!(::Params().GetConsensus().IsTestnet())) {
unsigned char buff[32] = {0};
GroupElement base;
base.set_base_g();
base.sha256(buff);
g.generate(buff);
}
else
g = GroupElement("9216064434961179932092223867844635691966339998754536116709681652691785432045",
"33986433546870000256104618635743654523665060392313886665479090285075695067131");

//fixing n and m; N = n^m = 16,384
int n = 4;
int m = 7;
Expand Down
4 changes: 3 additions & 1 deletion src/sigma/test/coin_spend_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include "../../streams.h"
#include "../../uint256.h"

#include "../../test/fixtures.h"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(sigma_coin_spend_tests)
BOOST_FIXTURE_TEST_SUITE(sigma_coin_spend_tests, ZerocoinTestingSetup200)

BOOST_AUTO_TEST_CASE(serialize_deserialize_test)
{
Expand Down
4 changes: 3 additions & 1 deletion src/sigma/test/coin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

#include "../../streams.h"

#include "../../test/fixtures.h"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(sigma_coin_tests)
BOOST_FIXTURE_TEST_SUITE(sigma_coin_tests, ZerocoinTestingSetup200)

BOOST_AUTO_TEST_CASE(pubcoin_serialization)
{
Expand Down
4 changes: 3 additions & 1 deletion src/sigma/test/protocol_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(sigma_protocol_tests)
#include "../../test/fixtures.h"

BOOST_FIXTURE_TEST_SUITE(sigma_protocol_tests, ZerocoinTestingSetup200)

BOOST_AUTO_TEST_CASE(one_out_of_n)
{
Expand Down
4 changes: 3 additions & 1 deletion src/sigma/test/serialize_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(sigma_serialize_tests)
#include "../../test/fixtures.h"

BOOST_FIXTURE_TEST_SUITE(sigma_serialize_tests, ZerocoinTestingSetup200)

BOOST_AUTO_TEST_CASE(group_element_serialize)
{
Expand Down
15 changes: 6 additions & 9 deletions src/zerocoin_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@

namespace sigma {

// Set up the Sigma Params object
sigma::Params* SigmaParams = sigma::Params::get_default();

static CSigmaState sigmaState;

static bool CheckSigmaSpendSerial(
Expand Down Expand Up @@ -99,7 +96,7 @@ std::pair<std::unique_ptr<sigma::CoinSpend>, uint32_t> ParseSigmaSpend(const CTx
PROTOCOL_VERSION
);

std::unique_ptr<sigma::CoinSpend> spend(new sigma::CoinSpend(SigmaParams, serialized));
std::unique_ptr<sigma::CoinSpend> spend(new sigma::CoinSpend(sigma::Params::get_default(), serialized));

return std::make_pair(std::move(spend), groupId);
}
Expand Down Expand Up @@ -459,7 +456,7 @@ bool CheckSigmaTransaction(
CDataStream serializedCoinSpend((const char *)&*(txin.scriptSig.begin() + 1),
(const char *)&*txin.scriptSig.end(),
SER_NETWORK, PROTOCOL_VERSION);
sigma::CoinSpend newSpend(SigmaParams, serializedCoinSpend);
sigma::CoinSpend newSpend(sigma::Params::get_default(), serializedCoinSpend);
uint64_t denom = newSpend.getIntDenomination();
totalValue += denom;
sigma::CoinDenomination denomination;
Expand Down Expand Up @@ -488,8 +485,8 @@ void RemoveSigmaSpendsReferencingBlock(CTxMemPool& pool, CBlockIndex* blockIndex
for (CTxMemPool::txiter mi = pool.mapTx.begin(); mi != pool.mapTx.end(); ++mi) {
const CTransaction& tx = mi->GetTx();
if (tx.IsSigmaSpend()) {
// Run over all the inputs, check if their Accumulator block hash is equal to
// block removed. If any one is equal, remove txn from mempool.
// Run over all the inputs, check if their Accumulator block hash is equal to
// block removed. If any one is equal, remove txn from mempool.
for (const CTxIn& txin : tx.vin) {
if (txin.IsSigmaSpend()) {
std::unique_ptr<sigma::CoinSpend> spend;
Expand Down Expand Up @@ -533,7 +530,7 @@ Scalar GetSigmaSpendSerialNumber(const CTransaction &tx, const CTxIn &txin) {
(const char *)&*(txin.scriptSig.begin() + 1),
(const char *)&*txin.scriptSig.end(),
SER_NETWORK, PROTOCOL_VERSION);
sigma::CoinSpend spend(SigmaParams, serializedCoinSpend);
sigma::CoinSpend spend(sigma::Params::get_default(), serializedCoinSpend);
return spend.getCoinSerialNumber();
}
catch (const std::ios_base::failure &) {
Expand All @@ -555,7 +552,7 @@ CAmount GetSigmaSpendInput(const CTransaction &tx) {
(const char *)&*(txin.scriptSig.begin() + 1),
(const char *)&*txin.scriptSig.end(),
SER_NETWORK, PROTOCOL_VERSION);
sigma::CoinSpend spend(SigmaParams, serializedCoinSpend);
sigma::CoinSpend spend(sigma::Params::get_default(), serializedCoinSpend);
sum += spend.getIntDenomination();
}
return sum;
Expand Down
3 changes: 0 additions & 3 deletions src/zerocoin_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ namespace zerocoin_tests3_v3 { struct zerocoin_mintspend_v3; }

namespace sigma {

// zerocoin parameters
extern Params *SigmaParams;

// Zerocoin transaction info, added to the CBlock to ensure zerocoin mint/spend transactions got their info stored into
// index
class CSigmaTxInfo {
Expand Down