Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(security): Rate-limit and size-limit peer transaction ID messages #6625

Merged
merged 12 commits into from
May 15, 2023

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented May 7, 2023

Motivation

Zebra can send a transaction gossip to half its peers for every transaction it verifies. This could put a lot of load on the network if transaction rates increase.

This helps with the following tickets, but doesn't completely resolve any of them:

Specifications

Zcash network messages are limited to 2MB.

Gossip behaviour is implementation-specific.

The larger wide transaction ID inventory gossip message size of 68 bytes is documented in:
https://zips.z.cash/zip-0239#deployment

Complex Code or Requirements

This code modifies a channel shared between concurrent async tasks.

Solution

Fixes - network message size:

Fixes - network message rate-limits:

  • Combine multiple transaction updates into a single gossip & rate-limit gossips
    • At the moment, peers can trigger lots of broadcast gossips, by sending transactions that are quick to verify
    • This also fixes some bugs:
      • Some transaction gossips could be dropped if they verify close together
      • Zebra logs each transaction gossip, which is a usability problem
      • In rare cases, Zebra could produce invalid gossips with too many transactions, and generate a network error (which was ignored)
  • Rate-limit block gossips
    • This rate limit is unlikely to be reached, because blocks are usually 75 seconds apart
    • Zebra logs each block gossip, which could be a usability problem if blocks arrive close together

Docs:

Testing:

Review

This is a routine security fix. It doesn't have to go into the next release, but if we have time to review it, it would be nice to get it in.

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

Follow Up Work

Rate-limit other kinds of network messages if they become an issue.

@teor2345 teor2345 added C-bug Category: This is a bug NU-5 Network Upgrade: NU5 specific tasks P-Medium ⚡ C-security Category: Security issues I-usability Zebra is hard to understand or use I-remote-node-overload Zebra can overload other nodes on the network A-network Area: Network protocol updates or fixes A-diagnostics Area: Diagnosing issues or monitoring performance A-concurrency Area: Async code, needs extra work to make it work properly. A-mempool Area: Memory pool transactions I-remote-trigger Remote nodes can make Zebra do something bad labels May 7, 2023
@teor2345 teor2345 self-assigned this May 7, 2023
@teor2345 teor2345 requested a review from a team as a code owner May 7, 2023 23:44
@teor2345 teor2345 requested review from oxarbitrage and removed request for a team May 7, 2023 23:44
@teor2345
Copy link
Contributor Author

teor2345 commented May 7, 2023

After this change, new blocks and transactions are gossiped immediately, but then the next gossip is delayed for 6 seconds, and any pending changes are combined:

2023-05-07T23:44:14.798961Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(4) changes=1
2023-05-07T23:44:15.038166Z  INFO {zebrad="e426f63" net="Main"}:{peer=Out("162.19.139.183:8233")}:msg_as_req{msg="inv"}:inbound:download_and_verify{hash=000000000067b02b015bccab67b49a0979145b9b685076c2897343706cd8e9e1}: zebrad::components::inbound::downloads: downloaded and verified gossiped block height=Height(2078266)
2023-05-07T23:44:25.046703Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(7) changes=4
2023-05-07T23:44:31.048226Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(3) changes=3
2023-05-07T23:44:37.049697Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(3) changes=2
2023-05-07T23:44:43.050632Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(1) changes=1
2023-05-07T23:44:49.052259Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(1) changes=1
2023-05-07T23:45:09.622233Z  INFO {zebrad="e426f63" net="Main"}: zebrad::components::mempool::gossip: sending mempool transaction broadcast request=AdvertiseTransactionIds(1) changes=1

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Merging #6625 (07d89b5) into main (0190882) will increase coverage by 0.12%.
The diff coverage is 52.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6625      +/-   ##
==========================================
+ Coverage   77.87%   78.00%   +0.12%     
==========================================
  Files         309      310       +1     
  Lines       40665    40740      +75     
==========================================
+ Hits        31669    31779     +110     
+ Misses       8996     8961      -35     

@teor2345 teor2345 changed the title fix(security): Rate-limit peer gossip messages fix(security): Rate-limit and size-limit peer gossip messages May 9, 2023
@teor2345 teor2345 force-pushed the reduce-peer-gossip-load branch from e426f63 to e8e0df2 Compare May 9, 2023 20:30
@teor2345 teor2345 changed the title fix(security): Rate-limit and size-limit peer gossip messages fix(security): Rate-limit and size-limit peer transaction gossip messages May 9, 2023
@teor2345 teor2345 changed the title fix(security): Rate-limit and size-limit peer transaction gossip messages fix(security): Rate-limit and size-limit peer transaction ID messages May 9, 2023
@teor2345
Copy link
Contributor Author

teor2345 commented May 9, 2023

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented May 9, 2023

update

✅ Branch has been successfully updated

@teor2345
Copy link
Contributor Author

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented May 10, 2023

update

✅ Branch has been successfully updated

@teor2345
Copy link
Contributor Author

We're seeing an increased volume of transactions on the network after the ZIP-317 deployment, so this seems like a high priority to get fixed.

@teor2345
Copy link
Contributor Author

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented May 11, 2023

update

✅ Branch has been successfully updated

mergify bot added a commit that referenced this pull request May 15, 2023
@mergify mergify bot merged commit dc51989 into main May 15, 2023
@mergify mergify bot deleted the reduce-peer-gossip-load branch May 15, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Async code, needs extra work to make it work properly. A-diagnostics Area: Diagnosing issues or monitoring performance A-mempool Area: Memory pool transactions A-network Area: Network protocol updates or fixes C-bug Category: This is a bug C-security Category: Security issues I-remote-node-overload Zebra can overload other nodes on the network I-remote-trigger Remote nodes can make Zebra do something bad I-usability Zebra is hard to understand or use NU-5 Network Upgrade: NU5 specific tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants