fix(net): enforce 65-byte signature length#6782
Open
Federico2014 wants to merge 1 commit into
Open
Conversation
xxo1shine
approved these changes
May 19, 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 strict 65-byte length check on signatures received at broadcast / P2P admission entrypoints, before any signature recovery work is done:
Wallet.broadcastTransactionrejects the transaction withSIGERRORwhen any signature in the list is not 65 bytes.TransactionsMsgHandler.checkthrowsP2pException(BAD_TRX)when any signature in aTransactionsMessageis not 65 bytes, causing the peer to be disconnected withBAD_TX.RelayService.checkHelloMessagereturnsfalsewhen theHelloMessagesignature from a fast-forward peer is not 65 bytes.The constant
Constant.PER_SIGN_LENGTH(= 65) is reused everywhere.Why are these changes required?
A TRON transaction / hello 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.
Consensus compatibility
This PR does not change transaction validation for blocks or any shared consensus validation path.
In particular,
TransactionCapsule.checkWeightcurrently rejects signatures shorter than 65 bytes, while longer signatures are 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.The observable behavior change is limited to local broadcast / P2P admission:
SIGERRORbefore downstream checks.BAD_TX.This PR has been tested by:
WalletMockTest#testBroadcastTxInvalidSigLength: 64 / 66 / empty signatures returnSIGERROR; 65-byte signature falls through.TransactionsMsgHandlerTest#testInvalidSigLength: 64 / 66 / empty signatures raiseP2pException(BAD_TRX)viaassertThrows; 65-byte signature passes the new length check.RelayServiceTest#testCheckHelloMessage: extended to assert that 64 / 66 / 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.