Skip to content

Commit e9f6e82

Browse files
committed
Merge #515: [0.17] Cleaned up CA
ac64280 Set correct ports for Liquid network params (Steven Roose) 6491b4d Use upstream Shuffle which doesn't cause DEBUG panic (Gregory Sanders) de56cd8 move fee estimation test to extended tests, takes too long (Gregory Sanders) 1f062da Fix compilation of certain builds (Gregory Sanders) 7d86c7d remove leftover asset debug printing (Gregory Sanders) 1fec77f Add elements transaction unit test data to EXTRA_DIST (Gregory Sanders) 665d9eb Whitespace and tab linting (Gregory Sanders) 3055245 Spelling linter (Gregory Sanders) 0148024 Functional test linting (Gregory Sanders) 242515f LogPrints need \n (Gregory Sanders) b4c9ccb remove duplicate includes in test_bitcoin (Gregory Sanders) 8371cfc Fixup blind.h guard (Gregory Sanders) bc9a610 Fixup wallet log print (Gregory Sanders) f56de12 Remove all but one circular dep: coinselection <-> wallet (Gregory Sanders) 5c3481a Lint RPC args (Gregory Sanders) 04a8f2e Document blindedprefix arg (Gregory Sanders) a687dd9 Add assets and issuance functional tests (Steven Roose) 96af43b Add confidential transactions functional test (Steven Roose) 39020cd Adapt existing functional tests to CA (Steven Roose) 6113bf8 [BROKEN] Add fee outputs to functional tests (Steven Roose) b48aea8 [BROKEN] Account for assets in all balance inspection in tests (Steven Roose) 43f8b45 [BROKEN] Adapt bitcoin_functional tests to CA (Steven Roose) 5f9f578 [BROKEN] Unbreak Qt code after CA (Steven Roose) f7920d7 [BROKEN] Add issuance wallet RPCs (Steven Roose) a361dda [BROKEN] Add CA wallet RPCs (Steven Roose) b6397d6 [BROKEN] Adapt wallet unit tests to CA (Steven Roose) d3ab44d [BROKEN] Adapt wallet to CA (Steven Roose) 49e8083 [BROKEN] Add raw issuance RPCs (Steven Roose) a03239d [BROKEN] Add raw tx RPCs for CA (Steven Roose) 6038c37 [BROKEN] Add unit test for blinding logic (Steven Roose) aa33202 [BROKEN] Add blinding logic (Steven Roose) cd56626 [BROKEN] Adapt existing unit tests to CA (Steven Roose) f4553d4 [BROKEN] Adapt existing benchmarks to CA (Steven Roose) 703db5b [BROKEN] Adapt existing RPCs to CA (Steven Roose) 6493ad9 Adapt bitcoin-tx to CA (Steven Roose) 0b50661 [BROKEN] Add CA validation (Steven Roose) d53479c [BROKEN] Introduce CA in data structures (Steven Roose) 04d0691 Rename con_elementswitness to con_elementsmode (Steven Roose) 484d83c Add new arguments (Steven Roose) fde9fe1 Add basic issuance boilerplate (Steven Roose) f81122f Add asset and value blinding functionality (Steven Roose) 8b8256d Add ConfidentialCommitment-based types (Steven Roose) d0322f7 Add initial issuance boilerplate (Steven Roose) fd411bb Enable surjection proof module in secp256k1-zkp (Steven Roose) 84954c8 Add CAssetsDir (Steven Roose) 10773c6 Add CAsset and CAmountMap (Steven Roose) 14af0b6 Implement blech32 addresses, expose over RPC (Gregory Sanders) 0f28780 Add blech32 implementation and API (Steven Roose) 9cb2fa0 Add blech32 python implementation with diff annotation with segwit_addr.py (Gregory Sanders) 17a22f1 Add support for blinded addresses (Steven Roose) 00fba77 Add liquidv1 chainparams (Gregory Sanders) 045e615 Add CKey::ECDH (Steven Roose) aa375e6 Replace CScriptID and CKeyID in CTxDestination with dedicated type (Gregory Sanders) 3e7cff1 Disable tests that are not relevant for Elements (Steven Roose) 3a0b3b7 Add tweakfedpeg and compatbility test (Gregory Sanders) 36a5d5d Fix bug in calculate_contract for Liquid (Steven Roose) 77ba5ee RPC params convertion cleanup (Steven Roose) ce19a5f Add secure reporting document, link in README (Gregory Sanders) Pull request description: Cleaned up version of #503. Tree-SHA512: fb82a182a49384dd4be5838c147f6049f3b554f6d861681df46d83819c39c460b469cb68a8f6c47a2e8d3c17e439fea8818f8bca03b200027e6a127875376892
2 parents 658dae0 + ac64280 commit e9f6e82

