mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:29:40 +00:00
wallet: reject recipient amounts above MAX_MONEY #36342
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36342
Loading…
Reference in a new issue
No description provided.
Delete branch "fix-recipients-sum-overflow"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CreateTransactionchecks that recipient amounts aren't negative, but not that they're withinMAX_MONEY.CreateTransactionInternalthen sums them intorecipients_sum(spend.cpp:1100) with no range check, and that sum can overflow.Easiest way to hit it is
fundrawtransactionwith a raw tx that has two outputs of 2^62 sat. It can also be reached with only valid amounts throughwalletcreatefundedpsbt/send/sendmanyand a few thousand 21M BTC outputs. The "Transaction too large" check only runs after coin selection, so it doesn't stop this. On master the node aborts:UBSan reports the overflow at spend.cpp:1100 first. With other values the sum wraps to a small positive number instead, and
fundrawtransactionreturns success for a tx with outputs of 46116860184 BTC each.This checks every amount and the running sum against
MoneyRangein the existing recipients loop ofCreateTransactionInternal, before the amount is added torecipients_sum, and returns "Transaction output amount must be valid" before coin selection starts. The same check rejects negative amounts, so the separate negative check inCreateTransactionis removed. The newtest_outputs_above_max_moneyinwallet_fundrawtransaction.pycovers a single output above MAX_MONEY, two outputs whose sum is above it, a sum that overflows int64, and a negative output. On master the first case returns "Insufficient funds" and the overflow case crashes the node; with the fix all of them get the new error.wallet_fundrawtransaction.py,wallet_send.py,wallet_basic.pyandrpc_psbt.pypass.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
No conflicts as of last run.
You just opened three PRs in ten minutes. Do all three of these conform to our AI Policy? Before we spend any precious human resources reading through your submissions can you please assure us that you understand all the choices you've made and that you are motivated by solving real problems real users have with the software?
Yes, I've read the AI policy and I accept it. And yes, I used AI, but only for the PR description and the tests. Finding the bug and the rest of the underlying work was done by me.
About the 3 PRs: I've been preparing for PRs for the last few days, and it made more sense to me to collect all the bugs I found and send them at the same time.
You now have 7 PRs open in two days, and you are a brand new contributor. If you really want to support the project I suggest closing 6 of them. Pick one that really means a lot to you, that you think is the most important for the most bitcoin users, and really commit to it. Show us that you the human cares about the project and is willing to put in the time and the hard work that the rest of us put in.
Earn your reputation here by starting slow.
We do not need another "AI operator" pasting claude output, that will result in a ban.
🔵 Suggestion · An oversized total is reported as an invalid output amount
When individually in-range outputs total more than MAX_MONEY, fundrawtransaction reports an invalid output amount rather than explaining that the total exceeds the limit.
Location:
src/wallet/spend.cpp:1094(head).🔵 Suggestion · The overflow test does not cover amount-check ordering
The first 2**62 output is rejected immediately, so this functional test would still pass if the running-sum expression were evaluated before validating the individual amount.
Location:
test/functional/wallet_fundrawtransaction.py:180(head).Review coverage was incomplete.
Reviewed:
bab579e56aa8· Full review report · Previous reportspermalink
lgtm ACK
f2915243d6Seems fine as a low-prio sanity check and for nicer sanitizer use
nit: I think you can combine this check/loop and have the error message just be "Transaction output amount must be valid". this avoids two loops and overly strict hand holding for errors that should never happen anyway.
Done: the negative-amount check is folded into the MoneyRange loop, with the single "Transaction output amount must be valid" error. (Changes prepared with AI tools.)
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits
Can move the check below the existing loop:
github.com/bitcoin/bitcoin@dc2a9987aa/src/wallet/spend.cpp (L1092-L1097)and could also merge the negative amount checks there too. So it is just one loop.
Squashed into one commit (
bab579e56a). Following furszy, the MoneyRange check now sits in the existing recipients loop inCreateTransactionInternal, and it also covers the negative-amount case, so the separate check inCreateTransactionis gone. Added a negative output to the test. (Changes prepared with AI tools.)Please write your own pull request descriptions. I find yours currently hard to read. Putting things into your own words focusing on why this change is being made makes it easier for reviewers.
lgtm ACK
bab579e56aSeems fine as a style cleanup with test coverage and to make sanitizers happy while fuzzing (not sure if anyone is doing this)
tACK
bab579e56aTested on macOS 27.0.1 arm64, comparing against master
49c3c7fe09. The PR’swallet_fundrawtransaction.pyfails on master withInsufficient fundsinstead ofTransaction output amount must be valid, and passes on the PR.I also checked these cases manually on regtest:
The abort on master reports:
With the PR, all four calls return RPC error -4 and the node remains running.
utACK
bab579e56anano nit: could move the
!MoneyRange(recipients_sum + recipient.nAmount)here so it just checks for!MoneyRange(recipients_sum)instead.I think it is nice to have a single check and error for this kind, so I'd prefer to leave as-is
@Bruce039 That is the part where AI is not allowed to be used, per the policy. Can you please write the description briefly in your own words? No one wants to read stuff like "the tests passed", etc. The CI runs the tests and any reviewer is welcome to test themselves.
ACK
bab579e56abytearrayis unnecessary