Skip to content

bitcoin-tx: validate range of parsed output amount - #22193

Closed
theStack wants to merge 1 commit into
bitcoin:masterfrom
theStack:202106-bitcoin-tx-validate_money_range
Closed

theStack wants to merge 1 commit into
bitcoin:masterfrom
theStack:202106-bitcoin-tx-validate_money_range

Conversation

@theStack

@theStack theStack commented Jun 8, 2021

Copy link
Copy Markdown
Contributor

This tiny PR adds a sanity check to the bitcoin-tx tool w.r.t. to tx output values specified by the user: the parsing function ExtractAndValidateValue is extended to throw if the amount is not in range [0, MAX_MONEY].

master:

$ bitcoin-tx -create outdata=21000001:affe
0200000000010021fd5ff0750700046a02affe00000000

PR branch:

$ bitcoin-tx -create outdata=21000001:affe
error: TX output value out of range

@practicalswift

Copy link
Copy Markdown
Contributor

Concept ACK

Non-blocking thought: I guess it could be argued that bool ParseMoney(const std::string& str, CAmount& nRet) should return false if !MoneyRange(nRet).

Can we see a use case for ParseMoney where it shouldn't be immediately followed by a MoneyRange check?

@maflcko

maflcko commented Jun 10, 2021

Copy link
Copy Markdown
Member

Agree with @practicalswift that neither fees nor fee rates larger than MAX_MONEY make any sense.

See also:

Finally, ParseMoney could be changed to return std::optional<CAmount>.

@DrahtBot

DrahtBot commented Jun 11, 2021 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@theStack

theStack commented Aug 3, 2021

Copy link
Copy Markdown
Contributor Author

PR #22220 includes putting the MoneyRange check into ParseMoney, so this PR can be closed.

@theStack theStack closed this Aug 3, 2021
fanquake added a commit that referenced this pull request Aug 24, 2021
f7752ad util: check MoneyRange() inside ParseMoney() (fanquake)
5ef2738 util: make ParseMoney return a std::optional<CAmount> (fanquake)

Pull request description:

  Related discussion in #22193.

ACKs for top commit:
  MarcoFalke:
    review ACK f7752ad 📄

Tree-SHA512: 88453f9e28f668deff4290d4bc0b2468cbd54699a3be1bfeac63a512276d309354672e7ea7deefa01466c3d9d826e837cc1ea244d4d74b4fa9c11c56f074e098
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants