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: miner delay attack #5582

Merged
merged 9 commits into from
Aug 8, 2023

Conversation

SWvheerden
Copy link
Collaborator

@SWvheerden SWvheerden commented Jul 10, 2023

Description

Stops the node blocking until it has a full block

Audit Finding Number

TARI-0001, TARI-0002

Motivation and Context

Its possible for a malicious node to block access to the full block by using first the mempool to say it does not have the missing transactions, then when asked for the full block to only then provide the full block. But these requests can be made slow to delay the node constructing the new block by almost 2 mins. This is the block time.

By only accepting 1 block request at a time, a malicious node can lock down the local node for that entire 2 mins knowing they wont accept any other blocks. This changes it so that nodes can still process new requests. The first complete block will be served first.

Also changes the display of block information to ensure block sorted is correctly used.

@ghpbot-tari-project ghpbot-tari-project added P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged labels Jul 10, 2023
@github-actions
Copy link

github-actions bot commented Jul 10, 2023

Test Results (CI)

1 182 tests   1 182 ✔️  12m 7s ⏱️
     37 suites         0 💤
       1 files           0

Results for commit 5b6e6e7.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jul 10, 2023

Test Results (Integration tests)

  2 files  11 suites   15m 7s ⏱️
27 tests 26 ✔️ 0 💤 1
28 runs  27 ✔️ 0 💤 1

For more details on these failures, see this check.

Results for commit 5b6e6e7.

♻️ This comment has been updated with latest results.

@AaronFeickert
Copy link
Collaborator

Is it possible to label this PR to reflect its status as an audit fix? It should be easy for interested researchers and developers to quickly find audit-related fixes.

@SWvheerden SWvheerden added the C-audit_fix fixes bug found in the audit label Jul 12, 2023
Copy link
Collaborator

@stringhandler stringhandler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a bad start.

  1. I like doing the reconcile before the semaphore, but I think you should remove the semaphore entirely since it no longer serves a purpose.
  2. This solution introduces another problem, as @sdbondi noted, we will be requesting many blocks. I suggest only doing one reconcile per block hash. This could be done using a hashmap/set in this file, or potentially even in base_node_service.rs::spawn_handle_incoming_block and only spawning a thread if there is no thread currently handling this blockhash

@SWvheerden
Copy link
Collaborator Author

I disagree about removing the semaphore, after this point, we are making changes to the tip, and rely on the tip to stay constant during the process.

Copy link
Member

@sdbondi sdbondi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An attacker may still delay the reconciliation if it is the first message, in the worst case making the base node switch to BlockSync mode. This may be fine as an attacker would need to be the first message in, and we assume they have no control over that.

The hash removal also needs to be done in the error case.

@SWvheerden SWvheerden force-pushed the sw_fix_miner_bug branch 2 times, most recently from 2f010e8 to 1d0a4a6 Compare July 24, 2023 13:42
@stringhandler stringhandler removed the P-do_not_merge Process - Not ready for merging label Aug 1, 2023
@SWvheerden SWvheerden force-pushed the sw_fix_miner_bug branch 2 times, most recently from 6a7db77 to ac95868 Compare August 1, 2023 09:00
@ghpbot-tari-project ghpbot-tari-project removed the P-reviews_required Process - Requires a review from a lead maintainer to be merged label Aug 8, 2023
@SWvheerden SWvheerden merged commit bece2d0 into tari-project:development Aug 8, 2023
@SWvheerden SWvheerden deleted the sw_fix_miner_bug branch August 8, 2023 18:46
sdbondi added a commit to sdbondi/tari that referenced this pull request Aug 10, 2023
…-addresses

* development:
  chore: fix windows install (tari-project#5616)
  feat: ban peer unexpected response (tari-project#5608)
  fix!: add validator mr to mining hash (tari-project#5615)
  fix: check bytes remaining on monero blocks (tari-project#5610)
  fix: duplicate tari header in monero coinbase (tari-project#5604)
  fix: monero fork attack (tari-project#5603)
  feat: add mempool min fee (tari-project#5606)
  chore(tests): large block unit tests (tari-project#5599)
  fix: miner delay attack (tari-project#5582)
  fix: peer connection to stale nodes (tari-project#5579)
  ci(fix): artifact cleanup for diag-utils (tari-project#5613)
  ci(fix): update Windows installer for Minotari (tari-project#5614)
  chore: fixes monero build (tari-project#5612)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-audit_fix fixes bug found in the audit P-acks_required Process - Requires more ACKs or utACKs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants