Conversation
📝 WalkthroughWalkthroughA single-file update to the SECP256K1 cryptographic utility that replaces runtime assertions with Guava Preconditions for input validation across constructors and factory methods. Additionally implements a security-conscious PrivateKey toString() method that redacts sensitive data, with a new optional method to access the actual private key representation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="utils/src/main/java/org/tron/trident/crypto/SECP256K1.java">
<violation number="1" location="utils/src/main/java/org/tron/trident/crypto/SECP256K1.java:381">
P2: `toStringWithPrivateKey()` returns a `0x`-prefixed string that `PrivateKey.create(String)` immediately rejects, so the new API cannot round-trip its own output.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@utils/src/main/java/org/tron/trident/crypto/SECP256K1.java`:
- Around line 328-331: The create(String hexKey) method in SECP256K1 needs a
null check before calling hexKey.length(); update the method to first validate
hexKey is non-null (e.g., Preconditions.checkNotNull(hexKey, "hexKey cannot be
null")) and then assert the length is 64 with the existing
Preconditions.checkArgument, then proceed to call Bytes32.fromHexString(hexKey)
and return create(...); this keeps behavior consistent with other factory
methods and prevents NullPointerException.
- Around line 607-610: In SECP256K1.decode, add a null-check for the parameter
`bytes` before calling `bytes.size()` (e.g., use
Preconditions.checkNotNull(bytes, "encoded SECP256K1 signature must not be
null")) so a clear error is thrown instead of a NullPointerException, then keep
the existing size check against BYTES_REQUIRED and proceed with signature
decoding; this aligns with other methods' null-checking behavior.
- Around line 159-162: Add explicit null checks for the BigInteger parameters r
and s before calling r.signum() and s.signum() in SECP256K1 (so the NPE is
avoided and error messages are clear): insert Preconditions.checkNotNull(r, "r
must not be null") and Preconditions.checkNotNull(s, "s must not be null") ahead
of the existing Preconditions.checkArgument(r.signum() >= 0, ...) and
Preconditions.checkArgument(s.signum() >= 0, ...), keeping the existing recId
and dataHash checks intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 39c6e071-c25f-4f47-a7e6-384ff1081a04
📒 Files selected for processing (1)
utils/src/main/java/org/tron/trident/crypto/SECP256K1.java
What does this PR do?
toString()inPrivateKeyto return a redacted representation and add a newtoStringWithPrivateKeyfunction.asserttoPreconditions.checkArgument/Preconditions.checkNotNullWhy are these changes required?
This PR has been tested by:
Follow up
Extra details
Summary by cubic
Redacts
SECP256K1.PrivateKey#toString()to prevent key leaks and addstoStringWithPrivateKey()for explicit access. Replacesassertchecks withcom.google.common.base.Preconditionsand adds stricter null/length validation across ECDH, signature decode, key creation, and verify helpers to fix input handling bugs.Written for commit 34bfbe5. Summary will update on new commits.
Summary by CodeRabbit
Security
New Features
Improvements