File tree

198 files changed

+11646
-1928
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+11646
-1928
lines changed

Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ EXTRA_DIST += \
269269
test/util/data/txcreatesignv1.hex \
270270
test/util/data/txcreatesignv1.json \
271271
test/util/data/txcreatesignv2.hex \
272+
test/util/data/txcreatemultisig4_elements.hex \
273+
test/util/data/txcreatemultisig4_elements.json \
272274
test/util/rpcauth-test.py
273275

274276
CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER)

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ Translations are periodically pulled from Transifex and merged into the git repo
7474
pull from Transifex would automatically overwrite them again.
7575

7676
Translators should also subscribe to the [mailing list](https://groups.google.com/forum/#!forum/bitcoin-translators).
77+
78+
Secure Reporting
79+
------------------
80+
See [our vulnerability reporting guide](SECURITY.md)

SECURITY.md

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ if test "x$enable_debug" = xyes; then
256256
# Prefer -Og, fall back to -O0 if that is unavailable.
257257
AX_CHECK_COMPILE_FLAG(
258258
[-Og],
259-
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -Og"]],
259+
[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],
260260
[AX_CHECK_COMPILE_FLAG([-O0],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])],
261261
[[$CXXFLAG_WERROR]])
262262

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

1462-
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"
1462+
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"
14631463
AC_CONFIG_SUBDIRS([src/secp256k1])
14641464

14651465
AC_OUTPUT

src/Makefile.am

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ endif
9292
BITCOIN_CORE_H = \
9393
addrdb.h \
9494
addrman.h \
95+
asset.h \
96+
assetsdir.h \
9597
base58.h \
9698
bech32.h \
99+
blech32.h \
100+
blind.h \
97101
bloom.h \
98102
blockencodings.h \
99103
blockfilter.h \
@@ -111,6 +115,7 @@ BITCOIN_CORE_H = \
111115
compat/endian.h \
112116
compat/sanity.h \
113117
compressor.h \
118+
confidential_validation.h \
114119
consensus/consensus.h \
115120
consensus/tx_verify.h \
116121
core_io.h \
@@ -126,6 +131,7 @@ BITCOIN_CORE_H = \
126131
interfaces/handler.h \
127132
interfaces/node.h \
128133
interfaces/wallet.h \
134+
issuance.h \
129135
key.h \
130136
key_io.h \
131137
keystore.h \
@@ -223,12 +229,14 @@ libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
223229
libbitcoin_server_a_SOURCES = \
224230
addrdb.cpp \
225231
addrman.cpp \
232+
assetsdir.cpp \
226233
bloom.cpp \
227234
blockencodings.cpp \
228235
blockfilter.cpp \
229236
block_proof.cpp \
230237
chain.cpp \
231238
checkpoints.cpp \
239+
confidential_validation.cpp \
232240
consensus/tx_verify.cpp \
233241
httprpc.cpp \
234242
httpserver.cpp \
@@ -290,6 +298,7 @@ endif
290298
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
291299
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
292300
libbitcoin_wallet_a_SOURCES = \
301+
assetsdir.cpp \
293302
interfaces/wallet.cpp \
294303
wallet/coincontrol.cpp \
295304
wallet/crypter.cpp \
@@ -358,6 +367,7 @@ libbitcoin_consensus_a_SOURCES = \
358367
amount.h \
359368
arith_uint256.cpp \
360369
arith_uint256.h \
370+
asset.cpp \
361371
consensus/merkle.cpp \
362372
consensus/merkle.h \
363373
consensus/params.h \
@@ -367,6 +377,8 @@ libbitcoin_consensus_a_SOURCES = \
367377
prevector.h \
368378
primitives/block.cpp \
369379
primitives/block.h \
380+
primitives/confidential.cpp \
381+
primitives/confidential.h \
370382
primitives/txwitness.cpp \
371383
primitives/txwitness.h \
372384
primitives/transaction.cpp \
@@ -403,11 +415,14 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
403415
libbitcoin_common_a_SOURCES = \
404416
base58.cpp \
405417
bech32.cpp \
418+
blech32.cpp \
419+
blind.cpp \
406420
chainparams.cpp \
407421
coins.cpp \
408422
compressor.cpp \
409423
core_read.cpp \
410424
core_write.cpp \
425+
issuance.cpp \
411426
key.cpp \
412427
key_io.cpp \
413428
keystore.cpp \

