Repository navigation
[UTXO-BUG] Reject non-string transfer memo before dual-write - #4833
Conversation
strongkeep-debug
left a comment
There was a problem hiding this comment.
Approved current head 9fbf4618a5e0a819333b3504a40e2a68276d50d7.
This is the right fix for the dual-write partial-commit case: the endpoint now rejects a non-string JSON memo before amount parsing, signature checks, nonce reservation, UTXO writes, or the dual-write shadow ledger path that slices memo[:30]. The new regression also exercises the important failure mode directly by seeding both UTXO and account state, sending an object memo, and confirming the request returns 400 while UTXO balances, balances, and ledger remain unchanged.
Validation performed:
git diff --check origin/main...HEAD -- node\utxo_endpoints.py node\test_utxo_endpoints.py-> passedpython -m py_compile node\utxo_endpoints.py node\test_utxo_endpoints.py-> passedpython -m pytest node\test_utxo_endpoints.py -q-> 19 passedpython -m ruff check node\utxo_endpoints.py node\test_utxo_endpoints.py --select E9,F821,F811 --output-format=concise-> passedpython tools\bcos_spdx_check.py --base-ref origin/main-> OK
GitHub checks are green on this head and the PR merge state is clean.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM. 🚀
chenzf534403209
left a comment
There was a problem hiding this comment.
Reviewed the non-string memo guard for /utxo/transfer.
The fix is narrowly placed before amount parsing, signature verification, nonce reservation, UTXO mutation, and dual-write shadow writes, which is the right point for this bug: malformed memo values now fail before any state can be committed. The new dual-write regression is also strong because it checks both ledgers after rejection: UTXO balances stay unchanged, the account-model balance remains at the seeded value, the recipient is not created, and no ledger rows are inserted.
Validation I ran locally on this PR:
python -m py_compile node\utxo_endpoints.py node\test_utxo_endpoints.py-> passedgit diff --check origin/main...HEAD -- node\utxo_endpoints.py node\test_utxo_endpoints.py-> passedpython -m pytest node\test_utxo_endpoints.py -q-> 19 passedpython tools\bcos_spdx_check.py --base-ref origin/main-> OKpython -m pytest node\test_utxo_endpoints.py tests\test_utxo_transfer_replay.py -q-> 19 passed before the two known Windows temp-DB unlink failures intests/test_utxo_transfer_replay.py
I did not find a blocker in this patch. ruff is not installed in my local Python environment, so I could not independently rerun that check.
Review bounty context: Scottcjn/rustchain-bounties#73
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM. 🚀
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM. 🚀
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM. 🚀
godd-ctrl
left a comment
There was a problem hiding this comment.
Approved current head 9fbf461 after independently reviewing the non-string memo guard. The check rejects malformed optional memo values before signature verification, nonce reservation, UTXO mutation, or dual-write account/ledger shadow writes. The regression covers the important partial-commit failure mode by asserting the object-memo request returns 400 while sender/recipient UTXO state, account balances, and ledger rows remain unchanged. Validation: python -m pytest node\test_utxo_endpoints.py -q -> 19 passed; python -m py_compile node\utxo_endpoints.py node\test_utxo_endpoints.py -> passed; git diff --check origin/main...HEAD -- node\utxo_endpoints.py node\test_utxo_endpoints.py -> passed; python tools\bcos_spdx_check.py --base-ref origin/main -> OK; uv run --no-project --with ruff python -m ruff check node\utxo_endpoints.py node\test_utxo_endpoints.py --select E9,F821,F811 --output-format=concise -> passed. No live node, wallet, or production endpoint was exercised.
508704820
left a comment
There was a problem hiding this comment.
Code Review: Reject Non-String Transfer Memo Before UTXO Commit
Summary
Validates that the memo field in UTXO transfers is a string before committing any database state. This prevents a partial-write bug where non-string memos could commit UTXO boxes but fail on the shadow/ledger write, leaving the database in an inconsistent state.
What Works Well
- Prevents partial writes: Validates memo before any database mutation
- 71-line test: Comprehensive test that verifies rejection and that no state was committed
- Correct order: Validation → dual write → commit, not commit → validate
- Database consistency check: Test verifies sender balance is unchanged after rejection
Issues Found
1. Low — What other fields could cause partial writes?
If any other user-supplied field (amount, address, signature) has a type mismatch that fails after UTXO commit, the same partial-write bug could occur. Consider a comprehensive validation step before any database writes:
# Validate ALL fields before touching the database
errors = validate_all_fields(payload)
if errors:
return jsonify({"error": errors}), 400
# Only now begin database operations2. Nit — Test uses direct SQL to set up state
The test manually creates ledger table and inserts data. This is fine for testing but fragile if the schema changes. Consider using the application's own setup functions.
Verdict: Approve
Important data integrity fix. The comprehensive validation suggestion is worth considering.
|
Review for Scottcjn/rustchain-bounties#73. I reviewed the non-string memo guard and the dual-write regression. The placement is good: the endpoint rejects Actionable coverage notes:
Overall this fixes the commit-before-shadow-write failure mode cleanly. I would merge with the additional |
|
Updated the PR to address the coverage note about other non-string memo shapes. New head: Change:
Validation rerun:
|
508704820
left a comment
There was a problem hiding this comment.
Code Review — #4833
1. Correct fix — validates memo type before dual-write
Rejecting non-string memos before the UTXO commit prevents state corruption where the primary database commits but the shadow/ledger write fails due to type mismatch.
2. Test coverage is thorough
The test test_dual_write_rejects_non_string_memo_before_utxo_commit directly verifies that:
- A non-string memo is rejected
- The UTXO balance is not changed (sender still has 100 UNIT)
- No partial commit occurs
3. Defense-in-depth approach
This fix follows the "validate early, reject before mutation" pattern which is the correct approach for financial transaction systems. Never let invalid data reach the commit stage.
4. Consider also validating memo content
Beyond type checking, consider:
- Length limiting (prevent arbitrarily long memos)
- Character set validation (reject control characters, null bytes)
- Encoding validation (ensure valid UTF-8)
— Xeophon
godd-ctrl
left a comment
There was a problem hiding this comment.
Approved current head b05c69e.
The updated guard rejects non-string memo values before signature verification, nonce reservation, UTXO mutation, or dual-write account/ledger writes. The expanded regression covers object, null, and list memo payloads and confirms the sender/recipient UTXO balances, account balance row, and ledger row count remain unchanged after each rejected request.
Validation performed:
- git diff --name-status origin/main...HEAD -> node/utxo_endpoints.py, node/test_utxo_endpoints.py
- git diff --check origin/main...HEAD -> passed
- python tools\bcos_spdx_check.py --base-ref origin/main -> passed
- python -m py_compile node\utxo_endpoints.py node\test_utxo_endpoints.py -> passed
- python -m pytest node\test_utxo_endpoints.py -q -> 19 passed, 3 subtests passed
No blocking issues found in the reviewed diff.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
jaxint
left a comment
There was a problem hiding this comment.
Great contribution! LGTM.
loganoe
left a comment
There was a problem hiding this comment.
Approved. The memo type guard runs before the UTXO commit path, so object/list/null memos are rejected cleanly and do not leave partial UTXO or dual-write ledger state behind.
Validation performed:
git diff --check origin/main...HEADpython3 -m py_compile node/utxo_endpoints.py node/test_utxo_endpoints.pyPYTEST_DISABLE_PLUGIN_AUTOLOAD=1 /tmp/rustchain-flask-venv/bin/python -m pytest -q node/test_utxo_endpoints.py-> 19 passed, 3 subtests passed
shuibui
left a comment
There was a problem hiding this comment.
Code Review: Good Fix
Approve.
**Verdict: Approve.
TJCurnutte
left a comment
There was a problem hiding this comment.
Reviewed the UTXO non-string memo guard.
Validation run on the PR head:
python3 -m py_compile node/utxo_endpoints.py node/test_utxo_endpoints.py-> passed- Focused regression with node on
PYTHONPATHpassed:
PYTHONPATH=node PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --no-project --with flask python -m unittest test_utxo_endpoints.TestUtxoEndpoints.test_dual_write_rejects_non_string_memo_before_utxo_commit-> OK - Local static smoke check confirmed the guard is before transfer processing and returns
memo must be a string-> passed git diff --check origin/main...HEAD-> passedpython3 tools/bcos_spdx_check.py --base-ref origin/main-> OK
The regression covers dict, null, and list memo values and verifies no UTXO, balance, or ledger mutation occurs on rejection. This is the right failure point before dual-write side effects.
himanalot
left a comment
There was a problem hiding this comment.
Reviewed PR #4833 against the current diff. The patch rejects non-string memo values immediately after parsing the request body, before signature verification, nonce reservation, UTXO application, or dual-write shadow ledger updates. That directly prevents the reported partial-commit path where UTXO state could change and the account-model write later failed on memo[:30].
The regression test covers object, null, and list memo values and verifies no UTXO balance, account balance, or ledger mutation occurs. No blocking issues found.
/claim #2819
Summary
/utxo/transfermemovalues before signature verification, nonce reservation, UTXO commit, or dual-write shadow writes.Bug / Impact
With
dual_write=True, the current endpoint accepts a JSON object memo. The UTXO transaction commits first, then the account-model shadow write tries to slicememo[:30], raisesTypeError, catches it in the broad dual-write exception handler, and still returns HTTP 200.That leaves the UTXO model debited/credited while
balancesandledgerremain unchanged. In the local repro, a 10 RTC transfer withmemo: {bad:memo}returned 200, moved UTXO balances to sender=90 RTC and recipient=10 RTC, but leftbalancesat sender=100 RTC and inserted zero ledger rows.Validation
git diff --check -- node/utxo_endpoints.py node/test_utxo_endpoints.py-> passedpython -m py_compile node\utxo_endpoints.py node\test_utxo_endpoints.py-> passedpython -m pytest node\test_utxo_endpoints.py -q-> 19 passedpython -m ruff check node\utxo_endpoints.py node\test_utxo_endpoints.py --select E9,F821,F811 --output-format=concise-> passedpython tools\bcos_spdx_check.py --base-ref origin/main-> OKNote:
python -m pytest node\test_utxo_endpoints.py tests\test_utxo_transfer_replay.py -qruns my focused suite successfully, then hits existing Windows cleanup locks intests/test_utxo_transfer_replay.pywhile unlinking temp DB files. I did not bundle that unrelated cleanup here because it is outside this fix.Wallet/miner ID:
RTC253255d034065a839cd421811ec589ae5b694ffc