Commit Graph

276 Commits

Author SHA1 Message Date
Kris Nuttycombe 1b2d994a39 zcashd release v5.3.3
Notable changes
 ===============
 
 This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
 as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
 messages to fill the memory of a node, resulting in a crash.
 -----BEGIN PGP SIGNATURE-----
 
 iQGzBAABCgAdFiEEX8Nd8pnYcf0pobEL9FXpuSAjoYsFAmP1CD8ACgkQ9FXpuSAj
 oYvGXQwAqaa1l5qC3VY/60jkH4xmWoSUEzeCOPUG7lYJrIEyzgXj8Ko0Cjr308jm
 ISXDDTOxKb2hfnCbeqbZqRyFbzGzG5L6AkjHAvmQMiZwx2JlbH2k+jd5fggOZSMv
 shL5KbxWN2YRftc8r+fDraJMbGULbKBWQooKaFyQmupT+bVsRf1Nh+lFIVG4FUwA
 oWZot36wB6Y99Y57wlyN2m22+j1glyk5mKv2ttXYbdwSRTFB5W5L1US6Z8uxXQPb
 Qa7sVO90QtzkHr+GPtMiTn513VuLFr+KArGn+qidU/PvblJI/vXuBf54g7JZw4Ot
 gkKziatgaN3pO30I4rTij78LCgKJZ/WImLE7nwTl/bG2Ki1WfyolNLjS+1pXpcPL
 xlXso5ioKlSIGhnlPouXwoxlaqTpDwRKLp0azNJl5hG/tXEHupToK2M61woi9LlP
 4RB+a75OptFi9NMp/Sx0T8zNRn7OB8iP+3BgRP0+mzcLC1AHfjJk/IRo9CQh5jRZ
 MMe98OrC
 =6QYn
 -----END PGP SIGNATURE-----

Merge tag 'v5.3.3' into hotfix-v5.4.2

zcashd release v5.3.3

Notable changes
===============

This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
messages to fill the memory of a node, resulting in a crash.
2023-03-13 06:18:00 -06:00
Kris Nuttycombe 2c85dd9598 Merge remote-tracking branch '22387-backport' into hotfix-5.3.3 2023-02-20 19:33:18 -07:00
Daira Hopwood 074e633798 Improve the encapsulation of `CNode::filterInventoryKnown`.
Co-authored-by: Jack Grigg <jack@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-20 23:39:20 +00:00
Daira Hopwood c5b8807ce7 Ensure that CNode::{addrKnown, filterInventoryKnown} immediately take
little memory when we disconnect the node.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: Jack Grigg <str4d@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-20 20:14:55 +00:00
Pieter Wuille 1dddc1337c Add logging and addr rate limiting statistics
Includes logging improvements by Vasil Dimov and John Newbery.

(cherry picked from commit bitcoin/bitcoin@f424d601e1)
2023-02-17 16:47:47 -07:00
Pieter Wuille 7c739e2b20 Rate limit the processing of incoming addr messages
While limitations on the influence of attackers on addrman already
exist (affected buckets are restricted to a subset based on incoming
IP / network group), there is no reason to permit them to let them
feed us addresses at more than a multiple of the normal network
rate.

This commit introduces a "token bucket" rate limiter for the
processing of addresses in incoming ADDR and ADDRV2 messages.
Every connection gets an associated token bucket. Processing an
address in an ADDR or ADDRV2 message from non-whitelisted peers
consumes a token from the bucket. If the bucket is empty, the
address is ignored (it is not forwarded or processed). The token
counter increases at a rate of 0.1 tokens per second, and will
accrue up to a maximum of 1000 tokens (the maximum we accept in a
single ADDR or ADDRV2). When a GETADDR is sent to a peer, it
immediately gets 1000 additional tokens, as we actively desire many
addresses from such peers (this may temporarily cause the token
count to exceed 1000).

The rate limit of 0.1 addr/s was chosen based on observation of
honest nodes on the network. Activity in general from most nodes
is either 0, or up to a maximum around 0.025 addr/s for recent
Bitcoin Core nodes. A few (self-identified, through subver) crawler
nodes occasionally exceed 0.1 addr/s.