src/Makefile.test.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ BITCOIN_TESTS =\
9696
test/util_tests.cpp \
9797
test/validation_block_tests.cpp \
9898
test/versionbits_tests.cpp \
99-
test/pegin_spent_tests.cpp
99+
test/pegin_spent_tests.cpp \
100+
test/blind_tests.cpp
100101
# ELEMENTS IN THE END
101102

102103
if ENABLE_PROPERTY_TESTS

src/asset.cpp

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
#include <asset.h>
3+
4+
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b)
5+
{
6+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
7+
a[it->first] += it->second;
8+
return a;
9+
}
10+
11+
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b)
12+
{
13+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
14+
a[it->first] -= it->second;
15+
return a;
16+
}
17+
18+
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b)
19+
{
20+
CAmountMap c;
21+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
22+
c[it->first] += it->second;
23+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
24+
c[it->first] += it->second;
25+
return c;
26+
}
27+
28+
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b)
29+
{
30+
CAmountMap c;
31+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it)
32+
c[it->first] += it->second;
33+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it)
34+
c[it->first] -= it->second;
35+
return c;
36+
}
37+
38+
bool operator<(const CAmountMap& a, const CAmountMap& b)
39+
{
40+
bool smallerElement = false;
41+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
42+
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
43+
if (aValue > it->second)
44+
return false;
45+
if (aValue < it->second)
46+
smallerElement = true;
47+
}
48+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
49+
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
50+
if (it->second > bValue)
51+
return false;
52+
if (it->second < bValue)
53+
smallerElement = true;
54+
}
55+
return smallerElement;
56+
}
57+
58+
bool operator<=(const CAmountMap& a, const CAmountMap& b)
59+
{
60+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
61+
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
62+
if (aValue > it->second)
63+
return false;
64+
}
65+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
66+
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
67+
if (it->second > bValue)
68+
return false;
69+
}
70+
return true;
71+
}
72+
73+
bool operator>(const CAmountMap& a, const CAmountMap& b)
74+
{
75+
bool largerElement = false;
76+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
77+
CAmount aValue = a.count(it->first) ? a.find(it->first)->second : 0;
78+
if (aValue < it->second)
79+
return false;
80+
if (aValue > it->second)
81+
largerElement = true;
82+
}
83+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
84+
CAmount bValue = b.count(it->first) ? b.find(it->first)->second : 0;
85+
if (it->second < bValue)
86+
return false;
87+
if (it->second > bValue)
88+
largerElement = true;
89+
}
90+
return largerElement;
91+
}
92+
93+
bool operator>=(const CAmountMap& a, const CAmountMap& b)
94+
{
95+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
96+
if ((a.count(it->first) ? a.find(it->first)->second : 0) < it->second)
97+
return false;
98+
}
99+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
100+
if (it->second < (b.count(it->first) ? b.find(it->first)->second : 0))
101+
return false;
102+
}
103+
return true;
104+
}
105+
106+
bool operator==(const CAmountMap& a, const CAmountMap& b)
107+
{
108+
for(std::map<CAsset, CAmount>::const_iterator it = a.begin(); it != a.end(); ++it) {
109+
if ((b.count(it->first) ? b.find(it->first)->second : 0) != it->second)
110+
return false;
111+
}
112+
for(std::map<CAsset, CAmount>::const_iterator it = b.begin(); it != b.end(); ++it) {
113+
if ((a.count(it->first) ? a.find(it->first)->second : 0) != it->second)
114+
return false;
115+
}
116+
return true;
117+
}
118+
119+
bool operator!=(const CAmountMap& a, const CAmountMap& b)
120+
{
121+
return !(a == b);
122+
}
123+
124+
bool hasNegativeValue(const CAmountMap& amount)
125+
{
126+
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
127+
if (it->second < 0)
128+
return true;
129+
}
130+
return false;
131+
}
132+
133+
bool hasNonPostiveValue(const CAmountMap& amount)
134+
{
135+
for(std::map<CAsset, CAmount>::const_iterator it = amount.begin(); it != amount.end(); ++it) {
136+
if (it->second <= 0)
137+
return true;
138+
}
139+
return false;
140+
}
141+
142+
CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset) {
143+
CAmountMap::const_iterator it = mapValue.find(asset);
144+
if (it != mapValue.end()) {
145+
return it->second;
146+
} else {
147+
return CAmount(0);
148+
}
149+
}

src/asset.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
#ifndef BITCOIN_ASSET_H
3+
#define BITCOIN_ASSET_H
4+
5+
#include <uint256.h>
6+
7+
#include <amount.h>
8+
#include <serialize.h>
9+
10+
/**
11+
* Native Asset Issuance
12+
*
13+
* An asset identifier tag, a 256 bits serialized hash (sha256) defined
14+
* by the issuance transaction from which the output’s coins are derived.
15+
* Each output contains coins from a single asset/currency.
16+
* For the host currency, the similarly-calculated hash of the chain’s genesis
17+
* block is used instead.
18+
**/
19+
struct CAsset {
20+
uint256 id;
21+
22+
CAsset() { }
23+
explicit CAsset(const uint256& idIn) : id(idIn) { }
24+
explicit CAsset(const std::vector<unsigned char>& vchIDIn) : id(vchIDIn) { }
25+
26+
ADD_SERIALIZE_METHODS;
27+
28+
template <typename Stream, typename Operation>
29+
inline void SerializationOp(Stream& s, Operation ser_action) {
30+
READWRITE(id);
31+
}
32+
33+
bool IsNull() const { return id.IsNull(); }
34+
void SetNull() { id.SetNull(); }
35+
36+
unsigned char* begin() { return id.begin(); }
37+
unsigned char* end() { return id.end(); }
38+
const unsigned char* begin() const { return id.begin(); }
39+
const unsigned char* end() const { return id.end(); }
40+
41+
std::string GetHex() const { return id.GetHex(); }
42+
void SetHex(const std::string& str) { id.SetHex(str); }
43+
44+
friend bool operator==(const CAsset& a, const CAsset& b)
45+
{
46+
return a.id == b.id;
47+
}
48+
49+
friend bool operator!=(const CAsset& a, const CAsset& b)
50+
{
51+
return !(a == b);
52+
}
53+
54+
friend bool operator<(const CAsset& a, const CAsset& b)
55+
{
56+
return a.id < b.id;
57+
}
58+
};
59+
60+
/** Used for consensus fee and general wallet accounting*/
61+
typedef std::map<CAsset, CAmount> CAmountMap;
62+
63+
CAmountMap& operator+=(CAmountMap& a, const CAmountMap& b);
64+
CAmountMap& operator-=(CAmountMap& a, const CAmountMap& b);
65+
CAmountMap operator+(const CAmountMap& a, const CAmountMap& b);
66+
CAmountMap operator-(const CAmountMap& a, const CAmountMap& b);
67+
68+
// WARNING: Comparisons are only looking for *complete* ordering.
69+
// For strict inequality checks, if any entry would fail the non-strict
70+
// inequality, the comparison will fail. Therefore it is possible
71+
// that all inequality comparison checks may fail.
72+
// Therefore if >/< fails against a CAmountMap(), this means there
73+
// are all zeroes or one or more negative values.
74+
//
75+
// Examples: 1A + 2B <= 1A + 2B + 1C
76+
// and 1A + 2B < 1A + 2B + 1C
77+
// but
78+
// !(1A + 2B == 1A + 2B + 1C)
79+
//-------------------------------------
80+
// 1A + 2B == 1A + 2B
81+
// and 1A + 2B <= 1A + 2B
82+
// but
83+
// !(1A + 2B < 1A + 2B)
84+
//-------------------------------------
85+
// !(1A + 2B == 2B - 1C)
86+
// !(1A + 2B >= 2B - 1C)
87+
// ...
88+
// !(1A + 2B < 2B - 1C)
89+
// and 1A + 2B != 2B - 1C
90+
bool operator<(const CAmountMap& a, const CAmountMap& b);
91+
bool operator<=(const CAmountMap& a, const CAmountMap& b);
92+
bool operator>(const CAmountMap& a, const CAmountMap& b);
93+
bool operator>=(const CAmountMap& a, const CAmountMap& b);
94+
bool operator==(const CAmountMap& a, const CAmountMap& b);
95+
bool operator!=(const CAmountMap& a, const CAmountMap& b);
96+
97+
inline bool MoneyRange(const CAmountMap& mapValue) {
98+
for(CAmountMap::const_iterator it = mapValue.begin(); it != mapValue.end(); it++) {
99+
if (it->second < 0 || it->second > MAX_MONEY) {
100+
return false;
101+
}
102+
}
103+
return true;
104+
}
105+
106+
CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset);
107+
108+
#endif // BITCOIN_AMOUNT_H

0 commit comments

Comments
 (0)