Repository navigation
fix(jsonrpc): preserve memos on smart contract transactions - #7120
Federico2014 wants to merge 4 commits into
Conversation
…7-contract-extra-data
|
[NIT] when |
|
@0xbigapple Fixed in 08a2c34. With |
|
|
||
| txBuilder.setRawData(rawBuilder); | ||
| tx = setTransactionPermissionId(args.getPermissionId(), txBuilder.build()); | ||
| tx = setTransactionExtraData(args.getExtraData(), tx, args.isVisible()); |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@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.
08a2c34 to
778793a
Compare
What does this PR do?
JSON-RPC
buildTransactionnow writesextraDatatoraw_data.datafor smart contract deployments and calls. The memo is included in the unsigned transaction and itstxID, alongside the deployment bytecode or call data.visibleis omitted orfalse,buildTransactionvalidates non-emptyextraDataas 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-32000to-32602.visible=true, the sharedUtil.setTransactionExtraDatahelper 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:
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../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=truecan now produce different memo bytes and a differenttxID. For deployments, a differenttxIDalso changes the derived contract address. Clients that precompute these values should encode text memos as UTF-8.