Skip to content

Decodes a Base58Check-encoded Tron address, throwing on invalid input#4708

Open
nikhil-gupta-tw wants to merge 2 commits intomasterfrom
fix/tron-address
Open

Decodes a Base58Check-encoded Tron address, throwing on invalid input#4708
nikhil-gupta-tw wants to merge 2 commits intomasterfrom
fix/tron-address

Conversation

@nikhil-gupta-tw
Copy link
Copy Markdown

This pull request improves Tron transaction signing by adding robust validation and error handling for Tron addresses. It introduces a centralized address decoding function that throws on invalid input, ensuring that all contract types consistently validate addresses. Additionally, it enhances the test suite with cases for invalid addresses to ensure correct error reporting.

Address validation and error handling:

  • Introduced a new decodeAddress helper function in Signer.cpp to decode Base58Check-encoded Tron addresses, throwing an exception on invalid input, and replaced all direct usages of Base58::decodeCheck with this function across all contract conversion functions. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15]
  • Updated the buildTransaction function to no longer be marked as noexcept, allowing exceptions to propagate for invalid addresses.
  • Modified the Signer::sign and Signer::compile methods to catch address decoding exceptions, set the error code to Error_invalid_address, and populate the error message accordingly in the output. [1] [2] [3]

Testing improvements:

  • Added new tests in SignerTests.cpp to verify that invalid addresses in transfers and TRC20 contracts are correctly detected and reported as errors, ensuring that no transaction ID or signature is produced in these cases.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens Tron transaction signing by centralizing Base58Check address decoding/validation and mapping invalid-address failures to Error_invalid_address instead of producing a signable transaction with empty/invalid address bytes.

Changes:

  • Added a decodeAddress() helper in src/Tron/Signer.cpp and replaced direct Base58::decodeCheck usages across contract conversions.
  • Allowed invalid address errors to propagate by removing noexcept from buildTransaction(), and added exception-to-error mapping in Signer::sign() and Signer::compile().
  • Extended the Tron signer test suite with invalid-address cases to ensure errors are reported and no id/signature is produced.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/Tron/Signer.cpp Centralizes address decoding + propagates/handles invalid address errors in signing/compilation flows.
tests/chains/Tron/SignerTests.cpp Adds regression tests for invalid recipient/contract addresses returning Error_invalid_address.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Binary size comparison

➡️ aarch64-apple-ios: 14.34 MB

➡️ aarch64-apple-ios-sim: 14.34 MB

➡️ aarch64-linux-android: 18.77 MB

➡️ armv7-linux-androideabi: 16.20 MB

➡️ wasm32-unknown-emscripten: 13.68 MB

Copy link
Copy Markdown
Contributor

@sergei-boiko-trustwallet sergei-boiko-trustwallet left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

3 participants