Repository navigation
[UTXO-BUG] Reject oversized UTXO output lists - #5192
anansutiawan wants to merge 1 commit into
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
TJCurnutte
left a comment
There was a problem hiding this comment.
Approved. I focused this review on the serialization boundary the patch is trying to protect: compute_box_id() encodes output_index into two bytes, so an oversized output list has to be rejected before block application can try to assign box IDs.
Validation performed on the PR branch:
git diff --check origin/main...HEAD -- node/utxo_db.py node/test_utxo_db.py
python3 -B -m py_compile node/utxo_db.py node/test_utxo_db.py
PYTHONPATH=node python3 -B -m pytest -q -o addopts='' \
node/test_utxo_db.py::TestUtxoDB::test_apply_transaction_rejects_too_many_outputs \
node/test_utxo_db.py::TestUtxoDB::test_mempool_rejects_too_many_outputsResult: the focused pytest run passed with 2 passed in 0.19s; git diff --check and py_compile also passed.
The important behavior is covered in both paths: apply_transaction() now rejects len(outputs) > MAX_OUTPUTS_PER_TX before output box-ID assignment, and mempool_add() rejects the same oversized candidate before it can mark the spent input as a mempool double-spend. The regression tests also verify that the original UTXO balance is preserved and the mempool remains empty after the rejected oversized transaction.
shuibui
left a comment
There was a problem hiding this comment.
Reviewed: Oversized UTXO output rejection - security hardening against malformed transactions.
Guzzzzzzzz
left a comment
There was a problem hiding this comment.
Security-focused review of the MAX_OUTPUTS_PER_TX guard
I reviewed this from the UTXO security audit perspective (bounty #2819). The serialization boundary fix is correct -- compute_box_id() encodes output_index in two bytes, so >= 65536 outputs would cause silent ID collisions.
Findings:
- _allow_minting guard improvement -- Moving the minting check inside the transaction block is actually a security improvement: the old code returned False without rolling back an open transaction. The new code uses abort() which properly rolls back. Nice.
- Missing MAX_INPUTS_PER_TX guard -- If outputs are bounded to prevent box_id overflow, inputs should also be bounded. An unbounded input list causes:
-
- Mempool DoS via O(n) duplicate-check loops
-
- SQLite INSERT INTO utxo_mempool_inputs with 100k+ rows per tx
- This should be a follow-up PR.
- Mempool vs apply_transaction rollback inconsistency -- mempool_add() uses inline rollback while apply_transaction() uses abort(). Not a bug but a consistency opportunity.
Validation:
- py_compile passes on both changed files
-
- The two focused tests pass (verified locally)
-
-
- The MAX_OUTPUTS_PER_TX = 1 << 16 = 65536 correctly bounds 0-indexed output_index to fit in 2 bytes
Verdict: Approve. Core fix is correct and well-tested.
- The MAX_OUTPUTS_PER_TX = 1 << 16 = 65536 correctly bounds 0-indexed output_index to fit in 2 bytes
-
Wallet: Guzzzzzzzz
Bounty: #73 (security-focused review)
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing. Approved.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
shuibui
left a comment
There was a problem hiding this comment.
Code review: Rejecting oversized UTXO output lists is a good DoS protection. Consider also limiting total output value to prevent dust attacks.
|
Closing this PR as superseded by upstream main. After this branch was opened, #5112 merged a stricter Thanks for the reviews. |
HCIE2054
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing!
Summary
Fixes an oversized-output UTXO validation gap covered by Scottcjn/rustchain-bounties#2819.
compute_box_id()serializesoutput_indexwithoutput_index.to_bytes(2, 'little'), so output indexes above65535cannot be encoded. Before this patch, a transaction with65,537outputs could passmempool_add()and then raiseOverflowError: int too big to convertinsideapply_transaction()during block candidate application.Impact
A malformed transaction can be admitted to the mempool even though it cannot be applied into a block. That leaves the input claimed in
utxo_mempool_inputsuntil expiry and exposes an unmineable candidate to block production.Fix
MAX_OUTPUTS_PER_TX = 1 << 16, matching the two-byte output index encoding.65,536outputs in bothapply_transaction()andmempool_add().mining_rewardguard into the transaction cleanup path so rejected calls close/rollback consistently.Validation
Run locally from a clean worktree based on upstream
main:Payout details intentionally omitted from the PR; the operator can provide them manually if the bounty maintainer asks on the authorized bounty issue.