Repository navigation
[UTXO-BUG] Fix dual-write transfer rejection on sub-micro absorbed fee dust (bounty #2819) - #8483
TomerGamerTV wants to merge 2 commits into
Conversation
Scottcjn#2819) Under UTXO dual-write mode (_dual_write=True), transfer requests with clean 6-decimal amounts and fees were rejected if coin selection absorbed sub-micro dust change (< DUST_THRESHOLD) into the transaction fee. Because UTXO boxes (e.g. from mining rewards or genesis migration) carry 8-decimal precision, absorbed dust often has non-zero 7th/8th decimals (such as 45 nRTC). Previously, _nrtc_to_account_i64 strictly enforced that the effective fee be an exact multiple of 100 nRTC, throwing ValueError and returning HTTP 400 'effective_fee_nrtc cannot be mirrored by dual-write account model', preventing legitimate senders from spending their funds. Fix this by deriving the dual-write shadow fee via integer division (effective_fee_nrtc // (UNIT // ACCOUNT_UNIT)), mirroring the whole microRTC fee units to the shadow account model while safely allowing sub-micro dust fee absorption on the UTXO side. Added comprehensive regression tests in node/test_utxo_endpoints.py.
|
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! |
Scottcjn
left a comment
There was a problem hiding this comment.
@TomerGamerTV — this one is a real finding, and I want to say that plainly given I rejected your last claim. The difference: this defect is reachable in the code, your two tests fail when I revert only utxo_endpoints.py, and the full test_utxo_endpoints.py + test_utxo_db.py run stays green (150 passed). The test-hygiene tidy is correct too: with sqlite3.connect(...) does not close the connection, so the explicit close() fixes a real fd leak.
I also checked the guard you might have weakened, and you didn't: the user-supplied fee_rtc is still validated to 6 dp up front (#8443 intact, test_dual_write_rejects_sub_micro_amounts still passes). Only the ≤99 nRTC coin-selection remainder is dropped, which converges a pre-existing divergence rather than creating one.
Reachability, measured on production just now:
SELECT COUNT(*) FROM utxo_boxes WHERE spent_at IS NULL AND value_nrtc % 100 != 0; -- 0
SELECT COUNT(*) FROM utxo_boxes WHERE value_nrtc % 100 != 0; -- 0
All 1,697 live boxes are micro-aligned (genesis derives them from balances ×100, and reward mints are ×100 too). So the bug is latent today, not live. That's why this is a change request rather than a rush merge: dual-write is now enabled in production, so this is live settlement/transfer code.
One change before merge: keep the truncation, but when effective_fee_nrtc % (UNIT // ACCOUNT_UNIT) != 0, log it (wallet, tx, remainder in nRTC). As written the truncation is silent, which would mask a genuine model divergence instead of surfacing it. Everything else looks right.
|
You want me to apply the one change you suggested? |
|
Queue sweep (2026-11-06): the branch conflicts with |
|
This PR has been inactive for 21 days. It will be closed in 14 days unless updated. |
Summary
Fixes a bug in
/utxo/transfer(node/utxo_endpoints.py) where legitimate transfer requests under_dual_write=Trueare rejected with HTTP 400 (Invalid amount: effective_fee_nrtc cannot be mirrored by dual-write account model (max 6 decimal places)) if UTXO coin selection absorbs sub-micro dust remainder into the effective transaction fee.Vulnerability & Root Cause Analysis
/utxo/transfer(production caller onmain).amount_rtc = 10.0,fee_rtc = 0).33,870,945nRTC or any remaindervalue_nrtc % 100 != 0).coin_select()selects the UTXO boxes. If the unspent change is belowDUST_THRESHOLD(1,000 nRTC / 10 uRTC),coin_selectabsorbs the change into the transaction fee (change = 0,absorbed_fee_nrtc = total - target_nrtc).node/utxo_endpoints.py:effective_fee_nrtc % 100 != 0(e.g.45nRTC), calling_nrtc_to_account_i64(effective_fee_nrtc, 'effective_fee_nrtc')raisesValueError: effective_fee_nrtc cannot be mirrored by dual-write account model (max 6 decimal places).Fix
fee_rtcis already validated upfront (_decimal_to_account_i64(fee_rtc, 'fee_rtc')) to have at most 6 decimal places.Verification & Tests
node/test_utxo_endpoints.py:test_dual_write_allows_sub_micro_absorbed_dust_fee: verifies transfer with 45 nRTC absorbed fee succeeds (HTTP 200), balances update properly, and/utxo/integritymodels agree.test_dual_write_allows_sub_micro_absorbed_dust_fee_with_multiple_micros: verifies absorbed fee with mixed microRTC and nanoRTC dust remainder (345 nRTC).node/test_utxo_endpoints.pyPASS.node/test_utxo_db.pyPASS.