authorization: reject bodies with the wrong number of authorizations#32
Open
ace-degen wants to merge 1 commit into
Open
authorization: reject bodies with the wrong number of authorizations#32ace-degen wants to merge 1 commit into
ace-degen wants to merge 1 commit into
Conversation
`verify_authorizations` paired `body.authorizations` with the per-input messages using `.zip()`, which stops at the shorter iterator. A body carrying fewer authorizations than inputs was therefore accepted, leaving the surplus inputs unverified. Because block validation reaches this code via `Authorization::verify_body`, a miner could spend a UTXO without a valid signature by ordering an authorized input first and omitting the authorization for the victim's input -- a consensus-level authorization bypass (theft). The address-binding `.zip()` in `state::block::validate_body` has the same truncation, but it is gated behind `verify_body`, so enforcing the count in one place closes both. Add an explicit count check at the top of `verify_authorizations`, returning `NotEnoughAuthorizations` / `TooManyAuthorizations`, mirroring the sibling Rust L2s (e.g. Thunder). Add regression tests for too-few, too-many, and matching authorization counts.
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.
Summary
verify_authorizationspairsbody.authorizationswith the per-input messages using.zip(), which stops at the shorter iterator. A body carrying fewer authorizations than inputs is therefore accepted, and the surplus inputs are never signature-checked.Block validation reaches this code via
Authorization::verify_body(lib/state/block.rs→verify_body→verify_authorizations), so the gap is consensus-critical: a miner can spend a UTXO without a valid signature by ordering an authorized input first and omitting the authorization for the victim's input. The address-binding.zip()instate::blockhas the same truncation, but it is gated behindverify_body, so enforcing the count in one place closes both.Comparison with sibling L2s
Thunder, CoinShift, Photon, and Truthcoin-DC all reject a count mismatch before signature verification.
plain-bitassetsis missing this check. This PR adds the same guard, matching theNotEnoughAuthorizations/TooManyAuthorizationsidiom used elsewhere.Change
Error::NotEnoughAuthorizationsandError::TooManyAuthorizations.verify_authorizations, comparebody.authorizations.len()against the total input count and reject any mismatch.Testing
Full
cargo test --libpasses;cargo fmt --checkandcargo clippy --libare clean.