Skip to content

fix(jsonrpc): preserve memos on smart contract transactions - #7120

Closed
Federico2014 wants to merge 4 commits into
tronprotocol:release_v4.8.3from
Federico2014:fix/jt-957-contract-extra-data
Closed

Federico2014 wants to merge 4 commits into
tronprotocol:release_v4.8.3from
Federico2014:fix/jt-957-contract-extra-data

Conversation

@Federico2014

@Federico2014 Federico2014 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

JSON-RPC buildTransaction now writes extraData to raw_data.data for smart contract deployments and calls. The memo is included in the unsigned transaction and its txID, alongside the deployment bytecode or call data.

  • When visible is omitted or false, buildTransaction validates non-empty extraData as hex before selecting the transaction type. Malformed input such as "zz" returns -32602 (invalid params). For existing TRX and TRC10 transfer clients, this changes the error code from -32000 to -32602.
  • When visible=true, the shared Util.setTransactionExtraData helper encodes memo text as UTF-8. This applies to JSON-RPC transfers, deployments and calls, as well as HTTP endpoints that use the helper.

Why are these changes required?

Deployments and calls previously accepted a memo and silently dropped it before signing. Applications that use memos to match transactions to orders lost that reference. The shared helper also used the JVM default charset, so two nodes could encode the same text as different bytes.

This PR has been tested by:

  • All 10 targeted tests passed locally in a JVM with US-ASCII as its default charset. They cover memo bytes in serialized transactions, txID, deployment bytecode, call data, JSON-RPC error responses, and the HTTP memo helper. The new deployment and call tests both reproduced the encoding issue before the fix.
  • The clean build (./gradlew clean build -x test), Checkstyle, and the Math usage check passed locally.

Follow up

None.

Extra details

On a node whose default charset encoded a memo differently from UTF-8, building the same transaction with visible=true can now produce different memo bytes and a different txID. For deployments, a different txID also changes the derived contract address. Clients that precompute these values should encode text memos as UTF-8.

@0xbigapple

Copy link
Copy Markdown
Collaborator

[NIT] when visible is omitted, buildTransaction decodes extraData as hex. Passing "zz" during contract deployment raises JsonRpcInternalException (-32000). Could we handle invalid hex as JsonRpcInvalidParamsException (-32602) and add a regression test covering both cases? With visible omitted, "zz" should return -32602. With visible=true, it should be preserved as a text memo.

@Federico2014

Copy link
Copy Markdown
Collaborator Author

@0xbigapple Fixed in 08a2c34. With visible omitted, buildTransaction now returns -32602 for extraData: "zz". With visible: true, it preserves zz as the transaction memo. Both deployment regression tests passed: one checks the JSON-RPC error code, and the other verifies the memo bytes in the serialized transaction.


txBuilder.setRawData(rawBuilder);
tx = setTransactionPermissionId(args.getPermissionId(), txBuilder.build());
tx = setTransactionExtraData(args.getExtraData(), tx, args.isVisible());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MUST] Use explicit UTF-8 for contract memo text

The shared helper encodes visible memo text with String.getBytes(), which uses the node's default charset. In a JDK 17 check the same non-ASCII memo produced e8aea2e58d95 under UTF-8 and 3f3f under US-ASCII. The call path has the same issue. The difference changes the signed raw data and its txID.

Suggestion: Use explicit UTF-8 for visible memos in the two new contract paths and add a non-ASCII regression test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bladehan1 Agreed that visible memo text should use UTF-8. Since contract deployment, contract calls, regular transfers, and several HTTP endpoints all use Util.setTransactionExtraData, I think we should make this change once in the shared helper. A contract-only fix would let the same visible=true memo produce different bytes depending on which endpoint built the transaction.

On nodes with a non-UTF-8 default charset, the shared fix can change the memo bytes and txID of newly built transactions, and the derived address for contract deployments. Nodes already using UTF-8, hex memos (visible=false), and previously signed transactions are unaffected.

Does that scope look right to you? If so, I’ll update the shared helper and add non-ASCII regression coverage for deployment and calls.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bladehan1 Fixed in 4962dc1. The shared Util.setTransactionExtraData helper now uses ByteString.copyFromUtf8 for visible=true, so JSON-RPC and HTTP callers encode text memos consistently.

With US-ASCII as the JVM default charset, the deployment and call tests both reproduced 3f3f before the fix and now verify e8aea2e58d95 in the serialized transaction. All 10 targeted tests passed.

@Federico2014
Federico2014 force-pushed the fix/jt-957-contract-extra-data branch from 08a2c34 to 778793a Compare November 23, 2026 15:03
@317787106 317787106 removed this from the GreatVoyage-v4.8.3 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants