Skip to content
Open
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
6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Running 1 test case...
PASSED
PASSED
PASSED
PASSED
23 changes: 22 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ LIBBITCOIN_CONSENSUS=libbitcoin_consensus.a
LIBBITCOIN_CLI=libbitcoin_cli.a
LIBBITCOIN_UTIL=libbitcoin_util.a
LIBLELANTUS=liblelantus.a
LIBAURA=libaura.a
LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a
LIBBITCOINQT=qt/libfiroqt.a
LIBSECP256K1=secp256k1/libsecp256k1.la
Expand Down Expand Up @@ -86,7 +87,8 @@ EXTRA_LIBRARIES += \
$(LIBBITCOIN_WALLET) \
$(LIBBITCOIN_ZMQ) \
$(LIBFIRO_SIGMA) \
$(LIBLELANTUS)
$(LIBLELANTUS) \
$(LIBAURA)

lib_LTLIBRARIES = $(LIBBITCOINCONSENSUS)

Expand Down Expand Up @@ -691,6 +693,24 @@ libsigma_a_SOURCES = \
sigma/params.cpp \
sigma/openssl_context.h

libaura_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -Werror
libaura_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -Werror
libaura_a_SOURCES = \
libaura/r1_proof.h \
libaura/r1_proof_generator.h \
libaura/r1_proof_generator.hpp \
libaura/r1_proof_verifier.h \
libaura/r1_proof_verifier.hpp \
libaura/sigmaplus_proof.h \
libaura/sigmaplus_prover.h \
libaura/sigmaplus_prover.hpp \
libaura/sigmaplus_verifier.h \
libaura/sigmaplus_verifier.hpp \
libaura/aura_primitives.h \
libaura/aura_primitives.hpp \
libaura/params.h\
libaura/params.cpp

if GLIBC_BACK_COMPAT
libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp
AM_LDFLAGS += $(COMPAT_LDFLAGS)
Expand Down Expand Up @@ -729,6 +749,7 @@ firod_LDADD = \
$(LIBBITCOIN_WALLET) \
$(LIBFIRO_SIGMA) \
$(LIBLELANTUS) \
$(LIBAURA) \
$(LIBBITCOIN_ZMQ) \
$(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) \
Expand Down
6 changes: 4 additions & 2 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ BITCOIN_TESTS = \
sigma/test/r1_test.cpp \
sigma/test/serialize_test.cpp \
sigma/test/sigma_primitive_types_test.cpp \
libaura/test/protocol_tests.cpp \
libaura/test/hoom_tests.cpp \
test/addrman_tests.cpp \
test/allocator_tests.cpp \
test/amount_tests.cpp \
Expand Down Expand Up @@ -198,8 +200,8 @@ endif
test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) -ltor

test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS)
test_test_bitcoin_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBLELANTUS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS) $(LIBBLSSIG_INCLUDES)
test_test_bitcoin_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBAURA) $(LIBLELANTUS) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \
$(BACKTRACE_LIB) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(ZMQ_LIBS) $(ZLIB_LIBS)
test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
if ENABLE_WALLET
Expand Down
58 changes: 58 additions & 0 deletions src/libaura/aura_primitives.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef FIRO_AURA_SIGMA_SIGMA_PRIMITIVES_H
#define FIRO_AURA_SIGMA_SIGMA_PRIMITIVES_H

#include "../secp256k1/include/MultiExponent.h"
#include "../secp256k1/include/GroupElement.h"
#include "../secp256k1/include/Scalar.h"

#include <algorithm>
#include <vector>

