fix(net): restrict admission signature length#6782
Merged
kuny0707 merged 2 commits intoMay 26, 2026
Conversation
xxo1shine
approved these changes
May 19, 2026
This comment was marked as resolved.
This comment was marked as resolved.
3for
reviewed
May 26, 2026
317787106
reviewed
May 26, 2026
6ac1c2c to
3eceacc
Compare
317787106
approved these changes
May 26, 2026
3for
approved these changes
May 26, 2026
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.
What does this PR do?
Adds a signature-length range check at broadcast / P2P admission entrypoints, before any signature recovery work is done. Accepted sizes are
[PER_SIGN_LENGTH, MAX_PER_SIGN_LENGTH]=[65, 68]:Wallet.broadcastTransactionrejects the transaction withSIGERRORwhen any signature in the list falls outside[65, 68].TransactionsMsgHandler.checkthrowsP2pException(BAD_TRX)when any signature in aTransactionsMessagefalls outside[65, 68], causing the peer to be disconnected withBAD_TX.RelayService.checkHelloMessagereturnsfalsewhen theHelloMessagesignature from a fast-forward peer falls outside[65, 68].The predicate is centralized in
SignUtils.isValidLength(int size); all three call sites now share that helper. The bounds live inConstant.PER_SIGN_LENGTH(= 65) andConstant.MAX_PER_SIGN_LENGTH(= 68).Why are these changes required?
A canonical TRON ECDSA signature is encoded as 65 bytes (
r32 +s32 +v1). The affected entrypoints currently pass malformed admission payloads intoSignUtils.signatureToAddress/ signature recovery first, which wastes CPU before the request is rejected or fails later.This PR adds a cheap length check at the network and broadcast boundaries so invalid admission payloads fail before crypto recovery is attempted. This is intentionally scoped to admission handling only.
Why
[65, 68]instead of strict== 65?A canonical signature is 65 bytes. Historical on-chain data, however, contains transactions with a small amount of trailing padding (up to 3 bytes) that ECDSA recovery silently ignores. Using
MAX_PER_SIGN_LENGTH = 68closes the previously unbounded encoding window at admission while remaining tolerant of clients that may still produce the legacy padded form.The long-term goal is to tighten the rule once the compatibility window is no longer needed. Because the bounds are centralized in
Constantand the predicate is centralized inSignUtils.isValidLength, that tightening is a one-line change.Consensus compatibility
This PR does not change transaction validation for blocks or any shared consensus validation path.
In particular,
TransactionCapsule.checkWeightkeeps the loosersig.size() < 65check so historical signatures with trailing padding remain valid; longer signatures continue to be parsed by the existingRsv.fromSignaturebehavior using the first 65 bytes. Tightening that shared validation path would be a consensus-impacting behavior change and is intentionally not part of this PR.To keep this rule visible to future readers,
SignUtils.isValidLengthcarries a javadoc that names the admission-vs-consensus split and points atTransactionCapsule.checkWeightso the next reviewer who greps either operator lands on the explanation.The observable behavior change is limited to local broadcast / P2P admission:
[65, 68]now receiveSIGERRORbefore downstream checks.[65, 68]are rejected at message admission withBAD_TX.[65, 68]are rejected before signature recovery.This PR has been tested by:
WalletMockTest#testBroadcastTxInvalidSigLength: 64 / 69 / empty signatures returnSIGERROR; 65-byte and 68-byte (upper bound) signatures fall through.TransactionsMsgHandlerTest#testInvalidSigLength: 64 / 69 signatures raiseP2pException(BAD_TRX)viaassertThrows; 65-byte and 68-byte signatures pass the new length check.RelayServiceTest#testCheckHelloMessage: extended to assert that 64 / 69 / emptyHelloMessagesignatures returnfalse; the existing 65-byte case still returnstrue../gradlew :framework:checkstyleMain :framework:checkstyleTest./gradlew :framework:test --tests "org.tron.core.WalletMockTest.testBroadcastTxInvalidSigLength" --tests "org.tron.core.net.messagehandler.TransactionsMsgHandlerTest.testInvalidSigLength" --tests "org.tron.core.net.services.RelayServiceTest.testCheckHelloMessage"Follow up
None.