Skip to content

fix: use int64 to avoid error when building for 32-bits target#143

Open
jht6 wants to merge 1 commit intoXRPLF:mainfrom
jht6:main
Open

fix: use int64 to avoid error when building for 32-bits target#143
jht6 wants to merge 1 commit intoXRPLF:mainfrom
jht6:main

Conversation

@jht6
Copy link

@jht6 jht6 commented Jun 30, 2025

Title

Description

This PR aims to . (Mark tags that apply)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where needed
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

Changes

  • Change 1
  • Change 2

Notes (optional)

Describe any additional notes here.

Summary by CodeRabbit

  • Refactor
    • Improved internal consistency by updating the loop counter to use a 64-bit integer type. No changes to user-facing features or functionality.

@coderabbitai
Copy link

coderabbitai bot commented Jun 30, 2025

📝 Walkthrough

Walkthrough

The change updates the type of the loop variable in the deriveScalar method within the secp256k1 crypto package, switching it from an untyped integer to an explicit int64. No other logic or exported declarations were modified.

Changes

File Change Summary
pkg/crypto/secp256k1.go Changed the loop variable in deriveScalar from default int to int64

Sequence Diagram(s)

No sequence diagram generated as the change is limited to a loop variable type update and does not affect control flow or feature logic.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
pkg/crypto/secp256k1.go (2)

66-74: discrimBytes never filled – hashing the wrong data
The code allocates discrimBytes but then writes the 4 derived bytes into the input slice bytes, leaving discrimBytes zero-initialised. Consequently, the hash operates on four zero bytes instead of the intended discriminator, and bytes is mutated unexpectedly.

-        discrimBytes := make([]byte, 4)
-        bytes[0] = byte(discrim.Uint64())
-        bytes[1] = byte(discrim.Uint64() >> 8)
-        bytes[2] = byte(discrim.Uint64() >> 16)
-        bytes[3] = byte(discrim.Uint64() >> 24)
-
-        hash.Write(discrimBytes)
+        discrimBytes := []byte{
+            byte(discrim.Uint64()),
+            byte(discrim.Uint64() >> 8),
+            byte(discrim.Uint64() >> 16),
+            byte(discrim.Uint64() >> 24),
+        }
+        hash.Write(discrimBytes)

76-83: Same slice-mix-up for shiftBytes
shiftBytes is allocated but never populated; instead bytes is overwritten. The hash again receives zeros, and the original seed slice is corrupted each iteration.

-        shiftBytes := make([]byte, 4)
-        bytes[0] = byte(i)
-        bytes[1] = byte(i >> 8)
-        bytes[2] = byte(i >> 16)
-        bytes[3] = byte(i >> 24)
-
-        hash.Write(shiftBytes)
+        shiftBytes := []byte{
+            byte(i),
+            byte(i >> 8),
+            byte(i >> 16),
+            byte(i >> 24),
+        }
+        hash.Write(shiftBytes)
🧹 Nitpick comments (1)
pkg/crypto/secp256k1.go (1)

58-59: Parameter name masks the built-in bytes package
Using the identifier bytes for a slice parameter shadows the standard library package bytes, hindering readability and potential future imports. Consider renaming to seed or input.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b8142e and da6775f.

📒 Files selected for processing (1)
  • pkg/crypto/secp256k1.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: florent-uzio
PR: Peersyst/xrpl-go#113
File: xrpl/transaction/credential_create.go:30-34
Timestamp: 2025-03-11T11:50:58.330Z
Learning: In PR #113 for xrpl-go, the `CredentialCreate` struct in xrpl/transaction/credential_create.go does not have any duplicated fields as was incorrectly flagged in a previous review comment.
Learnt from: florent-uzio
PR: Peersyst/xrpl-go#113
File: xrpl/transaction/credential_create.go:30-34
Timestamp: 2025-03-11T11:50:58.330Z
Learning: In the PR #113 for xrpl-go, the initial flagging of duplicated fields (`CredentialType` and `Expiration`) in the `xrpl/transaction/credential_create.go` file was determined to be irrelevant and not an actual issue.
Learnt from: florent-uzio
PR: Peersyst/xrpl-go#113
File: xrpl/transaction/credential_create.go:30-34
Timestamp: 2025-03-11T11:50:58.330Z
Learning: The CredentialCreate struct in xrpl/transaction/credential_create.go does not have any duplicated fields as was incorrectly flagged in a previous review comment.
🔇 Additional comments (1)
pkg/crypto/secp256k1.go (1)

61-61: 32-bit build fix is spot-on
Switching the loop counter to int64 removes the overflow/constant-too-large error on 32-bit targets without changing behaviour.

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.

1 participant