fix: validate tron address checksum#577
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds stricter validation for Tron addresses by explicitly rejecting decoded Base58Check payloads with an unexpected length or a non-Tron network prefix, and extends tests to cover the non-Tron prefix case.
Changes:
- Add decoded address length and prefix checks in
ValidateTronAddress. - Add a test case for Base58Check addresses that have a valid checksum but non-Tron prefix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| x/tron/types/address.go | Adds length and Tron prefix validation before re-encoding and comparing. |
| x/tron/types/address_test.go | Adds coverage for rejecting Base58Check addresses with a non-Tron prefix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesTron Address Validation Hardening
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@x/tron/types/address_test.go`:
- Around line 60-64: The base58check invalid decoded-length test in
address_test.go is too generic and can succeed on the earlier character-length
validation instead of the new decoded-length branch. Update the test case around
the address decoding checks in the relevant test function to use input that
bypasses the char-length guard and only fails at the decoded-length validation,
and tighten the assertion in the corresponding require.Contains check so it
proves the branch-specific error path is exercised.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro Plus
Run ID: 680496f6-f341-4184-8764-bd3e63f9cd8d
📒 Files selected for processing (2)
x/tron/types/address.gox/tron/types/address_test.go
| testName: "base58check address with invalid decoded length", | ||
| value: troncommon.EncodeCheck(shortTronPayload), | ||
| expectPass: false, | ||
| errStr: "invalid address length", | ||
| }, |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Make the decoded-length regression case branch-specific.
Line 63 ("invalid address length") plus Line 79 (require.Contains) can pass via the earlier char-length guard, so this case does not reliably prove the new decoded-length check is exercised.
Suggested patch
@@
{
testName: "base58check address with invalid decoded length",
value: troncommon.EncodeCheck(shortTronPayload),
expectPass: false,
- errStr: "invalid address length",
+ errStr: "expected decoded",
},
@@
- require.Contains(t, err.Error(), testCase.errStr, testCase.value)
+ require.Error(t, err)
+ require.Contains(t, err.Error(), testCase.errStr, testCase.value)As per path instructions, "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request".
Also applies to: 79-79
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@x/tron/types/address_test.go` around lines 60 - 64, The base58check invalid
decoded-length test in address_test.go is too generic and can succeed on the
earlier character-length validation instead of the new decoded-length branch.
Update the test case around the address decoding checks in the relevant test
function to use input that bypasses the char-length guard and only fails at the
decoded-length validation, and tighten the assertion in the corresponding
require.Contains check so it proves the branch-specific error path is exercised.
Source: Path instructions
/claim #173
Fixes #173
Summary
0x41prefixTests
go test ./x/tron/... -count=1git diff --checkSummary by CodeRabbit