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

[0.17] Cleaned up CA #515

Merged
merged 58 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ce19a5f
Add secure reporting document, link in README
instagibbs Mar 6, 2019
77ba5ee
RPC params convertion cleanup
stevenroose Mar 20, 2019
36a5d5d
Fix bug in calculate_contract for Liquid
stevenroose Mar 19, 2019
3a0b3b7
Add tweakfedpeg and compatbility test
instagibbs Mar 19, 2019
3e7cff1
Disable tests that are not relevant for Elements
stevenroose Feb 27, 2019
aa375e6
Replace CScriptID and CKeyID in CTxDestination with dedicated type
instagibbs Feb 19, 2019
045e615
Add CKey::ECDH
stevenroose Mar 19, 2019
00fba77
Add liquidv1 chainparams
instagibbs Mar 15, 2019
17a22f1
Add support for blinded addresses
stevenroose Mar 15, 2019
9cb2fa0
Add blech32 python implementation with diff annotation with segwit_ad…
instagibbs Mar 1, 2019
0f28780
Add blech32 implementation and API
stevenroose Mar 19, 2019
14af0b6
Implement blech32 addresses, expose over RPC
instagibbs Mar 1, 2019
10773c6
Add CAsset and CAmountMap
stevenroose Mar 19, 2019
84954c8
Add CAssetsDir
stevenroose Mar 19, 2019
fd411bb
Enable surjection proof module in secp256k1-zkp
stevenroose Mar 19, 2019
d0322f7
Add initial issuance boilerplate
stevenroose Mar 19, 2019
8b8256d
Add ConfidentialCommitment-based types
stevenroose Mar 19, 2019
f81122f
Add asset and value blinding functionality
stevenroose Mar 19, 2019
fde9fe1
Add basic issuance boilerplate
stevenroose Mar 19, 2019
484d83c
Add new arguments
stevenroose Mar 19, 2019
04d0691
Rename con_elementswitness to con_elementsmode
stevenroose Mar 20, 2019
d53479c
[BROKEN] Introduce CA in data structures
stevenroose Mar 19, 2019
0b50661
[BROKEN] Add CA validation
stevenroose Mar 19, 2019
6493ad9
Adapt bitcoin-tx to CA
stevenroose Mar 20, 2019
703db5b
[BROKEN] Adapt existing RPCs to CA
stevenroose Mar 19, 2019
f4553d4
[BROKEN] Adapt existing benchmarks to CA
stevenroose Mar 19, 2019
cd56626
[BROKEN] Adapt existing unit tests to CA
stevenroose Mar 19, 2019
aa33202
[BROKEN] Add blinding logic
stevenroose Mar 20, 2019
6038c37
[BROKEN] Add unit test for blinding logic
stevenroose Mar 20, 2019
a03239d
[BROKEN] Add raw tx RPCs for CA
stevenroose Mar 20, 2019
49e8083
[BROKEN] Add raw issuance RPCs
stevenroose Mar 20, 2019
d3ab44d
[BROKEN] Adapt wallet to CA
stevenroose Mar 20, 2019
b6397d6
[BROKEN] Adapt wallet unit tests to CA
stevenroose Mar 20, 2019
a361dda
[BROKEN] Add CA wallet RPCs
stevenroose Mar 20, 2019
f7920d7
[BROKEN] Add issuance wallet RPCs
stevenroose Mar 20, 2019
5f9f578
[BROKEN] Unbreak Qt code after CA
stevenroose Mar 20, 2019
43f8b45
[BROKEN] Adapt bitcoin_functional tests to CA
stevenroose Mar 20, 2019
b48aea8
[BROKEN] Account for assets in all balance inspection in tests
stevenroose Feb 22, 2019
6113bf8
[BROKEN] Add fee outputs to functional tests
stevenroose Feb 27, 2019
39020cd
Adapt existing functional tests to CA
stevenroose Mar 20, 2019
96af43b
Add confidential transactions functional test
stevenroose Mar 20, 2019
a687dd9
Add assets and issuance functional tests
stevenroose Mar 20, 2019
04a8f2e
Document blindedprefix arg
instagibbs Mar 20, 2019
5c3481a
Lint RPC args
instagibbs Mar 20, 2019
f56de12
Remove all but one circular dep: coinselection <-> wallet
instagibbs Mar 20, 2019
bc9a610
Fixup wallet log print
instagibbs Mar 20, 2019
8371cfc
Fixup blind.h guard
instagibbs Mar 20, 2019
b4c9ccb
remove duplicate includes in test_bitcoin
instagibbs Mar 20, 2019
242515f
LogPrints need \n
instagibbs Mar 20, 2019
0148024
Functional test linting
instagibbs Mar 20, 2019
3055245
Spelling linter
instagibbs Mar 20, 2019
665d9eb
Whitespace and tab linting
instagibbs Mar 20, 2019
1fec77f
Add elements transaction unit test data to EXTRA_DIST
instagibbs Mar 20, 2019
7d86c7d
remove leftover asset debug printing
instagibbs Mar 20, 2019
1f062da
Fix compilation of certain builds
instagibbs Mar 20, 2019
de56cd8
move fee estimation test to extended tests, takes too long
instagibbs Mar 20, 2019
6491b4d
Use upstream Shuffle which doesn't cause DEBUG panic
instagibbs Mar 20, 2019
ac64280
Set correct ports for Liquid network params
stevenroose Mar 20, 2019
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: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ EXTRA_DIST += \
test/util/data/txcreatesignv1.hex \
test/util/data/txcreatesignv1.json \
test/util/data/txcreatesignv2.hex \
test/util/data/txcreatemultisig4_elements.hex \
test/util/data/txcreatemultisig4_elements.json \
test/util/rpcauth-test.py

CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ Translations are periodically pulled from Transifex and merged into the git repo
pull from Transifex would automatically overwrite them again.

Translators should also subscribe to the [mailing list](https://groups.google.com/forum/#!forum/bitcoin-translators).

Secure Reporting
------------------
See [our vulnerability reporting guide](SECURITY.md)
894 changes: 894 additions & 0 deletions SECURITY.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ if test "x$enable_debug" = xyes; then
# Prefer -Og, fall back to -O0 if that is unavailable.
AX_CHECK_COMPILE_FLAG(
[-Og],
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -Og"]],
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],
[AX_CHECK_COMPILE_FLAG([-O0],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])],
[[$CXXFLAG_WERROR]])

Expand Down Expand Up @@ -1459,7 +1459,7 @@ if test x$need_bundled_univalue = xyes; then
AC_CONFIG_SUBDIRS([src/univalue])
fi

ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery --disable-jni --enable-experimental --enable-module-whitelist --enable-module-rangeproof --enable-module-generator"
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --with-bignum=no --enable-module-recovery --disable-jni --enable-experimental --enable-module-whitelist --enable-module-rangeproof --enable-module-generator --enable-module-surjectionproof --enable-module-ecdh"
AC_CONFIG_SUBDIRS([src/secp256k1])

AC_OUTPUT
Expand Down
15 changes: 15 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ endif
BITCOIN_CORE_H = \
addrdb.h \
addrman.h \
asset.h \
assetsdir.h \
base58.h \
bech32.h \
blech32.h \
blind.h \
bloom.h \
blockencodings.h \
blockfilter.h \
Expand All @@ -111,6 +115,7 @@ BITCOIN_CORE_H = \
compat/endian.h \
compat/sanity.h \
compressor.h \
confidential_validation.h \
consensus/consensus.h \
consensus/tx_verify.h \
core_io.h \
Expand All @@ -126,6 +131,7 @@ BITCOIN_CORE_H = \
interfaces/handler.h \
interfaces/node.h \
interfaces/wallet.h \
issuance.h \
key.h \
key_io.h \
keystore.h \
Expand Down Expand Up @@ -223,12 +229,14 @@ libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_server_a_SOURCES = \
addrdb.cpp \
addrman.cpp \
assetsdir.cpp \
bloom.cpp \
blockencodings.cpp \
blockfilter.cpp \
block_proof.cpp \
chain.cpp \
checkpoints.cpp \
confidential_validation.cpp \
consensus/tx_verify.cpp \
httprpc.cpp \
httpserver.cpp \
Expand Down Expand Up @@ -290,6 +298,7 @@ endif
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_wallet_a_SOURCES = \
assetsdir.cpp \
interfaces/wallet.cpp \
wallet/coincontrol.cpp \
wallet/crypter.cpp \
Expand Down Expand Up @@ -358,6 +367,7 @@ libbitcoin_consensus_a_SOURCES = \
amount.h \
arith_uint256.cpp \
arith_uint256.h \
asset.cpp \
consensus/merkle.cpp \
consensus/merkle.h \
consensus/params.h \
Expand All @@ -367,6 +377,8 @@ libbitcoin_consensus_a_SOURCES = \
prevector.h \
primitives/block.cpp \
primitives/block.h \
primitives/confidential.cpp \
primitives/confidential.h \
primitives/txwitness.cpp \
primitives/txwitness.h \
primitives/transaction.cpp \
Expand Down Expand Up @@ -403,11 +415,14 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libbitcoin_common_a_SOURCES = \
base58.cpp \
bech32.cpp \
blech32.cpp \
blind.cpp \
chainparams.cpp \
coins.cpp \
compressor.cpp \
core_read.cpp \
core_write.cpp \
issuance.cpp \
key.cpp \
key_io.cpp \
keystore.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ BITCOIN_TESTS =\
test/util_tests.cpp \
test/validation_block_tests.cpp \
test/versionbits_tests.cpp \
test/pegin_spent_tests.cpp
test/pegin_spent_tests.cpp \
test/blind_tests.cpp
# ELEMENTS IN THE END

if ENABLE_PROPERTY_TESTS
Expand Down
149 changes: 149 additions & 0 deletions src/asset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@

#include <asset.h>

CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
a[it->first] += it->second;
return a;
}

CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
a[it->first] -= it->second;
return a;
}

CAmountMap operator+(const CAmountMap& a, const CAmountMap& b)
{
CAmountMap c;
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
c[it->first] += it->second;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
c[it->first] += it->second;
return c;
}

CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
{
CAmountMap c;
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
c[it->first] += it->second;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
c[it->first] -= it->second;
return c;
}

bool operator<(const CAmountMap& a, const CAmountMap& b)
{
bool smallerElement = false;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue > it->second)
return false;
if (aValue < it->second)
smallerElement = true;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second > bValue)
return false;
if (it->second < bValue)
smallerElement = true;
}
return smallerElement;
}

bool operator<=(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue > it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second > bValue)
return false;
}
return true;
}

bool operator>(const CAmountMap& a, const CAmountMap& b)
{
bool largerElement = false;
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
if (aValue < it->second)
return false;
if (aValue > it->second)
largerElement = true;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
if (it->second < bValue)
return false;
if (it->second > bValue)
largerElement = true;
}
return largerElement;
}

bool operator>=(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
if ((a.count(it->first) ? a.find(it->first)->second : 0) < it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
if (it->second < (b.count(it->first) ? b.find(it->first)->second : 0))
return false;
}
return true;
}

bool operator==(const CAmountMap& a, const CAmountMap& b)
{
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
if ((b.count(it->first) ? b.find(it->first)->second : 0) != it->second)
return false;
}
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
if ((a.count(it->first) ? a.find(it->first)->second : 0) != it->second)
return false;
}
return true;
}

bool operator!=(const CAmountMap& a, const CAmountMap& b)
{
return !(a == b);
}

bool hasNegativeValue(const CAmountMap& amount)
{
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
if (it->second < 0)
return true;
}
return false;
}

bool hasNonPostiveValue(const CAmountMap& amount)
{
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
if (it->second <= 0)
return true;
}
return false;
}

CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset) {
CAmountMap::const_iterator it = mapValue.find(asset);
if (it != mapValue.end()) {
return it->second;
} else {
return CAmount(0);
}
}
108 changes: 108 additions & 0 deletions src/asset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

#ifndef BITCOIN_ASSET_H
#define BITCOIN_ASSET_H

#include <uint256.h>

#include <amount.h>
#include <serialize.h>

/**
* Native Asset Issuance
*
* An asset identifier tag, a 256 bits serialized hash (sha256) defined
* by the issuance transaction from which the output’s coins are derived.
* Each output contains coins from a single asset/currency.
* For the host currency, the similarly-calculated hash of the chain’s genesis
* block is used instead.
**/
struct CAsset {
uint256 id;

CAsset() { }
explicit CAsset(const uint256& idIn) : id(idIn) { }
explicit CAsset(const std::vector<unsigned char>& vchIDIn) : id(vchIDIn) { }

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(id);
}

bool IsNull() const { return id.IsNull(); }
void SetNull() { id.SetNull(); }

unsigned char* begin() { return id.begin(); }
unsigned char* end() { return id.end(); }
const unsigned char* begin() const { return id.begin(); }
const unsigned char* end() const { return id.end(); }

std::string GetHex() const { return id.GetHex(); }
void SetHex(const std::string& str) { id.SetHex(str); }

friend bool operator==(const CAsset& a, const CAsset& b)
{
return a.id == b.id;
}

friend bool operator!=(const CAsset& a, const CAsset& b)
{
return !(a == b);
}

friend bool operator<(const CAsset& a, const CAsset& b)
{
return a.id < b.id;
}
};

/** Used for consensus fee and general wallet accounting*/
typedef std::map<CAsset, CAmount> CAmountMap;

CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b);
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b);

// WARNING: Comparisons are only looking for *complete* ordering.
// For strict inequality checks, if any entry would fail the non-strict
// inequality, the comparison will fail. Therefore it is possible
// that all inequality comparison checks may fail.
// Therefore if >/< fails against a CAmountMap(), this means there
// are all zeroes or one or more negative values.
//
// Examples: 1A + 2B <= 1A + 2B + 1C
// and 1A + 2B < 1A + 2B + 1C
// but
// !(1A + 2B == 1A + 2B + 1C)
//-------------------------------------
// 1A + 2B == 1A + 2B
// and 1A + 2B <= 1A + 2B
// but
// !(1A + 2B < 1A + 2B)
//-------------------------------------
// !(1A + 2B == 2B - 1C)
// !(1A + 2B >= 2B - 1C)
// ...
// !(1A + 2B < 2B - 1C)
// and 1A + 2B != 2B - 1C
bool operator<(const CAmountMap& a, const CAmountMap& b);
bool operator<=(const CAmountMap& a, const CAmountMap& b);
bool operator>(const CAmountMap& a, const CAmountMap& b);
bool operator>=(const CAmountMap& a, const CAmountMap& b);
bool operator==(const CAmountMap& a, const CAmountMap& b);
bool operator!=(const CAmountMap& a, const CAmountMap& b);

inline bool MoneyRange(const CAmountMap& mapValue) {
for(CAmountMap::const_iterator it = mapValue.begin(); it != mapValue.end(); it++) {
if (it->second < 0 || it->second > MAX_MONEY) {
return false;
}
}
return true;
}

CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset);

#endif // BITCOIN_AMOUNT_H
Loading