fix(net): enforce 65-byte signature length#29
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
2 issues found across 6 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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.