From bb9069555120474a53caf55027c2bdc1d4cf383c Mon Sep 17 00:00:00 2001 From: gustavonalle Date: Mon, 24 Sep 2018 16:10:23 +0100 Subject: [PATCH 01/12] [wallet] Ensure wallet is unlocked before signing Github-Pull: #14310 Rebased-From: db15805668e923c3493d77122d20926496cf6a1a --- src/wallet/rpcwallet.cpp | 2 ++ test/functional/rpc_signrawtransaction.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a3de61805..9ddd21126 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3732,6 +3732,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request) // Sign the transaction LOCK2(cs_main, pwallet->cs_wallet); + EnsureWalletIsUnlocked(pwallet); + return SignTransaction(mtx, request.params[1], pwallet, false, request.params[2]); } diff --git a/test/functional/rpc_signrawtransaction.py b/test/functional/rpc_signrawtransaction.py index 035f10e6b..823892a34 100755 --- a/test/functional/rpc_signrawtransaction.py +++ b/test/functional/rpc_signrawtransaction.py @@ -49,6 +49,14 @@ class SignRawTransactionsTest(BitcoinTestFramework): rawTxSigned2 = self.nodes[0].signrawtransaction(rawTx, inputs, privKeys) assert_equal(rawTxSigned, rawTxSigned2) + def test_with_lock_outputs(self): + """Test correct error reporting when trying to sign a locked output""" + self.nodes[0].encryptwallet("password") + self.restart_node(0) + rawTx = '020000000156b958f78e3f24e0b2f4e4db1255426b0902027cb37e3ddadb52e37c3557dddb0000000000ffffffff01c0a6b929010000001600149a2ee8c77140a053f36018ac8124a6ececc1668a00000000' + + assert_raises_rpc_error(-13, "Please enter the wallet passphrase with walletpassphrase first", self.nodes[0].signrawtransactionwithwallet, rawTx) + def script_verification_error_test(self): """Create and sign a raw transaction with valid (vin 0), invalid (vin 1) and one missing (vin 2) input script. @@ -150,6 +158,7 @@ class SignRawTransactionsTest(BitcoinTestFramework): def run_test(self): self.successful_signing_test() self.script_verification_error_test() + self.test_with_lock_outputs() if __name__ == '__main__': From 85aacc41ba3c4350faaf42582151776a47c6cf5c Mon Sep 17 00:00:00 2001 From: Walter Date: Thu, 20 Sep 2018 13:57:29 +0200 Subject: [PATCH 02/12] Add autogen.sh in ARM Cross-compilation autogen for the config files was missing. Github-Pull: #14276 Rebased-From: 52beb9ed8876e3129360197ac632c1b59f910c55 --- doc/build-unix.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/build-unix.md b/doc/build-unix.md index a01ff59fa..4a09bed2b 100644 --- a/doc/build-unix.md +++ b/doc/build-unix.md @@ -279,6 +279,7 @@ To build executables for ARM: cd depends make HOST=arm-linux-gnueabihf NO_QT=1 cd .. + ./autogen.sh ./configure --prefix=$PWD/depends/arm-linux-gnueabihf --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++ make From 94065024c7ad049a3750102d8cdccf9d1ac73ee4 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 7 Nov 2018 12:36:23 -0800 Subject: [PATCH 03/12] add a test demonstrating an overflow in a deserialization edge case Also add a test that the highest legal index is accepted. Github-Pull: #14685 Rebased-From: 051faf7e9d4e32142f95f7adb31d2f53f656cb66 --- src/test/blockencodings_tests.cpp | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index d2c7c8cb1..df62c5ac9 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -344,4 +344,49 @@ BOOST_AUTO_TEST_CASE(TransactionsRequestSerializationTest) { BOOST_CHECK_EQUAL(req1.indexes[3], req2.indexes[3]); } +BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationMaxTest) { + // Check that the highest legal index is decoded correctly + BlockTransactionsRequest req0; + req0.blockhash = InsecureRand256(); + req0.indexes.resize(1); + req0.indexes[0] = 0xffff; + CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); + stream << req0; + + BlockTransactionsRequest req1; + stream >> req1; + BOOST_CHECK_EQUAL(req0.indexes.size(), req1.indexes.size()); + BOOST_CHECK_EQUAL(req0.indexes[0], req1.indexes[0]); +} + +BOOST_AUTO_TEST_CASE(TransactionsRequestDeserializationOverflowTest) { + // Any set of index deltas that starts with N values that sum to (0x10000 - N) + // causes the edge-case overflow that was originally not checked for. Such + // a request cannot be created by serializing a real BlockTransactionsRequest + // due to the overflow, so here we'll serialize from raw deltas. + BlockTransactionsRequest req0; + req0.blockhash = InsecureRand256(); + req0.indexes.resize(3); + req0.indexes[0] = 0x7000; + req0.indexes[1] = 0x10000 - 0x7000 - 2; + req0.indexes[2] = 0; + CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); + stream << req0.blockhash; + WriteCompactSize(stream, req0.indexes.size()); + WriteCompactSize(stream, req0.indexes[0]); + WriteCompactSize(stream, req0.indexes[1]); + WriteCompactSize(stream, req0.indexes[2]); + + BlockTransactionsRequest req1; + try { + stream >> req1; + // before patch: deserialize above succeeds and this check fails, demonstrating the overflow + BOOST_CHECK(req1.indexes[1] < req1.indexes[2]); + // this shouldn't be reachable before or after patch + BOOST_CHECK(0); + } catch(std::ios_base::failure &) { + // deserialize should fail + } +} + BOOST_AUTO_TEST_SUITE_END() From 5331ad0506fa1e13a70613309532588b2cc74bb5 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 7 Nov 2018 12:39:44 -0800 Subject: [PATCH 04/12] fix a deserialization overflow edge case A specially-constructed BlockTransactionsRequest can overflow in deserialization in a way that is currently harmless. Github-Pull: #14685 Rebased-From: 6bed4b374daf26233e96fa7863d4324a5bfa99c2 --- src/blockencodings.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/blockencodings.h b/src/blockencodings.h index fad1f56f5..4bfe53825 100644 --- a/src/blockencodings.h +++ b/src/blockencodings.h @@ -52,12 +52,12 @@ public: } } - uint16_t offset = 0; + int32_t offset = 0; for (size_t j = 0; j < indexes.size(); j++) { - if (uint64_t(indexes[j]) + uint64_t(offset) > std::numeric_limits::max()) + if (int32_t(indexes[j]) + offset > std::numeric_limits::max()) throw std::ios_base::failure("indexes overflowed 16 bits"); indexes[j] = indexes[j] + offset; - offset = indexes[j] + 1; + offset = int32_t(indexes[j]) + 1; } } else { for (size_t i = 0; i < indexes.size(); i++) { From 2f9fd2932164eb86005e91cffcc66d2d79322db0 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 13 Nov 2018 12:40:22 -0800 Subject: [PATCH 05/12] disallow oversized CBlockHeaderAndShortTxIDs Otherwise we'd reply with a bogus BlockTransactionsRequest trying to request indexes with overflowed deltas. Github-Pull: #14685 Rebased-From: b08af10fb299dc3fdcd1f022619fb112c72e5d8e --- src/blockencodings.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/blockencodings.h b/src/blockencodings.h index 4bfe53825..0c2b83ebc 100644 --- a/src/blockencodings.h +++ b/src/blockencodings.h @@ -186,6 +186,9 @@ public: READWRITE(prefilledtxn); + if (BlockTxCount() > std::numeric_limits::max()) + throw std::ios_base::failure("indexes overflowed 16 bits"); + if (ser_action.ForRead()) FillShortTxIDSelector(); } From 60f7a97930ccec01d008036cb98f1304eeca7525 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 21 Oct 2018 23:36:23 -0400 Subject: [PATCH 06/12] qa: Add test to ensure node can generate all help texts at runtime Github-Pull: #14658 Rebased-From: bbbbb3f8850907d413db4715c10ef6df055234f6 --- test/functional/rpc_help.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/functional/rpc_help.py b/test/functional/rpc_help.py index be096af89..78d6e78ae 100755 --- a/test/functional/rpc_help.py +++ b/test/functional/rpc_help.py @@ -7,12 +7,18 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error +import os + class HelpRpcTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 def run_test(self): + self.test_categories() + self.dump_help() + + def test_categories(self): node = self.nodes[0] # wrong argument count @@ -37,6 +43,15 @@ class HelpRpcTest(BitcoinTestFramework): assert_equal(titles, components) + def dump_help(self): + dump_dir = os.path.join(self.options.tmpdir, 'rpc_help_dump') + os.mkdir(dump_dir) + calls = [line.split(' ', 1)[0] for line in self.nodes[0].help().splitlines() if line and not line.startswith('==')] + for call in calls: + with open(os.path.join(dump_dir, call), 'w', encoding='utf-8') as f: + # Make sure the node can generate the help at runtime without crashing + f.write(self.nodes[0].help(call)) + if __name__ == '__main__': HelpRpcTest().main() From 96f15e8bb3ca92d61030074c5499d07d8f89a92c Mon Sep 17 00:00:00 2001 From: fridokus Date: Thu, 1 Nov 2018 16:11:29 +0100 Subject: [PATCH 07/12] Tests: Fix a comment Github-Pull: #14632 Rebased-From: 086fc835718555bb332a807fe5794cb6cb4d1fef --- test/functional/mempool_resurrect.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/functional/mempool_resurrect.py b/test/functional/mempool_resurrect.py index d035ca907..845beb551 100755 --- a/test/functional/mempool_resurrect.py +++ b/test/functional/mempool_resurrect.py @@ -47,12 +47,11 @@ class MempoolCoinbaseTest(BitcoinTestFramework): tx = self.nodes[0].gettransaction(txid) assert(tx["confirmations"] > 0) - # Use invalidateblock to re-org back; all transactions should - # end up unconfirmed and back in the mempool + # Use invalidateblock to re-org back for node in self.nodes: node.invalidateblock(blocks[0]) - # mempool should be empty, all txns confirmed + # All txns should be back in mempool with 0 confirmations assert_equal(set(self.nodes[0].getrawmempool()), set(spends1_id+spends2_id)) for txid in spends1_id+spends2_id: tx = self.nodes[0].gettransaction(txid) From 91fa15aaebdf99fb0d1e2d811f765a5dd3fc3a93 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 27 Jun 2018 18:06:44 +0200 Subject: [PATCH 08/12] wallet: Avoid potential use of unitialized value bnb_used in CWallet::CreateTransaction(...) Github-Pull: #13546 Rebased-From: a23a7f60aa07de52d23ff1f2034fc43926ec3520 --- src/wallet/wallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5a7fdf9a8..1a14d7af0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2846,6 +2846,8 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac return false; } } + } else { + bnb_used = false; } const CAmount nChange = nValueIn - nValueToSelect; From fb9ad043f8b82c7d507ee729121658073eb894f8 Mon Sep 17 00:00:00 2001 From: Eric Scrivner Date: Sat, 6 Oct 2018 10:11:38 -0700 Subject: [PATCH 09/12] Fix listreceivedbyaddress not taking address as a string Fixes #14173. Add the patch in #14173 and include a regression test. Github-Pull: #14417 Rebased-From: d4d70eda339f6f74390b56edd4021e928bb588a7 --- src/rpc/client.cpp | 1 - test/functional/wallet_listreceivedby.py | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index c7f3e38ac..9fa042016 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -45,7 +45,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listreceivedbyaddress", 0, "minconf" }, { "listreceivedbyaddress", 1, "include_empty" }, { "listreceivedbyaddress", 2, "include_watchonly" }, - { "listreceivedbyaddress", 3, "address_filter" }, { "listreceivedbyaccount", 0, "minconf" }, { "listreceivedbyaccount", 1, "include_empty" }, { "listreceivedbyaccount", 2, "include_watchonly" }, diff --git a/test/functional/wallet_listreceivedby.py b/test/functional/wallet_listreceivedby.py index 3485c4470..9e8667c60 100755 --- a/test/functional/wallet_listreceivedby.py +++ b/test/functional/wallet_listreceivedby.py @@ -68,6 +68,10 @@ class ReceivedByTest(BitcoinTestFramework): res = self.nodes[1].listreceivedbyaddress(minconf=0, include_empty=True, include_watchonly=True, address_filter=addr) assert_array_result(res, {"address": addr}, expected) assert_equal(len(res), 1) + # Test for regression on CLI calls with address string (#14173) + cli_res = self.nodes[1].cli.listreceivedbyaddress(0, True, True, addr) + assert_array_result(cli_res, {"address": addr}, expected) + assert_equal(len(cli_res), 1) # Error on invalid address assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, include_empty=True, include_watchonly=True, address_filter="bamboozling") # Another address receive money From 7edebedef10457dfc3062f52b180c91f332d69f0 Mon Sep 17 00:00:00 2001 From: Jon Layton Date: Sat, 3 Nov 2018 05:03:50 -0500 Subject: [PATCH 10/12] build: Remove illegal spacing in darwin.mk Github-Pull: #14647 Rebased-From: 63c74d2d3abcb685c773c3ad1414da6ad062a55d --- depends/builders/darwin.mk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index 27f550ab0..c7671c154 100644 --- a/depends/builders/darwin.mk +++ b/depends/builders/darwin.mk @@ -1,13 +1,13 @@ -build_darwin_CC: = $(shell xcrun -f clang) -build_darwin_CXX: = $(shell xcrun -f clang++) -build_darwin_AR: = $(shell xcrun -f ar) -build_darwin_RANLIB: = $(shell xcrun -f ranlib) -build_darwin_STRIP: = $(shell xcrun -f strip) -build_darwin_OTOOL: = $(shell xcrun -f otool) -build_darwin_NM: = $(shell xcrun -f nm) +build_darwin_CC:=$(shell xcrun -f clang) +build_darwin_CXX:=$(shell xcrun -f clang++) +build_darwin_AR:=$(shell xcrun -f ar) +build_darwin_RANLIB:=$(shell xcrun -f ranlib) +build_darwin_STRIP:=$(shell xcrun -f strip) +build_darwin_OTOOL:=$(shell xcrun -f otool) +build_darwin_NM:=$(shell xcrun -f nm) build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) -build_darwin_SHA256SUM = shasum -a 256 -build_darwin_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o +build_darwin_SHA256SUM=shasum -a 256 +build_darwin_DOWNLOAD=curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o #darwin host on darwin builder. overrides darwin host preferences. darwin_CC=$(shell xcrun -f clang) -mmacosx-version-min=$(OSX_MIN_VERSION) From ec71f06a8d8f3d476542880673c6814e3311c9fe Mon Sep 17 00:00:00 2001 From: Chun Kuan Lee Date: Fri, 9 Nov 2018 21:57:13 +0800 Subject: [PATCH 11/12] build: Add bitcoin-tx.exe into Windows installer Github-Pull: #14698 Rebased-From: 5c5902acc515c8f46ad73222cd57a29c4c13b92c --- Makefile.am | 5 +++++ share/setup.nsi.in | 1 + 2 files changed, 6 insertions(+) diff --git a/Makefile.am b/Makefile.am index 10dda65b2..8972c47f4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,7 @@ endif BITCOIND_BIN=$(top_builddir)/src/$(BITCOIN_DAEMON_NAME)$(EXEEXT) BITCOIN_QT_BIN=$(top_builddir)/src/qt/$(BITCOIN_GUI_NAME)$(EXEEXT) BITCOIN_CLI_BIN=$(top_builddir)/src/$(BITCOIN_CLI_NAME)$(EXEEXT) +BITCOIN_TX_BIN=$(top_builddir)/src/$(BITCOIN_TX_NAME)$(EXEEXT) BITCOIN_WIN_INSTALLER=$(PACKAGE)-$(PACKAGE_VERSION)-win$(WINDOWS_BITS)-setup$(EXEEXT) empty := @@ -74,6 +75,7 @@ $(BITCOIN_WIN_INSTALLER): all-recursive STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIND_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_QT_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_CLI_BIN) $(top_builddir)/release + STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_TX_BIN) $(top_builddir)/release @test -f $(MAKENSIS) && $(MAKENSIS) -V2 $(top_builddir)/share/setup.nsi || \ echo error: could not build $@ @echo built $@ @@ -167,6 +169,9 @@ $(BITCOIND_BIN): FORCE $(BITCOIN_CLI_BIN): FORCE $(MAKE) -C src $(@F) +$(BITCOIN_TX_BIN): FORCE + $(MAKE) -C src $(@F) + if USE_LCOV LCOV_FILTER_PATTERN=-p "/usr/include/" -p "src/leveldb/" -p "src/bench/" -p "src/univalue" -p "src/crypto/ctaes" -p "src/secp256k1" diff --git a/share/setup.nsi.in b/share/setup.nsi.in index b58a84e02..6542370f9 100644 --- a/share/setup.nsi.in +++ b/share/setup.nsi.in @@ -80,6 +80,7 @@ Section -Main SEC0000 SetOutPath $INSTDIR\daemon File @abs_top_srcdir@/release/@BITCOIN_DAEMON_NAME@@EXEEXT@ File @abs_top_srcdir@/release/@BITCOIN_CLI_NAME@@EXEEXT@ + File @abs_top_srcdir@/release/@BITCOIN_TX_NAME@@EXEEXT@ SetOutPath $INSTDIR\doc File /r /x Makefile* @abs_top_srcdir@/doc\*.* SetOutPath $INSTDIR From 542651cfb408d10e6eaaa24ad985c95e51f88f75 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Tue, 20 Nov 2018 18:31:18 -0500 Subject: [PATCH 12/12] travis: Remove deprecated sudo --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1772e43e..91b5af0f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: required dist: trusty os: linux language: minimal @@ -143,7 +142,6 @@ jobs: BITCOIN_CONFIG="--enable-gui --enable-reduce-exports --enable-werror" - stage: lint env: - sudo: false cache: false language: python python: '3.6'