namespace aura {

template<class Exponent>
struct NthPower {
Exponent num;
Exponent pow;

NthPower(const Exponent& num_) : num(num_), pow(uint64_t(1)) {}
NthPower(const Exponent& num_, const Exponent& pow_) : num(num_), pow(pow_) {}

void go_next() {
pow *= num;
}
};

template<class Exponent, class GroupElement>
class SigmaPrimitives {

public:
static void commit(const GroupElement& g,
const std::vector<GroupElement>& h,
const std::vector<Exponent>& exp,
const Exponent& r,
GroupElement& result_out);

static GroupElement commit(const GroupElement& g, const Exponent m, const GroupElement h, const Exponent r);

static void convert_to_sigma(uint64_t num, uint64_t n, uint64_t m, std::vector<Exponent>& out);

static std::vector<uint64_t> convert_to_nal(uint64_t num, uint64_t n, uint64_t m);

static void generate_challenge(const std::vector<GroupElement>& group_elements,
Exponent& result_out);

/** \brief Adds a factor of (x*x + a) to the given polynomial in coefficients.
* \param[in,out] coefficients Coefficients of the polynomial created.
*/
static void new_factor(const Exponent& x, const Exponent& a, std::vector<Exponent>& coefficients);

static GroupElement HelperFunction(const std::vector<GroupElement>& commits, const std::vector <Exponent>& x);

};

} // namespace aura

#include "aura_primitives.hpp"

#endif // FIRO_AURA_SIGMA_SIGMA_PRIMITIVES_H
103 changes: 103 additions & 0 deletions src/libaura/aura_primitives.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "../../crypto/sha256.h"

namespace aura {

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::commit(const GroupElement& g,
const std::vector<GroupElement>& h,
const std::vector<Exponent>& exp,
const Exponent& r,
GroupElement& result_out) {
secp_primitives::MultiExponent mult(h, exp);
result_out += g * r + mult.get_multiple();
}

template<class Exponent, class GroupElement>
GroupElement SigmaPrimitives<Exponent, GroupElement>::commit(
const GroupElement& g,
const Exponent m,
const GroupElement h,
const Exponent r){
return g * m + h * r;
}

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::convert_to_sigma(
uint64_t num,
uint64_t n,
uint64_t m,
std::vector<Exponent>& out) {
uint64_t rem;
uint64_t j = 0;

for (j = 0; j < m; ++j)
{
rem = num % n;
num /= n;
for (uint64_t i = 0; i < n; ++i) {
if(i == rem)
out.push_back(Exponent(uint64_t(1)));
else
out.push_back(Exponent(uint64_t(0)));
}
}
}

template<class Exponent, class GroupElement>
std::vector<uint64_t> SigmaPrimitives<Exponent, GroupElement>::convert_to_nal(
uint64_t num,
uint64_t n,
uint64_t m) {
std::vector<uint64_t> result;
uint64_t rem;
uint64_t j = 0;
while (num != 0)
{
rem = num % n;
num /= n;
result.push_back(rem);
j++;
}
result.resize(m);
return result;
}

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::generate_challenge(
const std::vector<GroupElement>& group_elements,
Exponent& result_out) {
if (group_elements.empty())
throw std::runtime_error("Group elements empty while generating a challenge.");
CSHA256 hash;
std::vector<unsigned char> data(group_elements.size() * group_elements[0].memoryRequired());
unsigned char* current = data.data();
for (size_t i = 0; i < group_elements.size(); ++i) {
current = group_elements[i].serialize(current);
}
hash.Write(data.data(), data.size());
unsigned char result_data[CSHA256::OUTPUT_SIZE];
hash.Finalize(result_data);
result_out = result_data;
}

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::new_factor(
const Exponent& x,
const Exponent& a,
std::vector<Exponent>& coefficients) {
std::size_t degree = coefficients.size();
coefficients.push_back(x * coefficients[degree-1]);
for (std::size_t d = degree-1; d >= 1; --d)
coefficients[d] = a * coefficients[d] + x * coefficients[d-1];
coefficients[0] *= a;
}

template<class Exponent, class GroupElement>
GroupElement SigmaPrimitives<Exponent, GroupElement>::HelperFunction(
const std::vector<GroupElement>& commits,
const std::vector <Exponent>& x) {
secp_primitives::MultiExponent mult(commits, x);
return mult.get_multiple();
}

} // namespace aura
Loading