Skip to content

fix(net): enforce 65-byte signature length#6781

Closed
Federico2014 wants to merge 5 commits into
tronprotocol:developfrom
Federico2014:fix/limit_sig_length_65
Closed

fix(net): enforce 65-byte signature length#6781
Federico2014 wants to merge 5 commits into
tronprotocol:developfrom
Federico2014:fix/limit_sig_length_65

Conversation

@Federico2014
Copy link
Copy Markdown
Collaborator

What does this PR do?

Adds a strict 65-byte length check on signatures received over the
network and the broadcast API, before any signature recovery work is
done:

  • Wallet.broadcastTransaction — rejects the transaction with
    SIGERROR when any signature in the list is not 65 bytes.
  • TransactionsMsgHandler.check — throws P2pException(BAD_TRX) when
    any signature in a TransactionsMessage is not 65 bytes, causing the
    peer to be disconnected with BAD_TX.
  • RelayService.checkHelloMessage — returns false when the
    HelloMessage signature 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 valid TRON ECDSA/SM2 signature is exactly 65 bytes (r 32 + s 32 +
v 1). Today these entrypoints will still feed a malformed signature
into SignUtils.signatureToAddress / signature recovery, which wastes
CPU on payloads that can never validate, and lets a peer cheaply force
expensive work by sending arbitrary-length blobs. A fast length check
up front rejects the payload before any crypto runs and keeps the
failure mode uniform across the three entrypoints.

This PR has been tested by:

  • Unit Tests
    • WalletMockTest#testBroadcastTxInvalidSigLength — 64 / 66 / empty
      signatures return SIGERROR; 65-byte signature falls through.
    • TransactionsMsgHandlerTest#testInvalidSigLength — 64 / 66 / empty
      signatures raise P2pException(BAD_TRX) via assertThrows.
    • RelayServiceTest#testCheckHelloMessage — extended to assert that
      64 / 66 / empty HelloMessage signatures return false; the
      existing 65-byte case still returns true.
  • Manual Testing
    • ./gradlew :framework:checkstyleMain :framework:checkstyleTest
    • ./gradlew :framework:test --tests "...RelayServiceTest" etc.

Follow up

None.

Extra details

No protocol or storage change. Behavior change is observable only for
peers / clients that previously sent non-65-byte signatures, which
would have failed signature recovery downstream anyway — now they fail
faster and with a clearer error.

317787106 and others added 5 commits May 10, 2026 16:09
* fix(config): remove redundant JSON-RPC config fields and consolidate parameter binding

Remove maxBlockFilterNum, maxAddressSize, and maxRequestTimeout from NodeConfig/CommonParameter
since they were superseded by the jsonRpcMaxBatchSize/jsonRpcMaxResponseSize parameters.
Consolidate the config binding path so all JSON-RPC size limits flow through a single
reference.conf entry, and clean up stale test-config fixtures.

* fix bug of NodeConfigTest

* remove allowShieldedTransactionApi from reference.conf

* add testcase of external.ip is null

* change comment

* fix the bug of --es and 7 failed testcases
…onprotocol#6760)

Pre-3.0.0(The previous event-plugin public release is 2.2.0)
event-plugin builds still link against com.alibaba.fastjson, which
was removed from java-tron in tronprotocol#6701. When such a plugin is loaded, the
NoClassDefFoundError surfaces inside the plugin's own worker thread and is
swallowed by its catch(Throwable) handler. The node keeps running while
silently dropping every trigger, leaving operators with no signal that the
event subscription is broken.

Enforce a minimum Plugin-Version at startup in EventPluginLoader.startPlugin
using pf4j's VersionManager (semver). When the descriptor version is below
3.0.0, log a clear upgrade hint and return false; the existing call chain in
Manager.startEventSubscribing wraps that into TronError(EVENT_SUBSCRIBE_INIT)
and aborts node startup instead of silently degrading.
…rs (tronprotocol#6761)

- Add `rate.limiter.apiNonBlocking` switch (default false). When off, callers wait for a permit; when on, they reject immediately and shed load.
- Wire the switch through `RateLimiterConfig` → `Args` → `CommonParameter`; update `reference.conf` / `config.conf`.
- Add blocking `acquire()` paths on `IRateLimiter`, `GlobalRateLimiter`, and `QpsStrategy` / `IPQpsStrategy` / `GlobalPreemptibleStrategy`. Only the semaphore-based strategy is bounded (2s); the QPS-based paths use unbounded Guava `RateLimiter.acquire()`.
- Introduce `acquirePermit()` dispatcher (default method on `IRateLimiter`; static on `GlobalRateLimiter`) that picks blocking vs non-blocking based on the switch.
- Swap `tryAcquire` → `acquirePermit` at the `RateLimiterServlet` and `RateLimiterInterceptor` call sites; preserve per-endpoint-before-global ordering to avoid consuming global quota on per-endpoint rejection.
- Extract `loadIpLimiter()` in `GlobalRateLimiter` and `loadLimiter()` in `IPQpsStrategy` to share cache+exception handling between `tryAcquire` and `acquire`.
- Add unit tests covering dispatcher routing (both directions), acquire IP-before-global ordering, and IP-loader-failure fail-closed behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants