Reject blocks and transactions with the wrong number of authorizations - #36
Merged
Merged
Conversation
Ash-L2L
approved these changes
Jun 15, 2026
Ash-L2L
force-pushed
the
fix/auth-count-check
branch
from
June 16, 2026 17:32
1f2d8a6 to
dacd927
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Authorizations were paired with inputs positionally via
zip, with no check that the two counts match. Becausezipstops at the shorter iterator, supplying fewer authorizations than there are inputs requiring one left the surplus inputs completely unverified, both the address check and the signature check simply skipped them.This allowed any UTXO to be spent without a valid signature. In the extreme case, a transaction (or whole block body) with zero authorizations passes validation: the address-check
zipand the batch signature verification both run over empty input sets and succeed. Since the blockHeadercommits only to the merkle root (which does not cover authorizations), a single crafted block could spend arbitrary UTXOs i.e. steal any funds on the chain.Fix
Enforce an exact authorization count at all three validation entry points, before the existing
zip-based address/signature checks:block::validate— block validationblock::prevalidate— the pathapply_blockactually uses when connectingState::validate_transaction— mempool admissionThe required count is computed from
spent_utxos_requiring_auth()rather than the raw input count, so legitimate batch-ICANN transactions which intentionally carry fewer authorizations than inputs still validate. A newError::WrongNumberOfAuthorizations { expected, received }variant is returned on mismatch.Test
Adds
validate_transaction_rejects_missing_authorization, which funds an address, then attempts to spend the UTXO with an empty authorization list and asserts it is rejected withWrongNumberOfAuthorizations { expected: 1, received: 0 }. It also confirms the same transaction validates once a correctauthorization is supplied.
Verified the test fails against the unpatched code (the unauthorized spend is accepted and returns a fee of 100 sat) and passes with the fix applied.