Repository navigation
[UTXO-BUG] Reject unpersistable UTXO outputs - #5451
Conversation
|
CI note after checking the failed The blocking failure is unrelated to this UTXO diff. The job reaches the full
The PR-specific validation remains green locally: |
GoodMorC
left a comment
There was a problem hiding this comment.
Approved. I reviewed the UTXO output normalization change and did not find a blocker.
What I checked:
mempool_add()andapply_transaction()now share the same output-shape validation for address, dust/value type, andtokens_json/registers_jsonpersistence shape.- Invalid JSON-serializable outputs are rejected before mempool insertion, so they do not claim
utxo_mempool_inputsor remain as unmineable block candidates. - Direct
apply_transaction()fails closed before spending the input or changing balances for malformed outputs. - Valid outputs without explicit metadata remain compatible because the normalizer supplies the existing default
[]/{}metadata shape during application.
Validation on head a271fb2e859facb45298c16b3a1146ae72ae99d7:
PYTHONPATH=review-5451/node:/tmp/rustchain-testdeps python3 -B -m unittest review-5451/node/test_utxo_db.py -v-> 73 passedpython3 -m py_compile review-5451/node/utxo_db.py review-5451/node/test_utxo_db.py-> passed
No blocking issue found in this scope.
kekehanshujun
left a comment
There was a problem hiding this comment.
Approved. I reviewed the UTXO output-normalization change and did not find a blocker.
What I checked:
apply_transaction()andmempool_add()now share_normalize_outputs(...), so mempool admission rejects output shapes that direct application cannot persist safely.- The validator rejects missing/non-string/blank
addressvalues and metadata fields that are not SQLite-safe JSON text with the expected decoded shape (tokens_jsonas list,registers_jsonas dict). - The mempool regression verifies invalid outputs do not enter block candidates and do not lock the input UTXO.
- The direct-apply regression verifies invalid output shapes fail before mutating balances.
Validation on head a271fb2e859facb45298c16b3a1146ae72ae99d7:
python -B -m unittest node.test_utxo_db.TestUtxoDB.test_mempool_rejects_unpersistable_outputs_without_locking_input node.test_utxo_db.TestUtxoDB.test_apply_transaction_rejects_unpersistable_outputs -v-> 2 passedpython -B node\test_utxo_db.py-> 73 passedpython -m py_compile node\utxo_db.py node\test_utxo_db.py-> passed
No blocking issue found in this scope.
HCIE2054
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing!
ZacharyZhang-NY
left a comment
There was a problem hiding this comment.
Reviewed PR #5451 at head a271fb2.
Validation performed:
- git fetch origin pull/5451/head:review-pr-5451 --force
- git diff --check origin/main...review-pr-5451 -- node/utxo_db.py node/test_utxo_db.py -> passed.
- python -m py_compile node/utxo_db.py node/test_utxo_db.py on an extracted PR-head tree -> passed.
- PYTHONPATH=node python -B -m unittest node.test_utxo_db.TestUtxoDB.test_mempool_rejects_unpersistable_outputs_without_locking_input node.test_utxo_db.TestUtxoDB.test_apply_transaction_rejects_unpersistable_outputs -v -> 2 passed.
- PYTHONPATH=node python -B node/test_utxo_db.py -> 73 tests passed.
- Checked bounty #2819 and the PR's duplicate-boundary statement for this mempool DoS / invalid block-candidate class.
- Ran an additional UtxoDB probe covering missing address, non-string address, non-string metadata, and wrong-shaped metadata JSON. Each invalid output was rejected by mempool_add(), block candidates stayed empty, the input stayed unlocked, and the original balance remained unchanged.
The shared _normalize_outputs() path aligns mempool admission with direct transaction application for persistable output shape, dust/value validation, and metadata JSON shape. This closes the issue-scoped invalid-candidate path while preserving valid default metadata behavior. Approving.
TJCurnutte
left a comment
There was a problem hiding this comment.
Validated locally and this looks good to merge.
Proof I ran on head a271fb2e859f:
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
python3 -B -m pytest -q node/test_utxo_db.py
# 73 passed, 11 subtests passed in 0.51sI also ran a runtime probe against temporary initialized UTXO databases. It covered seven invalid output shapes through mempool_add() — missing/blank/non-string address, non-string tokens_json/registers_json, and JSON strings with the wrong container type — and confirmed each one returns False, leaves mempool_get_block_candidates() empty, and does not set a double-spend lock on the input. A direct apply_transaction() probe for bad persisted metadata shapes also returned False while preserving Alice/Bob balances.
The important bit is that _normalize_outputs() is now shared by direct application and mempool admission, so the candidate set cannot accept an output shape that later fails while deriving propositions or binding the TEXT metadata columns. That closes the unmineable-mempool-lock path without weakening the existing dust/bool/non-int checks.
No blocking findings from this pass.
ZacharyZhang-NY
left a comment
There was a problem hiding this comment.
Reviewed PR #5451 at head a271fb2.
Validation performed:
- Checked rustchain-bounties#2819. This is a UTXO mempool/validation hardening finding: malformed but JSON-serializable outputs could enter mempool, lock inputs, and remain as unmineable block candidates.
- git fetch origin pull/5451/head:review-pr-5451 --force
- git diff --check origin/main...review-pr-5451 -- node/utxo_db.py node/test_utxo_db.py -> passed.
- python -m py_compile node/utxo_db.py node/test_utxo_db.py on an extracted PR-head tree -> passed.
- From the extracted PR-head
node/directory: python -B -m unittest test_utxo_db.TestUtxoDB.test_mempool_rejects_unpersistable_outputs_without_locking_input test_utxo_db.TestUtxoDB.test_apply_transaction_rejects_unpersistable_outputs -v -> 2 passed. - From the extracted PR-head
node/directory: python -B test_utxo_db.py -> 73 passed. - python tools/bcos_spdx_check.py --base-ref origin/main from a detached PR-head worktree -> OK.
The shared output normalization now keeps mempool admission and direct transaction application aligned for address shape, dust/value checks, and JSON metadata persistence. Approving.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing. Approved.
508704820
left a comment
There was a problem hiding this comment.
Reject unpersistable UTXO outputs. Verify: (1) Unpersistable outputs cannot be created even through internal API. (2) Rejection criteria cover all edge cases: null fields, invalid types, oversized data. (3) Existing unpersistable outputs in DB are identified and handled. - Xeophon (security review, UTXO)
|
Security Review ✅ IMPORTANT Reject unpersistable UTXO outputs. Malformed outputs that cannot be converted to propositions or SQLite TEXT metadata could enter the mempool, lock inputs, and persist as broken block candidates — effectively a state corruption DoS. Fix adds shared normalization for both apply_transaction() and mempool_add(). Reviewed by Xeophon - Solana: Lt9nERv6VHsojw15LpFeiaabuphAggzfLF9sM9UXRrZ |
|
Payment: 25 RTC (Medium tier, audit batch 4) Audit summary: UTXO output normalization (mempool + apply_transaction). Dispatched to wallet — Codex gpt-5.4 xhigh audit, Sophia/Claude synthesis |
Summary
apply_transaction()andmempool_add()Security impact
Current
mainaccepts several JSON-serializable output payloads into the mempool even though block application cannot persist or apply them. The admitted transaction claims the input inutxo_mempool_inputs, appears inmempool_get_block_candidates(), then fails duringapply_transaction()and remains available as an unmineable candidate until expiry.Confirmed pre-fix cases on current
main:Duplicate boundary
This overlaps the same UTXO mempool-hardening area as older reports, but it is not only the missing-
addresscase. This patch centralizes output normalization and covers additional unpersistable shapes that still reproduce onmain: non-string/blank addresses and metadata payloads whose JSON shape cannot be persisted consistently (tokens_jsonmust be JSON text decoding to a list;registers_jsonmust be JSON text decoding to a dict). The goal is to keep mempool admission and direct application on the same validation rules.Verification
python -B -m unittest test_utxo_db.TestUtxoDB.test_mempool_rejects_unpersistable_outputs_without_locking_input test_utxo_db.TestUtxoDB.test_apply_transaction_rejects_unpersistable_outputs -v-> 2 passedpython -m py_compile node\utxo_db.py node\test_utxo_db.py-> passedpython -B node\test_utxo_db.py-> 73 passedgit diff --check -- node\utxo_db.py node\test_utxo_db.py-> passedpython tools\bcos_spdx_check.py --base-ref origin/main-> BCOS SPDX check: OKBounty
Claiming under Scottcjn/rustchain-bounties#2819.
Requested severity: Medium, mempool DoS / invalid block-candidate manipulation.
Wallet/miner ID:
RTC74b80ab40602e5ae31819912b2fca974484e5dab