(cherry-picked from commit bitcoin/bitcoin@0d64b8f709)
2023-02-17 14:36:25 -07:00
Kris Nuttycombe 3cec519ce4 scripted-diff: Update Zcash copyrights to 2023
-BEGIN VERIFY SCRIPT-
for party in "The Zcash developers" "The Bitcoin Core developers" "Bitcoin Developers"; do
  sed -i"" -e "s#Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? $party#Copyright (c) \1-2023 $party#" COPYING
  sed -i"" -e "s#\(.*\)\([0-9]\{4\}\)\(-[0-9]\{4\}\)\, $party#\1\2-2023, $party#" contrib/debian/copyright
done

sed -i"" -e "s/define(_COPYRIGHT_YEAR, [0-9]\{4\})/define(_COPYRIGHT_YEAR, 2023)/" configure.ac
sed -i"" -e "s/#define COPYRIGHT_YEAR [0-9]\{4\}/#define COPYRIGHT_YEAR 2023/" src/clientversion.h

git grep "^// Copyright (c) .* The Zcash developers" \
  | awk -F ':' '{print $1}' \
  | xargs -I {} sed -i"" -e "s#// Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? The Zcash developers#// Copyright (c) \1-2023 The Zcash developers#" {}
-END VERIFY SCRIPT-
2023-01-23 11:31:54 -07:00
Jim Posen 9a7e2c153d scripted-diff: Move util files to separate directory.
-BEGIN VERIFY SCRIPT-
mkdir -p src/util
git mv src/util.h src/util/system.h
git mv src/util.cpp src/util/system.cpp
git mv src/utilmoneystr.h src/util/moneystr.h
git mv src/utilmoneystr.cpp src/util/moneystr.cpp
git mv src/utilstrencodings.h src/util/strencodings.h
git mv src/utilstrencodings.cpp src/util/strencodings.cpp
git mv src/utiltime.h src/util/time.h
git mv src/utiltime.cpp src/util/time.cpp

sed -i -e 's/"util\.h"/"util\/system\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
git checkout HEAD -- src/secp256k1 # exclude secp256k1, which has its own "util.h"
sed -i -e 's/"utilmoneystr\.h"/"util\/moneystr\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/"utilstrencodings\.h"/"util\/strencodings\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/"utiltime\.h"/"util\/time\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')

sed -i -e 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h
sed -i -e 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h
sed -i -e 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h
sed -i -e 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h

sed -i -e 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am
sed -i -e 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am
sed -i -e 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am
sed -i -e 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am

sed -i -e 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-locale-dependence.sh
sed -i -e 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh
sed -i -e 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh
-END VERIFY SCRIPT-
2022-07-01 17:50:09 -06:00
Matt Corallo 53b8b43567 Split CNode::cs_vSend: message processing and message sending
cs_vSend is used for two purposes - to lock the datastructures used
to queue messages to place on the wire and to only call
SendMessages once at a time per-node. I believe SendMessages used
to access some of the vSendMsg stuff, but it doesn't anymore, so
these locks do not need to be on the same mutex, and also make
deadlocking much more likely.

(cherry picked from commit bitcoin/bitcoin@d7c58ad514)
2022-05-14 01:25:08 +00:00
Kris Nuttycombe 28040f9ce4 scripted-diff: Add 2016-2022 copyright headers for files added/modified in 2016
-BEGIN VERIFY SCRIPT-
grep -l "Copyright" $(grep -L "The Zcash developers" $(git diff --name-only --diff-filter=ACM bitcoin-v0.11.2..94f427a211bb337200c29a1e19be0f5ad2f171b0 -- src/ test/ zcutil/ qa/)) | xargs -I {} sed -i"" -e "s#\(\(.*\)Copyright (c) .* The Bitcoin Core developers\)#\1\n\2Copyright (c) 2016-2022 The Zcash developers#" {}
-END VERIFY SCRIPT-
2022-05-11 17:23:09 -06:00
Dimitris Apostolou e05c1ddf8a
Fix typos 2021-11-14 16:27:09 +02:00
Jack Grigg fc8726e6a4 Use wtxid for peer state management 2021-09-10 21:50:24 +01:00
Jack Grigg d503691778 Add MSG_WTX support to inv messages
The change to AlreadyHave() means that nodes will also now send getdata
requests for v5 transactions.
2021-09-10 21:47:42 +01:00
Jack Grigg 41efe647de lint: remove duplicate include 2021-08-24 16:05:55 +01:00
John Newbery 8469683eb6 [net] split PushInventory()
PushInventory() is currently called with a CInv object, which can be a
MSG_TX or MSG_BLOCK. PushInventory() only uses the type to determine
whether to add the hash to setInventoryTxToSend or
vInventoryBlockToSend.

