Skip to content

fix(api): bound and truncate sign api signatures#6820

Open
Federico2014 wants to merge 2 commits into
tronprotocol:release_v4.8.2from
Federico2014:fix/getapprovedlist-sig-limit
Open

fix(api): bound and truncate sign api signatures#6820
Federico2014 wants to merge 2 commits into
tronprotocol:release_v4.8.2from
Federico2014:fix/getapprovedlist-sig-limit

Conversation

@Federico2014
Copy link
Copy Markdown
Collaborator

@Federico2014 Federico2014 commented Jun 4, 2026

What does this PR do?

Hardens the two read-only signature APIs — getTransactionApprovedList (/wallet/getapprovedlist) and getTransactionSignWeight — against CPU exhaustion and oversized-signature echo-back.

1. Bound the recovery loop (CPU DoS)

Wallet.getTransactionApprovedList previously ran a hand-rolled unbounded ecrecover loop. Replaced by delegation to TransactionCapsule.checkWeight, matching getTransactionSignWeight. checkWeight rejects up front when sigs.size() > permission.getKeysCount(), before any signature recovery.

2. Reject excessive signature counts at entry

Both APIs now check trx.getSignatureCount() > getTotalSignNum() as the very first step, returning OTHER_ERROR / "too many signatures" immediately. This is a zero-cost guard that mirrors the bound already enforced by the consensus signature-verification path.

3. Truncate oversized signatures at entry

TransactionCapsule.truncateSignatures(trx) truncates any signature > 65 bytes to its first 65 bytes. Called at the top of both methods, before checkWeight. The echoed-back transaction is also set on the response builder at entry, so error paths return the truncated form too — no path leaks untruncated signatures.

4. Harden checkWeight error message

weight == 0 path previously hex-encoded sig.toByteArray() (potentially oversized) into the exception message. Changed to the transaction hash (hash), a fixed 32-byte value that is more useful for debugging and cannot bloat error responses. This protects all callers of checkWeight, including consensus paths.

Why are these changes required?

getTransactionApprovedList was the only signature-recovery path without a bound on signature count. A single unauthenticated request with thousands of padded signatures could trigger unbounded ecrecover calls. Signature truncation and the error-message fix ensure clean, bounded, canonical responses on every code path.

This PR has been tested by

  • testApprovedListSigBound — signature within keysCount succeeds; exceeding keysCount rejected before recovery
  • testApprovedListSigTruncate — 70-byte signature truncated to 65 bytes, signer still recovered
  • testApprovedListTooManySigs — exceeding getTotalSignNum() rejected at entry with "too many signatures"
  • testSignWeightSigTruncate — same truncation test for getTransactionSignWeight
  • testSignWeightTooManySigs — same total-sign-num guard test for getTransactionSignWeight
  • Full WalletTest, TransactionUtilTest, RpcApiServicesTest — all green
  • :framework:checkstyleMain, :framework:checkstyleTest — clean

Follow up

None.

Extra details

getTransactionApprovedList now delegates to checkWeight, applying the same permission semantics as getTransactionSignWeight. Behavioral changes:

  • Too many signatures: the signature count exceeds permission.getKeysCount().
  • Signature not in the permission: a recovered address is not one of the permission keys (weight 0).
  • Duplicate signer: the same address signs more than once.

Callers that relied on the old "recover any signature" behavior to probe arbitrary signer addresses will see stricter results. No database, consensus, or config changes; read-only API paths only.

Comment thread framework/src/main/java/org/tron/core/Wallet.java
Comment thread framework/src/main/java/org/tron/core/Wallet.java Outdated
Comment thread framework/src/main/java/org/tron/core/Wallet.java
@Federico2014 Federico2014 force-pushed the fix/getapprovedlist-sig-limit branch from b13b51a to dfe3346 Compare June 4, 2026 08:40
@lvs0075 lvs0075 added this to the GreatVoyage-v4.8.2 milestone Jun 4, 2026
@Federico2014 Federico2014 force-pushed the fix/getapprovedlist-sig-limit branch from dfe3346 to 95599ad Compare June 4, 2026 09:43
@Federico2014 Federico2014 force-pushed the fix/getapprovedlist-sig-limit branch from 95599ad to a9bdbae Compare June 4, 2026 09:58
@halibobo1205 halibobo1205 added the topic:api rpc/http related issue label Jun 4, 2026
@KingsDmusk
Copy link
Copy Markdown

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:api rpc/http related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants