diff -Nru bitcoinabc-0.21.11/cmake/modules/InstallationHelper.cmake bitcoinabc-0.21.12/cmake/modules/InstallationHelper.cmake --- bitcoinabc-0.21.11/cmake/modules/InstallationHelper.cmake 2020-05-04 17:57:49.000000000 +0000 +++ bitcoinabc-0.21.12/cmake/modules/InstallationHelper.cmake 2020-07-17 16:19:01.000000000 +0000 @@ -8,15 +8,19 @@ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${PROJECT_NAME} + ${ARGN} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT ${PROJECT_NAME} + ${ARGN} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT ${PROJECT_NAME} + ${ARGN} PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT ${PROJECT_NAME} + ${ARGN} ) endfunction() diff -Nru bitcoinabc-0.21.11/cmake/modules/TestSuite.cmake bitcoinabc-0.21.12/cmake/modules/TestSuite.cmake --- bitcoinabc-0.21.11/cmake/modules/TestSuite.cmake 2020-07-07 17:16:37.000000000 +0000 +++ bitcoinabc-0.21.12/cmake/modules/TestSuite.cmake 2020-07-28 23:45:00.000000000 +0000 @@ -59,7 +59,7 @@ add_test_custom_target(${TARGET} TEST_COMMAND "${CMAKE_SOURCE_DIR}/cmake/utils/test_wrapper.sh" - "${NAME}.log" + "${SUITE}-${NAME}.log" ${CMAKE_CROSSCOMPILING_EMULATOR} "$" ${ARGN} CUSTOM_TARGET_ARGS COMMENT "${SUITE}: testing ${NAME}" diff -Nru bitcoinabc-0.21.11/CMakeLists.txt bitcoinabc-0.21.12/CMakeLists.txt --- bitcoinabc-0.21.11/CMakeLists.txt 2020-07-14 16:56:53.000000000 +0000 +++ bitcoinabc-0.21.12/CMakeLists.txt 2020-07-28 23:45:00.000000000 +0000 @@ -7,7 +7,7 @@ ) project(bitcoin-abc - VERSION 0.21.11 + VERSION 0.21.12 DESCRIPTION "Bitcoin ABC is a full node implementation of the Bitcoin Cash protocol." HOMEPAGE_URL "https://www.bitcoinabc.org" ) diff -Nru bitcoinabc-0.21.11/configure.ac bitcoinabc-0.21.12/configure.ac --- bitcoinabc-0.21.11/configure.ac 2020-07-14 16:56:53.000000000 +0000 +++ bitcoinabc-0.21.12/configure.ac 2020-07-28 23:45:00.000000000 +0000 @@ -2,7 +2,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 21) -define(_CLIENT_VERSION_REVISION, 11) +define(_CLIENT_VERSION_REVISION, 12) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2020) define(_COPYRIGHT_HOLDERS,[The %s developers]) diff -Nru bitcoinabc-0.21.11/contrib/CMakeLists.txt bitcoinabc-0.21.12/contrib/CMakeLists.txt --- bitcoinabc-0.21.11/contrib/CMakeLists.txt 2020-05-04 17:57:49.000000000 +0000 +++ bitcoinabc-0.21.12/contrib/CMakeLists.txt 2020-07-20 23:11:19.000000000 +0000 @@ -10,6 +10,7 @@ # Subdirectories "debian/" "gitian/" + "gitian-builder/" "gitian-descriptors/" "qos/" "seeds/" diff -Nru bitcoinabc-0.21.11/contrib/devtools/chainparams/chainparams_main.txt bitcoinabc-0.21.12/contrib/devtools/chainparams/chainparams_main.txt --- bitcoinabc-0.21.11/contrib/devtools/chainparams/chainparams_main.txt 2020-07-09 15:34:59.000000000 +0000 +++ bitcoinabc-0.21.12/contrib/devtools/chainparams/chainparams_main.txt 2020-07-27 15:24:34.000000000 +0000 @@ -1,4 +1,4 @@ -0000000000000000013add16221ff595c977de1027c8c3f962acf8fcdfa05065 -0000000000000000000000000000000000000000013b3489eb103468fa735866 -204 +000000000000000001831f2498ccf63ab3153bf6046362513832a0ac8008c16e +0000000000000000000000000000000000000000013e03edc46165e17570aac7 +205 3 diff -Nru bitcoinabc-0.21.11/contrib/devtools/chainparams/chainparams_test.txt bitcoinabc-0.21.12/contrib/devtools/chainparams/chainparams_test.txt --- bitcoinabc-0.21.11/contrib/devtools/chainparams/chainparams_test.txt 2020-07-09 15:34:59.000000000 +0000 +++ bitcoinabc-0.21.12/contrib/devtools/chainparams/chainparams_test.txt 2020-07-27 15:24:34.000000000 +0000 @@ -1,4 +1,4 @@ -0000000000190c28546af514f5255d8afae5c5f756e191e9b8e9724a1e256e61 -0000000000000000000000000000000000000000000000682bd38e9265377ec0 +0000000031bedd3009e21403ad61614af5237093f8a794c7c7c1dd5d312fc61e +00000000000000000000000000000000000000000000006983387157261b3275 55 2 diff -Nru bitcoinabc-0.21.11/contrib/devtools/symbol-check.py bitcoinabc-0.21.12/contrib/devtools/symbol-check.py --- bitcoinabc-0.21.11/contrib/devtools/symbol-check.py 2020-06-08 20:54:42.000000000 +0000 +++ bitcoinabc-0.21.12/contrib/devtools/symbol-check.py 2020-07-20 23:11:19.000000000 +0000 @@ -9,7 +9,7 @@ Example usage: - find ../gitian-builder/build -type f -executable | xargs python3 contrib/devtools/symbol-check.py + find contrib/gitian-builder/build -type f -executable | xargs python3 contrib/devtools/symbol-check.py ''' import subprocess import re diff -Nru bitcoinabc-0.21.11/contrib/release/debian-packages.sh bitcoinabc-0.21.12/contrib/release/debian-packages.sh --- bitcoinabc-0.21.11/contrib/release/debian-packages.sh 2020-07-14 17:36:12.000000000 +0000 +++ bitcoinabc-0.21.12/contrib/release/debian-packages.sh 2020-07-15 16:45:51.000000000 +0000 @@ -4,34 +4,47 @@ set -euo pipefail +DEFAULT_DISTROS=() +# Bionic: Ubuntu 18.04 LTS +DEFAULT_DISTROS+=("bionic") +# Eoan: Ubuntu 19.10 +DEFAULT_DISTROS+=("eoan") +# Focal: Ubuntu 20.04 LTS +DEFAULT_DISTROS+=("focal") + DEFAULT_PPA="bitcoin-abc" DPUT_CONFIG_FILE=~/".dput.cf" TOPLEVEL="$(git rev-parse --show-toplevel)" KEYS_TXT="${TOPLEVEL}"/contrib/gitian-signing/keys.txt help_message() { - echo "Build and sign Debian packages and push to a PPA." - echo "Usage: $0 signer" - echo - echo "Example usage: $0 jasonbcox" - echo - echo "signer will be used to fetch the signing key fingerprint from '${KEYS_TXT}'" - echo " That matching fingerprint will be used to fetch the correctly formatted name and email from GPG." - echo " signer must at least partially match the fingerprint or email in keys.txt" - echo - echo "Note: This script will prompt you to sign with your PGP key." - echo - echo "-d, --dry-run Build and sign the packages, but do not push them to the PPA." - echo "-h, --help Display this help message." - echo "-p, --ppa PPA hostname. Defaults to: '${DEFAULT_PPA}'. If no config file exists at ${DPUT_CONFIG_FILE}" - echo " then one will be created using '${DEFAULT_PPA}'. Setting this option to a hostname other than" - echo " the default will require that you add the necessary settings to the config file." - echo "-v, --version Set the package version. Defaults to the version returned by 'bitcoind --version'." - echo " If set, version must be of the form: MAJOR.MINOR.REVISION[.OPTIONALPATCH]" - echo " OPTIONALPATCH may be necessary when source files have changed but the version revision has not," - echo " as the PPA will reject source archives of the same name." +cat < signer + +Example usage: $0 jasonbcox + +signer will be used to fetch the signing key fingerprint from '${KEYS_TXT}' + That matching fingerprint will be used to fetch the correctly formatted name and email from GPG. + signer must at least partially match the fingerprint or email in keys.txt + +Note: This script will prompt you to sign with your PGP key. + +-d, --dry-run Build and sign the packages, but do not push them to the PPA. +-D, --distro Name of the distribution to package for. Can be supplied multiple times. + If supplied at least once, the defaults are ignored. Defaults to: '${DEFAULT_DISTROS[@]}' +-h, --help Display this help message. +-p, --ppa PPA hostname. Defaults to: '${DEFAULT_PPA}'. If no config file exists at ${DPUT_CONFIG_FILE} + then one will be created using '${DEFAULT_PPA}'. Setting this option to a hostname other than + the default will require that you add the necessary settings to the config file. +-v, --version Set the package version. Defaults to the version returned by 'bitcoind --version'. + If set, version must be of the form: MAJOR.MINOR.REVISION[.OPTIONALPATCH] + OPTIONALPATCH may be necessary when source files have changed but the version revision has not, + as the PPA will reject source archives of the same name. +EOF } +DISTROS=() DRY_RUN="false" NUM_EXPECTED_ARGUMENTS=1 PACKAGE_VERSION="" @@ -44,6 +57,11 @@ DRY_RUN="true" shift # shift past argument ;; + -D|--distro) + DISTROS+=("$2") + shift # shift past argument + shift # shift past value + ;; -h|--help) help_message exit 0 @@ -92,6 +110,11 @@ exit 20 fi +# If no distributions are explicitly set, use the defaults +if [ "${#DISTROS[@]}" == 0 ]; then + DISTROS=("${DEFAULT_DISTROS[@]}") +fi + SIGNER_FINGERPRINT=$(grep "$1" "${KEYS_TXT}" | cut -d' ' -f 1) || { echo "Error: Signer '$1' does not match any line in '${KEYS_TXT}'" exit 21 @@ -182,11 +205,7 @@ fi } -# Bionic: Ubuntu 18.04 LTS -package "bionic" -# Eoan: Ubuntu 19.10 -package "eoan" -# Focal: Ubuntu 20.04 LTS -package "focal" - +for DISTRO in "${DISTROS[@]}"; do + package "${DISTRO}" +done popd diff -Nru bitcoinabc-0.21.11/debian/changelog bitcoinabc-0.21.12/debian/changelog --- bitcoinabc-0.21.11/debian/changelog 2020-07-14 18:44:13.000000000 +0000 +++ bitcoinabc-0.21.12/debian/changelog 2020-07-28 23:48:00.000000000 +0000 @@ -1,5 +1,5 @@ -bitcoinabc (0.21.11-eoan) eoan; urgency=medium +bitcoinabc (0.21.12-eoan) eoan; urgency=medium * New upstream release. - -- Jason B. Cox Tue, 14 Jul 2020 11:44:13 -0700 + -- Jason B. Cox Tue, 28 Jul 2020 16:48:00 -0700 diff -Nru bitcoinabc-0.21.11/debian/compat bitcoinabc-0.21.12/debian/compat --- bitcoinabc-0.21.11/debian/compat 2020-07-14 18:44:13.000000000 +0000 +++ bitcoinabc-0.21.12/debian/compat 2020-07-28 23:48:00.000000000 +0000 @@ -1 +1 @@ -9 +12 diff -Nru bitcoinabc-0.21.11/debian/control bitcoinabc-0.21.12/debian/control --- bitcoinabc-0.21.11/debian/control 2020-07-14 18:44:13.000000000 +0000 +++ bitcoinabc-0.21.12/debian/control 2020-07-28 23:48:00.000000000 +0000 @@ -4,7 +4,7 @@ Maintainer: Bitcoin ABC Package Maintainers Uploaders: Jason B. Cox Build-Depends: cmake (>= 3.13), - debhelper, + debhelper (>=12.1), devscripts, git, libdb5.3++-dev, @@ -20,6 +20,7 @@ libqrencode-dev, libssl-dev, libzmq3-dev, + ninja-build, protobuf-compiler, python3, qttools5-dev, diff -Nru bitcoinabc-0.21.11/debian/rules bitcoinabc-0.21.12/debian/rules --- bitcoinabc-0.21.11/debian/rules 2020-07-14 18:44:13.000000000 +0000 +++ bitcoinabc-0.21.12/debian/rules 2020-07-28 23:48:00.000000000 +0000 @@ -2,7 +2,10 @@ # -*- mode: makefile; coding: utf-8 -*- %: - dh $@ --buildsystem=cmake + dh $@ --buildsystem=cmake+ninja --builddirectory=_build + +override_dh_auto_configure: + dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_JEMALLOC=OFF override_dh_auto_test: - echo "Temporarily skipped due to segfault in tests." + ninja -C _build check diff -Nru bitcoinabc-0.21.11/doc/man/bitcoin-cli.1 bitcoinabc-0.21.12/doc/man/bitcoin-cli.1 --- bitcoinabc-0.21.11/doc/man/bitcoin-cli.1 2020-07-13 17:51:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/man/bitcoin-cli.1 2020-07-27 15:24:34.000000000 +0000 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH BITCOIN-CLI "1" "July 2020" "bitcoin-cli v0.21.11" "User Commands" +.TH BITCOIN-CLI "1" "July 2020" "bitcoin-cli v0.21.12" "User Commands" .SH NAME -bitcoin-cli \- manual page for bitcoin-cli v0.21.11 +bitcoin-cli \- manual page for bitcoin-cli v0.21.12 .SH SYNOPSIS .B bitcoin-cli [\fI\,options\/\fR] \fI\, \/\fR[\fI\,params\/\fR] \fI\,Send command to Bitcoin ABC\/\fR @@ -15,7 +15,7 @@ .B bitcoin-cli [\fI\,options\/\fR] \fI\,help Get help for a command\/\fR .SH DESCRIPTION -Bitcoin ABC RPC client version v0.21.11 +Bitcoin ABC RPC client version v0.21.12 .SH OPTIONS .HP \-? diff -Nru bitcoinabc-0.21.11/doc/man/bitcoind.1 bitcoinabc-0.21.12/doc/man/bitcoind.1 --- bitcoinabc-0.21.11/doc/man/bitcoind.1 2020-07-13 17:51:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/man/bitcoind.1 2020-07-27 15:24:34.000000000 +0000 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH BITCOIND "1" "July 2020" "bitcoind v0.21.11" "User Commands" +.TH BITCOIND "1" "July 2020" "bitcoind v0.21.12" "User Commands" .SH NAME -bitcoind \- manual page for bitcoind v0.21.11 +bitcoind \- manual page for bitcoind v0.21.12 .SH SYNOPSIS .B bitcoind [\fI\,options\/\fR] \fI\,Start Bitcoin ABC Daemon\/\fR .SH DESCRIPTION -Bitcoin ABC Daemon version v0.21.11 +Bitcoin ABC Daemon version v0.21.12 .SH OPTIONS .HP \-? @@ -23,9 +23,9 @@ If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: -0000000000000000013add16221ff595c977de1027c8c3f962acf8fcdfa05065, +000000000000000001831f2498ccf63ab3153bf6046362513832a0ac8008c16e, testnet: -0000000000190c28546af514f5255d8afae5c5f756e191e9b8e9724a1e256e61) +0000000031bedd3009e21403ad61614af5237093f8a794c7c7c1dd5d312fc61e) .HP \fB\-blockfilterindex=\fR .IP diff -Nru bitcoinabc-0.21.11/doc/man/bitcoin-qt.1 bitcoinabc-0.21.12/doc/man/bitcoin-qt.1 --- bitcoinabc-0.21.11/doc/man/bitcoin-qt.1 2020-07-13 17:51:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/man/bitcoin-qt.1 2020-07-27 15:24:34.000000000 +0000 @@ -1,12 +1,12 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH BITCOIN-QT "1" "July 2020" "bitcoin-qt v0.21.11" "User Commands" +.TH BITCOIN-QT "1" "July 2020" "bitcoin-qt v0.21.12" "User Commands" .SH NAME -bitcoin-qt \- manual page for bitcoin-qt v0.21.11 +bitcoin-qt \- manual page for bitcoin-qt v0.21.12 .SH SYNOPSIS .B bitcoin-qt [\fI\,command-line options\/\fR] .SH DESCRIPTION -Bitcoin ABC version v0.21.11 (64\-bit) +Bitcoin ABC version v0.21.12 (64\-bit) .SH OPTIONS .HP \-? @@ -23,9 +23,9 @@ If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: -0000000000000000013add16221ff595c977de1027c8c3f962acf8fcdfa05065, +000000000000000001831f2498ccf63ab3153bf6046362513832a0ac8008c16e, testnet: -0000000000190c28546af514f5255d8afae5c5f756e191e9b8e9724a1e256e61) +0000000031bedd3009e21403ad61614af5237093f8a794c7c7c1dd5d312fc61e) .HP \fB\-blockfilterindex=\fR .IP diff -Nru bitcoinabc-0.21.11/doc/man/bitcoin-tx.1 bitcoinabc-0.21.12/doc/man/bitcoin-tx.1 --- bitcoinabc-0.21.11/doc/man/bitcoin-tx.1 2020-07-13 17:51:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/man/bitcoin-tx.1 2020-07-27 15:24:34.000000000 +0000 @@ -1,7 +1,7 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH BITCOIN-TX "1" "July 2020" "bitcoin-tx v0.21.11" "User Commands" +.TH BITCOIN-TX "1" "July 2020" "bitcoin-tx v0.21.12" "User Commands" .SH NAME -bitcoin-tx \- manual page for bitcoin-tx v0.21.11 +bitcoin-tx \- manual page for bitcoin-tx v0.21.12 .SH SYNOPSIS .B bitcoin-tx [\fI\,options\/\fR] \fI\, \/\fR[\fI\,commands\/\fR] \fI\,Update hex-encoded bitcoin transaction\/\fR @@ -9,7 +9,7 @@ .B bitcoin-tx [\fI\,options\/\fR] \fI\,-create \/\fR[\fI\,commands\/\fR] \fI\,Create hex-encoded bitcoin transaction\/\fR .SH DESCRIPTION -Bitcoin ABC bitcoin\-tx utility version v0.21.11 +Bitcoin ABC bitcoin\-tx utility version v0.21.12 .SH OPTIONS .HP \-? diff -Nru bitcoinabc-0.21.11/doc/man/bitcoin-wallet.1 bitcoinabc-0.21.12/doc/man/bitcoin-wallet.1 --- bitcoinabc-0.21.11/doc/man/bitcoin-wallet.1 2020-07-13 17:51:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/man/bitcoin-wallet.1 2020-07-27 15:24:34.000000000 +0000 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. -.TH BITCOIN-WALLET "1" "July 2020" "bitcoin-wallet v0.21.11" "User Commands" +.TH BITCOIN-WALLET "1" "July 2020" "bitcoin-wallet v0.21.12" "User Commands" .SH NAME -bitcoin-wallet \- manual page for bitcoin-wallet v0.21.11 +bitcoin-wallet \- manual page for bitcoin-wallet v0.21.12 .SH DESCRIPTION -Bitcoin ABC bitcoin\-wallet version v0.21.11 +Bitcoin ABC bitcoin\-wallet version v0.21.12 .PP wallet\-tool is an offline tool for creating and interacting with Bitcoin ABC wallet files. By default wallet\-tool will act on wallets in the default mainnet wallet directory in the datadir. diff -Nru bitcoinabc-0.21.11/doc/release-notes/release-notes-0.21.11.md bitcoinabc-0.21.12/doc/release-notes/release-notes-0.21.11.md --- bitcoinabc-0.21.11/doc/release-notes/release-notes-0.21.11.md 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/doc/release-notes/release-notes-0.21.11.md 2020-07-15 16:44:34.000000000 +0000 @@ -0,0 +1,18 @@ +Bitcoin ABC version 0.21.11 is now available from: + + + +This release includes the following features and fixes: + - Upgrade minimum supported boost version to 1.59 + +Deprecated or removed RPCs +-------------------------- +- The wallet's `generate` RPC method was deprecated in v0.21.5 and has now + been fully removed. This RPC is only used for + testing, but its implementation reached across multiple subsystems + (wallet and mining), so it has been removed to simplify the + wallet-node interface. Projects that are using `generate` for testing + purposes should transition to using the `generatetoaddress` RPC, which + does not require or use the wallet component. Calling + `generatetoaddress` with an address returned by the `getnewaddress` + RPC gives the same functionality as the old `generate` RPC. diff -Nru bitcoinabc-0.21.11/doc/rpc/CMakeLists.txt bitcoinabc-0.21.12/doc/rpc/CMakeLists.txt --- bitcoinabc-0.21.11/doc/rpc/CMakeLists.txt 2020-06-08 20:54:42.000000000 +0000 +++ bitcoinabc-0.21.12/doc/rpc/CMakeLists.txt 2020-07-20 15:59:43.000000000 +0000 @@ -3,7 +3,7 @@ if(BUILD_BITCOIN_CLI) add_custom_target(doc-rpc COMMENT "Generating RPC documentation" - COMMAND go run "${CMAKE_CURRENT_SOURCE_DIR}/generate.go" + COMMAND go run "${CMAKE_CURRENT_SOURCE_DIR}/generate.go" -regtest WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" DEPENDS bitcoin-cli ) diff -Nru bitcoinabc-0.21.11/doc/rpc/generate.go bitcoinabc-0.21.12/doc/rpc/generate.go --- bitcoinabc-0.21.11/doc/rpc/generate.go 2020-06-18 19:26:30.000000000 +0000 +++ bitcoinabc-0.21.12/doc/rpc/generate.go 2020-07-28 23:45:00.000000000 +0000 @@ -187,6 +187,7 @@ } func run(args ...string) string { + additionalArgs := os.Args[1:] + args = append(additionalArgs, args...) return runCommand(bitcoin_cli_path, args...) } - diff -Nru bitcoinabc-0.21.11/src/avalanche/peermanager.cpp bitcoinabc-0.21.12/src/avalanche/peermanager.cpp --- bitcoinabc-0.21.11/src/avalanche/peermanager.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/peermanager.cpp 2020-07-17 16:19:01.000000000 +0000 @@ -4,6 +4,7 @@ #include +#include #include #include @@ -17,6 +18,12 @@ return it->peerid; } + // Reject invalid proof. + ProofValidationState state; + if (!proof.verify(state)) { + return NO_PEER; + } + // We have no peer for this proof, time to create it. const PeerId peerid = nextPeerId++; auto inserted = peers.emplace(peerid, uint32_t(slots.size()), proof); @@ -61,9 +68,7 @@ bool PeerManager::addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey) { const PeerId peerid = getPeer(proof); - - auto pit = peers.find(peerid); - if (pit == peers.end()) { + if (peerid == NO_PEER) { return false; } diff -Nru bitcoinabc-0.21.11/src/avalanche/processor.cpp bitcoinabc-0.21.12/src/avalanche/processor.cpp --- bitcoinabc-0.21.11/src/avalanche/processor.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/processor.cpp 2020-07-20 15:59:43.000000000 +0000 @@ -277,13 +277,12 @@ { LOCK(cs_main); for (const auto &v : votes) { - BlockMap::iterator mi = mapBlockIndex.find(BlockHash(v.GetHash())); - if (mi == mapBlockIndex.end()) { + auto pindex = LookupBlockIndex(BlockHash(v.GetHash())); + if (!pindex) { // This should not happen, but just in case... continue; } - CBlockIndex *pindex = mi->second; if (!IsWorthPolling(pindex)) { // There is no point polling this block. continue; @@ -333,7 +332,7 @@ return true; } -bool Processor::addPeer(NodeId nodeid, const Proof &proof, +bool Processor::addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey) { LOCK(cs_peerManager); return peerManager->addNode(nodeid, proof, pubkey); @@ -428,12 +427,10 @@ { LOCK(cs_main); - BlockMap::iterator mi = mapBlockIndex.find(BlockHash(inv.hash)); - if (mi == mapBlockIndex.end()) { + pindex = LookupBlockIndex(BlockHash(inv.hash)); + if (!pindex) { continue; } - - pindex = mi->second; } auto w = vote_records.getWriteView(); diff -Nru bitcoinabc-0.21.11/src/avalanche/processor.h bitcoinabc-0.21.12/src/avalanche/processor.h --- bitcoinabc-0.21.11/src/avalanche/processor.h 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/processor.h 2020-07-14 19:22:04.000000000 +0000 @@ -258,7 +258,7 @@ bool registerVotes(NodeId nodeid, const Response &response, std::vector &updates); - bool addPeer(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); + bool addNode(NodeId nodeid, const Proof &proof, const CPubKey &pubkey); bool forNode(NodeId nodeid, std::function func) const; CPubKey getSessionPubKey() const { return sessionKey.GetPubKey(); } diff -Nru bitcoinabc-0.21.11/src/avalanche/proofbuilder.cpp bitcoinabc-0.21.12/src/avalanche/proofbuilder.cpp --- bitcoinabc-0.21.11/src/avalanche/proofbuilder.cpp 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/proofbuilder.cpp 2020-07-14 19:22:04.000000000 +0000 @@ -0,0 +1,77 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +namespace avalanche { + +SignedStake ProofBuilder::StakeSigner::sign(const ProofId &proofid) { + const uint256 h = stake.getHash(proofid); + + std::array sig; + std::vector vchSig; + if (key.SignSchnorr(h, vchSig)) { + // Schnorr sig are always 64 bytes in size. + assert(vchSig.size() == 64); + std::copy(vchSig.begin(), vchSig.end(), sig.begin()); + } else { + sig.fill(0); + } + + return SignedStake(std::move(stake), std::move(sig)); +} + +bool ProofBuilder::addUTXO(COutPoint utxo, Amount amount, uint32_t height, + CKey key) { + if (!key.IsValid()) { + return false; + } + + stakes.emplace_back(Stake(std::move(utxo), amount, height, key.GetPubKey()), + std::move(key)); + return true; +} + +Proof ProofBuilder::build() { + const ProofId proofid = getProofId(); + + std::vector signedStakes; + signedStakes.reserve(stakes.size()); + + for (auto &s : stakes) { + signedStakes.push_back(s.sign(proofid)); + } + + stakes.clear(); + return Proof(sequence, expirationTime, std::move(master), + std::move(signedStakes)); +} + +ProofId ProofBuilder::getProofId() const { + CHashWriter ss(SER_GETHASH, 0); + ss << sequence; + ss << expirationTime; + ss << master; + + WriteCompactSize(ss, stakes.size()); + for (const auto &s : stakes) { + ss << s.stake; + } + + return ProofId(ss.GetHash()); +} + +Proof ProofBuilder::buildRandom(uint32_t score) { + CKey key; + key.MakeNewKey(true); + + ProofBuilder pb(0, std::numeric_limits::max(), CPubKey()); + pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, + 0, std::move(key)); + return pb.build(); +} + +} // namespace avalanche diff -Nru bitcoinabc-0.21.11/src/avalanche/proofbuilder.h bitcoinabc-0.21.12/src/avalanche/proofbuilder.h --- bitcoinabc-0.21.11/src/avalanche/proofbuilder.h 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/proofbuilder.h 2020-07-14 19:22:04.000000000 +0000 @@ -0,0 +1,53 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_PROOFBUILDER_H +#define BITCOIN_AVALANCHE_PROOFBUILDER_H + +#include +#include + +#include + +namespace avalanche { + +class ProofBuilder { + uint64_t sequence; + int64_t expirationTime; + CPubKey master; + + struct StakeSigner { + Stake stake; + CKey key; + + StakeSigner(Stake stake_, CKey key_) + : stake(std::move(stake_)), key(std::move(key_)) {} + + SignedStake sign(const ProofId &proofid); + }; + + std::vector stakes; + +public: + ProofBuilder(uint64_t sequence_, int64_t expirationTime_, CPubKey master_) + : sequence(sequence_), expirationTime(expirationTime_), + master(std::move(master_)) {} + + bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, CKey key); + + Proof build(); + + /** + * Builds a randomized (and therefore invalid) Proof. + * Useful for tests. + */ + static Proof buildRandom(uint32_t score); + +private: + ProofId getProofId() const; +}; + +} // namespace avalanche + +#endif // BITCOIN_AVALANCHE_PROOFBUILDER_H diff -Nru bitcoinabc-0.21.11/src/avalanche/proof.cpp bitcoinabc-0.21.12/src/avalanche/proof.cpp --- bitcoinabc-0.21.11/src/avalanche/proof.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/proof.cpp 2020-07-17 16:19:01.000000000 +0000 @@ -4,18 +4,26 @@ #include +#include +#include // For SaltedOutpointHasher #include -#include -#include +#include namespace avalanche { -Proof::Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, - std::vector stakes_) - : sequence(sequence_), expirationTime(expirationTime_), - master(std::move(master_)), stakes(std::move(stakes_)), - proofid(computeProofId()) {} +uint256 Stake::getHash(const ProofId &proofid) const { + CHashWriter ss(SER_GETHASH, 0); + ss << proofid; + ss << *this; + return ss.GetHash(); +} + +bool SignedStake::verify(const ProofId &proofid) const { + // Unfortunately, the verify API require a vector. + std::vector vchSig{sig.begin(), sig.end()}; + return stake.getPubkey().VerifySchnorr(stake.getHash(proofid), vchSig); +} ProofId Proof::computeProofId() const { CHashWriter ss(SER_GETHASH, 0); @@ -40,11 +48,30 @@ return uint32_t((100 * total) / COIN); } -Proof Proof::makeRandom(uint32_t score) { - return Proof(0, std::numeric_limits::max(), CPubKey(), - {{{COutPoint(TxId(GetRandHash()), 0), - (int64_t(score) * COIN) / 100, 0, CPubKey()}, - {}}}); +static constexpr Amount PROOF_DUST_THRESOLD = 1 * SATOSHI; + +bool Proof::verify(ProofValidationState &state) const { + if (stakes.empty()) { + return state.Invalid(ProofValidationResult::NO_STAKE); + } + + std::unordered_set utxos; + for (const SignedStake &ss : stakes) { + const Stake &s = ss.getStake(); + if (s.getAmount() < PROOF_DUST_THRESOLD) { + return state.Invalid(ProofValidationResult::DUST_THRESOLD); + } + + if (!utxos.insert(s.getUTXO()).second) { + return state.Invalid(ProofValidationResult::DUPLICATE_STAKE); + } + + if (!ss.verify(proofid)) { + return state.Invalid(ProofValidationResult::INVALID_SIGNATURE); + } + } + + return true; } } // namespace avalanche diff -Nru bitcoinabc-0.21.11/src/avalanche/proof.h bitcoinabc-0.21.12/src/avalanche/proof.h --- bitcoinabc-0.21.11/src/avalanche/proof.h 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/proof.h 2020-07-17 16:19:01.000000000 +0000 @@ -17,6 +17,8 @@ namespace avalanche { +class ProofValidationState; + struct ProofId : public uint256 { explicit ProofId() : uint256() {} explicit ProofId(const uint256 &b) : uint256(b) {} @@ -56,6 +58,8 @@ uint32_t getHeight() const { return height >> 1; } bool isCoinbase() const { return height & 1; } const CPubKey &getPubkey() const { return pubkey; } + + uint256 getHash(const ProofId &proofid) const; }; class SignedStake { @@ -77,6 +81,8 @@ const Stake &getStake() const { return stake; } const std::array &getSignature() const { return sig; } + + bool verify(const ProofId &proofid) const; }; class Proof { @@ -91,7 +97,10 @@ public: Proof() : sequence(0), expirationTime(0), master(), stakes(), proofid() {} Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, - std::vector stakes_); + std::vector stakes_) + : sequence(sequence_), expirationTime(expirationTime_), + master(std::move(master_)), stakes(std::move(stakes_)), + proofid(computeProofId()) {} ADD_SERIALIZE_METHODS; @@ -107,14 +116,15 @@ } } + uint64_t getSequence() const { return sequence; } + int64_t getExpirationTime() const { return expirationTime; } + const CPubKey &getMaster() const { return master; } + const std::vector &getStakes() const { return stakes; } + const ProofId &getId() const { return proofid; } uint32_t getScore() const; - /** - * Builds a randomized (and therefore invalid) Proof. - * Useful for tests. - */ - static Proof makeRandom(uint32_t score); + bool verify(ProofValidationState &state) const; }; } // namespace avalanche diff -Nru bitcoinabc-0.21.11/src/avalanche/test/CMakeLists.txt bitcoinabc-0.21.12/src/avalanche/test/CMakeLists.txt --- bitcoinabc-0.21.11/src/avalanche/test/CMakeLists.txt 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/CMakeLists.txt 2020-07-14 19:22:04.000000000 +0000 @@ -10,6 +10,7 @@ add_boost_unit_tests_to_suite(avalanche test-avalanche fixture.cpp + util.cpp TESTS peermanager_tests.cpp diff -Nru bitcoinabc-0.21.11/src/avalanche/test/fixture.cpp bitcoinabc-0.21.12/src/avalanche/test/fixture.cpp --- bitcoinabc-0.21.11/src/avalanche/test/fixture.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/fixture.cpp 2020-07-14 19:22:04.000000000 +0000 @@ -3,5 +3,4 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #define BOOST_TEST_MODULE Avalanche Test Suite - #include diff -Nru bitcoinabc-0.21.11/src/avalanche/test/peermanager_tests.cpp bitcoinabc-0.21.12/src/avalanche/test/peermanager_tests.cpp --- bitcoinabc-0.21.11/src/avalanche/test/peermanager_tests.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/peermanager_tests.cpp 2020-07-14 19:22:04.000000000 +0000 @@ -4,6 +4,8 @@ #include +#include + #include #include @@ -157,12 +159,12 @@ const NodeId node0 = 42, node1 = 69, node2 = 37; // One peer, we always return it. - Proof proof0 = Proof::makeRandom(100); - pm.addNode(node0, Proof::makeRandom(100), CPubKey()); + Proof proof0 = buildRandomProof(100); + pm.addNode(node0, buildRandomProof(100), CPubKey()); BOOST_CHECK_EQUAL(pm.selectNode(), node0); // Two peers, verify ratio. - pm.addNode(node1, Proof::makeRandom(200), CPubKey()); + pm.addNode(node1, buildRandomProof(200), CPubKey()); std::unordered_map results = {}; for (int i = 0; i < 10000; i++) { @@ -174,7 +176,7 @@ BOOST_CHECK(abs(2 * results[0] - results[1]) < 500); // Three peers, verify ratio. - pm.addNode(node2, Proof::makeRandom(100), CPubKey()); + pm.addNode(node2, buildRandomProof(100), CPubKey()); results.clear(); for (int i = 0; i < 10000; i++) { @@ -194,7 +196,7 @@ // Add 4 peers. std::array peerids; for (int i = 0; i < 4; i++) { - peerids[i] = pm.getPeer(Proof::makeRandom(100)); + peerids[i] = pm.getPeer(buildRandomProof(100)); } BOOST_CHECK_EQUAL(pm.getSlotCount(), 400); @@ -224,7 +226,7 @@ // Add 4 more peers. for (int i = 0; i < 4; i++) { - peerids[i + 4] = pm.getPeer(Proof::makeRandom(100)); + peerids[i + 4] = pm.getPeer(buildRandomProof(100)); } BOOST_CHECK_EQUAL(pm.getSlotCount(), 700); @@ -264,7 +266,7 @@ // Add 4 peers. std::array peerids; for (int i = 0; i < 4; i++) { - peerids[i] = pm.getPeer(Proof::makeRandom(100)); + peerids[i] = pm.getPeer(buildRandomProof(100)); } // Remove all peers. @@ -289,7 +291,7 @@ PeerManager pm; // Create one peer. - Proof proof = Proof::makeRandom(100); + Proof proof = buildRandomProof(100000000); BOOST_CHECK_EQUAL(pm.selectNode(), NO_NODE); // Add 4 nodes. @@ -325,13 +327,20 @@ pm.updateNextRequestTime(n, std::chrono::steady_clock::now())); } - // Move a node from a peer to another. - Proof altproof = Proof::makeRandom(0); + // Move a node from a peer to another. This peer has a very low score such + // as chances of being picked are 1 in a billion. + Proof altproof = buildRandomProof(1); BOOST_CHECK(pm.addNode(3, altproof, CPubKey())); + int node3selected = 0; for (int i = 0; i < 100; i++) { NodeId n = pm.selectNode(); - BOOST_CHECK(n == 0); + if (n == 3) { + // Selecting this node should be exceedingly unlikely. + BOOST_CHECK(node3selected++ < 1); + } else { + BOOST_CHECK_EQUAL(n, 0); + } BOOST_CHECK( pm.updateNextRequestTime(n, std::chrono::steady_clock::now())); } diff -Nru bitcoinabc-0.21.11/src/avalanche/test/processor_tests.cpp bitcoinabc-0.21.12/src/avalanche/test/processor_tests.cpp --- bitcoinabc-0.21.11/src/avalanche/test/processor_tests.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/processor_tests.cpp 2020-07-27 15:24:34.000000000 +0000 @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include // For PeerLogicValidation #include @@ -210,7 +212,7 @@ PeerLogicValidation &peerLogic, CConnmanTest *connman) { PeerManager &pm = AvalancheTest::getPeerManager(p); - Proof proof = Proof::makeRandom(100); + Proof proof = buildRandomProof(100); std::array nodes; for (CNode *&n : nodes) { @@ -530,7 +532,7 @@ auto avanode = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); NodeId avanodeid = avanode->GetId(); - BOOST_CHECK(p.addPeer(avanodeid, Proof::makeRandom(100), CPubKey())); + BOOST_CHECK(p.addNode(avanodeid, buildRandomProof(100), CPubKey())); // It returns the avalanche peer. BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), avanodeid); @@ -677,7 +679,7 @@ auto avanode = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); NodeId avanodeid = avanode->GetId(); - BOOST_CHECK(p.addPeer(avanodeid, Proof::makeRandom(100), CPubKey())); + BOOST_CHECK(p.addNode(avanodeid, buildRandomProof(100), CPubKey())); // Expire requests after some time. auto queryTimeDuration = std::chrono::milliseconds(10); @@ -725,7 +727,7 @@ // Create enough nodes so that we run into the inflight request limit. PeerManager &pm = AvalancheTest::getPeerManager(p); - Proof proof = Proof::makeRandom(100); + Proof proof = buildRandomProof(100); std::array nodes; for (auto &n : nodes) { @@ -891,7 +893,7 @@ auto avanode = ConnectNode(config, NODE_AVALANCHE, *peerLogic, connman.get()); NodeId nodeid = avanode->GetId(); - BOOST_CHECK(p.addPeer(nodeid, Proof::makeRandom(100), CPubKey())); + BOOST_CHECK(p.addNode(nodeid, buildRandomProof(100), CPubKey())); // There is no query in flight at the moment. BOOST_CHECK_EQUAL(AvalancheTest::getSuitableNodeToQuery(p), nodeid); diff -Nru bitcoinabc-0.21.11/src/avalanche/test/proof_tests.cpp bitcoinabc-0.21.12/src/avalanche/test/proof_tests.cpp --- bitcoinabc-0.21.11/src/avalanche/test/proof_tests.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/proof_tests.cpp 2020-07-17 16:19:01.000000000 +0000 @@ -4,6 +4,9 @@ #include +#include +#include +#include #include #include @@ -15,11 +18,55 @@ BOOST_FIXTURE_TEST_SUITE(proof_tests, BasicTestingSetup) +BOOST_AUTO_TEST_CASE(proof_random) { + for (int i = 0; i < 1000; i++) { + const uint32_t score = InsecureRand32(); + const Proof p = buildRandomProof(score); + BOOST_CHECK_EQUAL(p.getScore(), score); + + ProofValidationState state; + BOOST_CHECK(p.verify(state)); + BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); + } +} + +BOOST_AUTO_TEST_CASE(proofbuilder) { + CKey key; + + // Master key. + key.MakeNewKey(true); + const CPubKey master = key.GetPubKey(); + + const uint64_t sequence = InsecureRandBits(64); + const int64_t expiration = InsecureRandBits(64); + + ProofBuilder pb(sequence, expiration, master); + + for (int i = 0; i < 3; i++) { + key.MakeNewKey(true); + pb.addUTXO(COutPoint(TxId(GetRandHash()), InsecureRand32()), + int64_t(InsecureRand32()) * COIN / 100, InsecureRand32(), + key); + } + + Proof p = pb.build(); + + ProofValidationState state; + BOOST_CHECK(p.verify(state)); + + BOOST_CHECK_EQUAL(p.getSequence(), sequence); + BOOST_CHECK_EQUAL(p.getExpirationTime(), expiration); + BOOST_CHECK(p.getMaster() == master); + + BOOST_CHECK(state.GetResult() == ProofValidationResult::NONE); +} + struct TestVector { std::string name; std::string hex; ProofId proofid; uint32_t score; + ProofValidationResult result; }; BOOST_AUTO_TEST_CASE(deserialization) { @@ -29,7 +76,7 @@ "3e95b02cacfd357b64e4fb6c92e92dd00", ProofId::fromHex("df721b6e2a857ce8abac63d8d5eca35f3bdb0293b6e8295942c7" "6274c5418c0c"), - 0}, + 0, ProofValidationResult::NO_STAKE}, {"1 utxo staked", "a6d66db9fe9378fdd37a0ad2c01c2acd2103648144bb6a0c1d09b0f04d0df6d55f914" "fd81efc65f23a718b68b7c9e42bd5430145a4d07798547464daa53acefb7c97c0c415" @@ -40,7 +87,7 @@ "77d8fcf68c54ebfadf08b9a446c251a0088301c50d53", ProofId::fromHex("048235ee870030f11c287d898dd3ec184f9b38cf4fb274334966" "c6aad83b769d"), - 7584312}, + 7584312, ProofValidationResult::INVALID_SIGNATURE}, {"2 utxo staked", "872379ab64f55b4166ca0e79639999ec4104a66861de557a54eefc0375264cc17c3a3" "50ccabca6fd9c91883e899ab55bb140517aa56c5b4041908e7027a786b99f66488a04" @@ -55,7 +102,7 @@ "91c965cba4dbc11c210979217f1ac3ece7a748f5b2fcf5cced40a5d4c40e", ProofId::fromHex("7319126f0d4efc188440dd50105ea30d792687b65e9cdde6c4d6" "08ed226cba00"), - 15610172}, + 15610172, ProofValidationResult::INVALID_SIGNATURE}, {"3 utxo staked", "525e2aa04af0e2457c66ac9e7f66257f210252db8e3ceea6fca44a7696e82f7b77e5a" "4025e60ac60271b174e91ffbb6ce01f039ce8d3b77938e49ce3bc9824e90b72c65542" @@ -75,7 +122,7 @@ "91b185e", ProofId::fromHex("3b3204993240ab338324310ecadc5f234da1dac0627029cef63e" "1169a049d18f"), - 29026903}, + 29026903, ProofValidationResult::INVALID_SIGNATURE}, {"4 utxo staked", "eef33172651f752ac255c85a4e1374992102c12b37ff6139157865fc4c3a9d7ad999b" "686ade45d453545d04e76f6e14793b404295de5ebf9fbbbb65fc1d9a71587c5284cff" @@ -99,7 +146,174 @@ "14a348c80ca1833d68b3d7b", ProofId::fromHex("62f256d73411fe69bf0db6083248e4efb75be9788850851468ac" "c913c5c14360"), - 44059793}, + 44059793, ProofValidationResult::INVALID_SIGNATURE}, + {"Properly signed 1 UTXO proof", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("17717dbf1cee175925be12321bb04eda7bc861a28b04d764c2d5" + "5eabf01cabd0"), + 444638638, ProofValidationResult::NONE}, + {"Duplicated UTXO", + "60f8332a3ff3430a4f3c9010160cc63e2102f2df6361a5744521d16753f9efb5ace68" + "d43121e90ff67290540b54341cbab0e02d1e26c2287948bc6ab2b55945c591b8ba3ff" + "a237f5d9164d30a4f10145a61f788e639b1480731e2aead30500bf84628721029ed70" + "5bdc5adf0444c57c5ec2ea929c1adc0cd5b9cef4647d85dcb7fc400dc3afd21b29571" + "9c45b90fda493bbc74c8ae1baf28e124cc23bb1987f9932d2df5a0b3455e6c815767c" + "be8ccdd04e0e2d33d5f2f092667ef081acdaafde869d58daed1e26c2287948bc6ab2b" + "55945c591b8ba3ffa237f5d9164d30a4f10145a61f788e639b1480731e2aead30500b" + "f84628721029ed705bdc5adf0444c57c5ec2ea929c1adc0cd5b9cef4647d85dcb7fc4" + "00dc3afd21b295719c45b90fda493bbc74c8ae1baf28e124cc23bb1987f9932d2df5a" + "0b3455e6c815767cbe8ccdd04e0e2d33d5f2f092667ef081acdaafde869d58dae", + ProofId::fromHex("b0c2c07cbc766df0a934bcb252063ad5d7d5167b080369f6feca" + "a3aabae29785"), + 3280755132, ProofValidationResult::DUPLICATE_STAKE}, + {"Properly signed 3 UTXO proof", + "c96492f9e27a25d7e8404581c7be874e210282eb68a587dc586673f439fe317fa0b76" + "aceefa9f99820eadaa70d3b19c0cfe10305d427b706705a5d4b6a368a231d6db62aba" + "cf8c29bc32b61e7f65a0a6976aa8b86b687bc0260e821e4f0200b9d3bf6d2102914b1" + "aade61c7b5d38b18fb8c02ec4a9411858a43969927e5a2bf371e83ea20aa2a8ac89e9" + "fb52edcb227de3c3bd51519c0afcd5c3c134f09e53a9dd4315d4cde560c54b5700c2e" + "7b4f15c18461a3c093b790e93ef54640c051fff6798f18e2c18f54247f6390791706a" + "f36fac782302479898b5273f9e51a92cb1fb5af43deeb6c8c269403dbd48c9530a001" + "34398c441040a9c4426531e19916a0250536684073fbedce86d73e883ee1107e7984e" + "7c721b2be965c63bcbdbd23dcabba6de7ae6715872c803a257e53b686ea69217228c0" + "6ee1b88c4c7aa55adb1804a13e9d222b8d327c4de466fcd9e71ec20582f8d0760830a" + "67e020688e73c91519bd4b74358e65e9ddc95065bcf1bee0d11767e10f30f0d4ce48c" + "4ca9d0714b1fa51920270f8575e0af610f07b4e602a018ecdbb649b64fff614c0026e" + "9fc8e0030092533d424104973b212564dfb8ff1aa4bab13389ed170ea6cbb06fd9a5b" + "5b3e8c00d1a7d4bca7d237748ad793fc043b12f73a28caabb00927c5aea81e323d3ba" + "047a9661adbb0728ccfb41ab345299d7469ff5ec259b98fc946c730b5100cc97284ea" + "6101f7e43337987bbfe655754939709c72c7ba69a9dc08558733781ee9da34e3de7bd" + "a7", + ProofId::fromHex("5948d32ee26882a2d9f96c18e9e51ad13a79234b627a020ee7db" + "733684cb05a7"), + 353426051, ProofValidationResult::NONE}, + {"Changing sequence affect ProofId", + "d87587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("3fdcb56110cfe2f394689be3dd28dedee674f79a567c8391dbd9" + "3900c9845ca8"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing expiration affect ProofId", + "d97587e6c882615797011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("a9ffbb2b37526e05a1f72b43314f872c381281ce8d3d96a5bf56" + "47db057a64dc"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the master key affect ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba897297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b19587 " + "0169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("c237e5436f2d21e4ae990422bfb8ec97df52a9f6db5c20c40f54" + "64e590dcda39"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the TxId affect the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870179a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("9d372d7580917985824c632c919ce8bf89fc6f45c07ee60b2564" + "6aea23390ec6"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the outpoint index change the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91df00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("1a98c5f7684508665fbc946c64c9486e3f7c91b2f42d299320c5" + "56e68e4028fe"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the amount changes the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21814712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("528fa9654e845dfe30ed03966240ab615a8d374d86256e1e4892" + "83eb0a0be44b"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the height changes the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010028e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("a932294f46f106b2b38e57a4b1e4b5849730aba2124662f680a6" + "1c8cc429adb0"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the pubkey changes the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d8d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23e", + ProofId::fromHex("336c9a502b22ba2edcd78298c1ce6cc5e8b5e94cdc60b1047d1f" + "96810d5d17a3"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"Changing the signatue does NOT change the ProofId", + "d97587e6c882615796011ec8f9a7b1c64104e556ba887297fd6a655bc2579d26814e8" + "54c902448ec3ce3c6fe965e3420aa3f0e9611d3c0b8a73b6329741e2e726fd17f5e8a" + "bd546a614b0e05433528b195870169a79ff23e1d58c64afad42ad81cffe53967e16be" + "b692fc5776bb442c79c5d91de00cf21804712806594010038e168a34104d9d84ebf65" + "22cf24c6fd4addedd068632a4db06c3cd6e40031c72d416e9eefbd90037383d8da9e9" + "213a4818a02f108ac1656141ecfbfdde0aeb8620eb210c08b2ce587d9fec0799f9725" + "5d2bc5a077c7b4e8ca8a68d6a0377abf0aa2473f97b37779431062dad50ef5fd21cf1" + "7c0276a293ee5b3f5a130fc5f9b217585cae23f", + ProofId::fromHex("17717dbf1cee175925be12321bb04eda7bc861a28b04d764c2d5" + "5eabf01cabd0"), + 444638638, ProofValidationResult::INVALID_SIGNATURE}, + {"1 utxo staked but zero coins", + "a6d66db9fe9378fdd37a0ad2c01c2acd2103648144bb6a0c1d09b0f04d0df6d55f914" + "fd81efc65f23a718b68b7c9e42bd5430145a4d07798547464daa53acefb7c97c0c415" + "ed8e81e549ff56a0ef6f847fcc9ca855b3620000000000000000e707d7274104fb662" + "6e21dbd1cc9feeecdefc9213fdce2b51ac4bb44e1f8dc6f14c2052f5dd7bfaeb2267a" + "97ca2bec6e0dd4acf50a66204bde1ebb5d6c551684cff2f939920f7fbb2efd860d6d5" + "926bf425eb47b78bf6979cdcd67eb705e2c9a4d45a0930ba25463178a3fb99cb28c8b" + "77d8fcf68c54ebfadf08b9a446c251a0088301c50d53", + ProofId::fromHex("32c852db61880e9e2d4de3edba2daf3f5449e00bf1bc5b18595f" + "80113d5b0722"), + 0, ProofValidationResult::DUST_THRESOLD}, }; for (auto &c : testcases) { @@ -108,14 +322,11 @@ stream >> p; BOOST_CHECK_EQUAL(p.getId(), c.proofid); BOOST_CHECK_EQUAL(p.getScore(), c.score); - } -} -BOOST_AUTO_TEST_CASE(proof_random) { - for (int i = 0; i < 1000; i++) { - const uint32_t score = InsecureRand32(); - const Proof p = Proof::makeRandom(score); - BOOST_CHECK_EQUAL(p.getScore(), score); + ProofValidationState state; + BOOST_CHECK_EQUAL(p.verify(state), + c.result == ProofValidationResult::NONE); + BOOST_CHECK(state.GetResult() == c.result); } } diff -Nru bitcoinabc-0.21.11/src/avalanche/test/util.cpp bitcoinabc-0.21.12/src/avalanche/test/util.cpp --- bitcoinabc-0.21.11/src/avalanche/test/util.cpp 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/util.cpp 2020-07-14 19:22:04.000000000 +0000 @@ -0,0 +1,26 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include +#include + +#include + +namespace avalanche { + +Proof buildRandomProof(uint32_t score) { + CKey key; + key.MakeNewKey(true); + + ProofBuilder pb(0, std::numeric_limits::max(), CPubKey()); + pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, + 0, std::move(key)); + return pb.build(); +} + +} // namespace avalanche diff -Nru bitcoinabc-0.21.11/src/avalanche/test/util.h bitcoinabc-0.21.12/src/avalanche/test/util.h --- bitcoinabc-0.21.11/src/avalanche/test/util.h 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/test/util.h 2020-07-14 19:22:04.000000000 +0000 @@ -0,0 +1,18 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_TEST_UTIL_H +#define BITCOIN_AVALANCHE_TEST_UTIL_H + +#include + +#include + +namespace avalanche { + +Proof buildRandomProof(uint32_t score); + +} // namespace avalanche + +#endif // BITCOIN_AVALANCHE_TEST_UTIL_H diff -Nru bitcoinabc-0.21.11/src/avalanche/validation.h bitcoinabc-0.21.12/src/avalanche/validation.h --- bitcoinabc-0.21.11/src/avalanche/validation.h 1970-01-01 00:00:00.000000000 +0000 +++ bitcoinabc-0.21.12/src/avalanche/validation.h 2020-07-17 16:19:01.000000000 +0000 @@ -0,0 +1,37 @@ +// Copyright (c) 2020 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_AVALANCHE_VALIDATION_H +#define BITCOIN_AVALANCHE_VALIDATION_H + +#include + +namespace avalanche { + +enum class ProofValidationResult { + NONE, + NO_STAKE, + DUST_THRESOLD, + DUPLICATE_STAKE, + INVALID_SIGNATURE, +}; + +class ProofValidationState : public ValidationState { +private: + ProofValidationResult m_result = ProofValidationResult::NONE; + +public: + bool Invalid(ProofValidationResult result, unsigned int chRejectCodeIn = 0, + const std::string &reject_reason = "", + const std::string &debug_message = "") { + m_result = result; + ValidationState::Invalid(chRejectCodeIn, reject_reason, debug_message); + return false; + } + ProofValidationResult GetResult() const { return m_result; } +}; + +} // namespace avalanche + +#endif // BITCOIN_AVALANCHE_VALIDATION_H diff -Nru bitcoinabc-0.21.11/src/bench/block_assemble.cpp bitcoinabc-0.21.12/src/bench/block_assemble.cpp --- bitcoinabc-0.21.11/src/bench/block_assemble.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/bench/block_assemble.cpp 2020-07-15 16:44:34.000000000 +0000 @@ -42,9 +42,8 @@ LOCK(::cs_main); for (const auto &txr : txs) { - CValidationState vstate; + TxValidationState vstate; bool ret{::AcceptToMemoryPool(config, ::g_mempool, vstate, txr, - nullptr /* pfMissingInputs */, false /* bypass_limits */, /* nAbsurdFee */ Amount::zero())}; assert(ret); diff -Nru bitcoinabc-0.21.11/src/bench/checkblock.cpp bitcoinabc-0.21.12/src/bench/checkblock.cpp --- bitcoinabc-0.21.11/src/bench/checkblock.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/bench/checkblock.cpp 2020-07-15 16:44:34.000000000 +0000 @@ -46,7 +46,7 @@ bool rewound = stream.Rewind(benchmark::data::block413567.size()); assert(rewound); - CValidationState validationState; + BlockValidationState validationState; bool checked = CheckBlock(block, validationState, params, options); assert(checked); } diff -Nru bitcoinabc-0.21.11/src/bench/CMakeLists.txt bitcoinabc-0.21.12/src/bench/CMakeLists.txt --- bitcoinabc-0.21.11/src/bench/CMakeLists.txt 2020-07-07 17:16:37.000000000 +0000 +++ bitcoinabc-0.21.12/src/bench/CMakeLists.txt 2020-07-17 16:19:01.000000000 +0000 @@ -75,4 +75,7 @@ target_link_libraries(bitcoin-bench wallet) endif() +include(InstallationHelper) +install_target(bitcoin-bench EXCLUDE_FROM_ALL) + add_custom_target(bench-bitcoin COMMAND bitcoin-bench USES_TERMINAL) diff -Nru bitcoinabc-0.21.11/src/bench/duplicate_inputs.cpp bitcoinabc-0.21.12/src/bench/duplicate_inputs.cpp --- bitcoinabc-0.21.11/src/bench/duplicate_inputs.cpp 2020-07-14 18:43:12.000000000 +0000 +++ bitcoinabc-0.21.12/src/bench/duplicate_inputs.cpp 2020-07-20 15:59:43.000000000 +0000 @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include