Since the caller always knows what type of inventory they're pushing,
the CInv is wastefully constructed and thrown away, and tx/block relay
is being split out, we split the function into PushTxInventory() and
PushBlockInventory().

(cherry picked from commit bitcoin/bitcoin@f52d403b81)

Zcash: Adjusted to account for bitcoin/bitcoin#15759 not having been
backported.
2021-08-13 15:42:04 +01:00
Gregory Maxwell 48ead0bea1 Defer inserting into maprelay until just before relaying.
This reduces the rate of not founds by better matching the far
 end expectations, it also improves privacy by removing the
 ability to use getdata to probe for a node having a txn before
 it has been relayed.

(cherry picked from commit bitcoin/bitcoin@4d8993b346)
2021-08-13 03:58:03 +01:00
Gregory Maxwell df5875048c Do not use mempool for GETDATA for tx accepted after the last mempool req.
The ability to GETDATA a transaction which has not (yet) been relayed
 is a privacy loss vector.

The use of the mempool for this was added as part of the mempool p2p
 message and is only needed to fetch transactions returned by it.

(cherry picked from commit bitcoin/bitcoin@7e908c7b82)
2021-08-13 03:58:03 +01:00
Gregory Maxwell 6fdc4def4a Move bloom and feerate filtering to just prior to tx sending.
This will avoid sending more pointless INVs around updates, and
 prevents using filter updates to timetag transactions.

Also adds locking for fRelayTxes.

(cherry picked from commit b5599147533103efea896a1fc4ff51f2d3ad5808)
2021-08-12 00:37:51 +01:00
Pieter Wuille 86f8b51096 Handle mempool requests in send loop, subject to trickle
By eliminating queued entries from the mempool response and responding only at
trickle time, this makes the mempool no longer leak transaction arrival order
information (as the mempool itself is also sorted)-- at least no more than
relay itself leaks it.

(cherry picked from commit ed7068302c7490e8061cb3a558a0f83a465beeea)
2021-08-12 00:37:51 +01:00
Pieter Wuille 709c5163d4 Split up and optimize transaction and block inv queues
(cherry picked from commit dc13dcd2bec2613a1cd5e0395b09b449d176146f)
2021-08-12 00:37:51 +01:00
Pieter Wuille ad8abd68a1 Change mapRelay to store CTransactions
(cherry picked from commit 38c310299cfef419d42744362b90c1700b598953)
2021-08-04 17:12:36 +01:00
Suhas Daftuar 44787c0179 Use txid as key in mapAlreadyAskedFor
Previously we used the CInv that would be sent to the peer announcing the
transaction as the key, but using the txid instead allows us to decouple the
p2p layer from the application logic (which relies on this map to avoid
duplicate tx requests).

(cherry picked from commit 7e91f632c70ff1848a152f24ee67a06796803943)
2021-08-04 17:12:36 +01:00
Pieter Wuille 13d8f294ac Replace trickle nodes with per-node/message Poisson delays
We used to have a trickle node, a node which was chosen in each iteration of
the send loop that was privileged and allowed to send out queued up non-time
critical messages. Since the removal of the fixed sleeps in the network code,
this resulted in fast and attackable treatment of such broadcasts.

This pull request changes the 3 remaining trickle use cases by random delays:
* Local address broadcast (while also removing the the wiping of the seen filter)
* Address relay
* Inv relay (for transactions; blocks are always relayed immediately)

The code is based on older commits by Patrick Strateman.

(cherry picked from commit 5400ef6bcb9d243b2b21697775aa6491115420f3)
2021-08-04 17:12:25 +01:00
Matt Corallo c9e2172eb6 Move CNode::addrLocal access behind locked accessors
zcash: cherry picked from commit db2dc7a58cb0a3df58188b748df8e0d04ba76f00
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-02 12:55:48 +13:00
Matt Corallo 116deeec5b Move CNode::addrName accesses behind locked accessors
zcash: cherry picked from commit 036073bf87c07f8d69e39168dd93a52f1aafe85c
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-02 12:55:48 +13:00
Matt Corallo 78e0b89750 Move [clean|str]SubVer writes/copyStats into a lock
zcash: cherry picked from commit 22b4966a29501c4f3f2e970ac5008fbd91e665a9
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-02 12:55:48 +13:00
Matt Corallo 676e7814f3 Make nServices atomic
zcash: cherry picked from commit 0f3187261519c7568ef4211ce12b9740a3c1200f
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-02 12:55:48 +13:00
Matt Corallo 651c46a4b3 Make nStartingHeight atomic
zcash: cherry picked from commit 96f42d8a12871b8d5c4e31fd27d8135f97c6b3e0
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-02 12:55:48 +13:00
Matt Corallo 208a1a5867 Make nTimeConnected const in CNode
zcash: cherry picked from commit 644f1234e22626a7b5618a1dae60a8457a4063b1
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-01 14:29:40 -06:00
Cory Fields 51fb0415c9 net: fix a few races. Credit @TheBlueMatt
These are (afaik) all long-standing races or concurrent accesses. Going
forward, we can clean these up so that they're not all individual atomic
accesses.

- Reintroduce cs_vRecv to guard receive-specific vars
- Lock vRecv/vSend for CNodeStats
- Make some vars atomic.
- Only set the connection time in CNode's constructor so that it doesn't change

zcash: cherry picked from commit 321d0fc6b6624c65508f8b9059418cb936f0bbbe
zcash: https://github.com/bitcoin/bitcoin/pull/9708
2021-04-01 14:29:40 -06:00
Cory Fields 9825103a10 net: add a lock around hSocket
zcash: cherry picked from commit 9a0b784deaab6b9fffcab227d928987b981d0572
zcash: https://github.com/bitcoin/bitcoin/pull/9698
2021-04-01 14:29:40 -06:00
Homu ba4eb241e7 Auto merge of #4996 - str4d:2074-net-blocksonly, r=str4d
Add -blocksonly option

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6993
- bitcoin/bitcoin#7046
- bitcoin/bitcoin#6780
  - The third commit (we backported the rest in #2390).
- bitcoin/bitcoin#7126
- bitcoin/bitcoin#7439
- bitcoin/bitcoin#15990
  - Only the `-blocksonly` documentation changes.
- bitcoin/bitcoin#16555
- bitcoin/bitcoin#18391
  - Only the `-blocksonly` documentation changes.

Part of #2074.
2021-03-31 11:27:22 +00:00
Jack Grigg ab3196c1df Add more detailed metrics
- Sprout and Sapling pool metrics (commitments, values)
- Block verification time histogram (as a summary, not bucketed)
- Mempool stats (same as getmempoolinfo returns)
- Inbound and outbound bytes labelled by command
- Added command labels to message counters
2021-03-30 15:12:08 +13:00
Homu 2aa9fbbdfe Auto merge of #4997 - str4d:2074-net-setInventoryKnown, r=str4d
Replace setInventoryKnown with a rolling bloom filter

Cherry-picked from bitcoin/bitcoin#7133.
- Excluding for last commit, which needs bitcoin/bitcoin#7129.

Part of #2074.
2021-03-05 12:17:16 +00:00
Daira Hopwood a0ac27ec6e Fix regression introduced in e286250ce4 by adding #include <atomic>. fixes #5014
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2021-03-01 17:00:13 +00:00
Patick Strateman 2391de6375 Only use filterInventoryKnown with MSG_TX inventory messages.
Previously this logic could erroneously filter a MSG_BLOCK inventory message.
2021-02-19 20:16:10 +00:00
Patick Strateman 021ff72e60 Rename setInventoryKnown filterInventoryKnown 2021-02-19 20:16:10 +00:00
Gregory Maxwell 12ddfcacd4 Remove mruset as it is no longer used. 2021-02-19 20:16:10 +00:00
Gregory Maxwell 994a094379 Replace setInventoryKnown with a rolling bloom filter.
Mruset setInventoryKnown was reduced to a remarkably small 1000
 entries as a side effect of sendbuffer size reductions in 2012.

This removes setInventoryKnown filtering from merkleBlock responses
 because false positives there are especially unattractive and
 also because I'm not sure if there aren't race conditions around
 the relay pool that would cause some transactions there to
 be suppressed. (Also, ProcessGetData was accessing
 setInventoryKnown without taking the required lock.)
2021-02-19 20:16:10 +00:00
Peter Todd f191acc477 Add relaytxes status to getpeerinfo 2021-02-19 19:28:16 +00:00
Patick Strateman f9555b6c18 Fix fRelayTxs comment 2021-02-19 19:28:16 +00:00
Patick Strateman 7e6ef59248 Add help text for blocksonly and whitelistalwaysrelay 2021-02-19 19:28:16 +00:00
Homu b62e35dee8 Auto merge of #4994 - str4d:2074-net-misc-1, r=nuttycom
Bitcoin 0.12 misc P2P/Net PRs

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5288
  - Only the reorg, option was removed in bitcoin/bitcoin#6374 which we merged in #1258
- bitcoin/bitcoin#6561
- bitcoin/bitcoin#6728
- bitcoin/bitcoin#6829
- bitcoin/bitcoin#6974
- bitcoin/bitcoin#7075
- bitcoin/bitcoin#7166

Part of #2074.
2021-02-19 15:48:11 +00:00
Homu 65122845c5 Auto merge of #4991 - nuttycom:backport/9792-fastrandom_chacha20, r=str4d
FastRandomContext improvements and switch to ChaCha20

Backport of bitcoin/bitcoin#9792

Commits are recorded here in stack order

- pick bitcoin/bitcoin@4fd2d2fc97
- pick bitcoin/bitcoin@16329224e7
- pick bitcoin/bitcoin@e04326fe66
- pick bitcoin/bitcoin@663fbae777 -- already applied in #3858, skip
- pick bitcoin/bitcoin@c21cbe61c6 -- already applied in #3858, skip
2021-02-18 21:40:41 +00:00
Josh Lehan d3a2f120f5 Re-organize -maxconnections option handling
Zcash: Was "Added -whiteconnections=<n> option" from bitcoin/bitcoin#5288. The
option was later removed in bitcoin/bitcoin#6374 which we merged in #1258. This
commit contains the difference between the two.
2021-02-18 19:03:58 +00:00
Pieter Wuille 1f41301c97 Add a FastRandomContext::randrange and use it
(cherry picked from commit 4fd2d2fc97e21efceab849576e544160fd5e3e3d)
2021-02-17 15:43:43 -07:00
Jack Grigg 1eb7bbc6be Fix some typos 2021-02-17 13:35:11 -07:00
Jack Grigg 51ae7a0ae5 init: Pass post-Blossom spacing into CNode::SetMaxOutboundTarget() 2021-02-17 13:35:11 -07:00
Jack Grigg 0f66b1e138 Pass current PoWTargetSpacing() into CNode::OutboundTargetReached() 2021-02-17 13:35:00 -07:00
MarcoFalke 72fbeae94e [net] Cleanup maxuploadtarget
* log: nMaxOutboundLimit is in bytes
* log: Hide misleading -maxuploadtarget=0 warning
* qa : Minor cleanup to maxuploadtarget rpc tests
* net: Use DEFAULT_MAX_UPLOAD_TARGET = 0
2021-02-17 19:23:38 +00:00