Skip to content

standalone: Reject bad input values in tx sanity.#3677

Open
davecgh wants to merge 2 commits intodecred:masterfrom
davecgh:standalone_checktxsanity_reject_inputs
Open

standalone: Reject bad input values in tx sanity.#3677
davecgh wants to merge 2 commits intodecred:masterfrom
davecgh:standalone_checktxsanity_reject_inputs

Conversation

@davecgh
Copy link
Copy Markdown
Member

@davecgh davecgh commented Apr 17, 2026

Transactions with input values that are negative or greater than the max supply ultimately will always eventually end up invalid by checks performed much later in the validation process. Moreover, the aforementioned conditions are entirely context free.

Given that, it is much more efficient and robust to simply reject any transactions that violate them as early as possible in the validation process.

The context-free transaction sanity checks are the ideal location since they are among the earliest validation checks that are performed.

However, unconfirmed transactions are allowed to leave the input value set to the special sentinel value of -1 (wire.NullValueIn) that signals the actual value will be filled in later. The sanity checks take place before that information is available to populate, so that case needs to be exempted and left for the later checks to reject as they already do now.

With that in mind, this modifies CheckTransactionSanity to reject transactions that violate those conditions accordingly.

It also adds ErrFraudAmountIn to uniquely identify when checks fail validation for that reason.

Finally, it modifies the rule error conversion in the internal blockchain code to recognize and convert the new error.

Additional tests are included in a second commit to test the new checks work as expected.

davecgh added 2 commits April 16, 2026 23:23
Transactions with input values that are negative or greater than the max
supply ultimately will always eventually end up invalid by checks
performed much later in the validation process.  Moreover, the
aforementioned conditions are entirely context free.

Given that, it is much more efficient and robust to simply reject any
transactions that violate them as early as possible in the validation
process.

The context-free transaction sanity checks are the ideal location since
they are among the earliest validation checks that are performed.

However, unconfirmed transactions are allowed to leave the input value
set to the special sentinel value of -1 (wire.NullValueIn) that signals
the actual value will be filled in later.  The sanity checks take place
before that information is available to populate, so that case needs to
be exempted and left for the later checks to reject as they already do
now.

With that in mind, this modifies CheckTransactionSanity to reject
transactions that violate those conditions accordingly.

It also adds ErrFraudAmountIn to uniquely identify when checks fail
validation for that reason.

Finally, it modifies the rule error conversion in the internal
blockchain code to recognize and convert the new error.
This adds a few additional tests for transaction sanity checking to
ensure negative values, except the special sentinel value, and values
greater than the max supply are rejected as expected.
@davecgh davecgh added this to the 2.2.0 milestone Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants