Skip to content

fix: correct loop iteration syntax in MuSig2Sign#1108

Closed
Olexandr88 wants to merge 1 commit intolightninglabs:masterfrom
Olexandr88:patch-2
Closed

fix: correct loop iteration syntax in MuSig2Sign#1108
Olexandr88 wants to merge 1 commit intolightninglabs:masterfrom
Olexandr88:patch-2

Conversation

@Olexandr88
Copy link
Copy Markdown

Fix invalid loop iteration over slice length in MuSig2Sign

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the MuSig2Sign utility function where incorrect loop syntax was being used to iterate over private keys. By updating the range expressions, the code now correctly iterates over the slice elements, ensuring proper session handling during the nonce exchange process.

Highlights

  • Loop Iteration Fix: Corrected the loop iteration syntax in the MuSig2Sign function by iterating directly over the slice instead of its length.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the range loops in utils/musig.go to use the more idiomatic range syntax for slices. Feedback identifies a logic error where the MuSig2Sign function fails when only one private key is provided because the signature combination loop is skipped, and also points out a typo in an error message.

// Next we'll pass around all public nonces to all MuSig2 sessions so
// that they become usable for creating the partial signatures.
for i := range len(privKeys) {
for i := range privKeys {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The MuSig2Sign function currently fails when len(privKeys) == 1. In this scenario, the signature combination loop (starting at line 66) is skipped, leaving the haveAllSigs variable as false. This subsequently triggers the error check at line 76, returning a "combining MuSig2 signatures failed" error. To make the function more robust, consider initializing haveAllSigs to len(privKeys) == 1 or handling the single-signer case explicitly. Additionally, note that there is a typo in the error message at line 77 ("combinging" should be "combining").

// Next we'll pass around all public nonces to all MuSig2 sessions so
// that they become usable for creating the partial signatures.
for i := range len(privKeys) {
for i := range privKeys {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change is not needed. The code is already correct. See https://go.dev/doc/go1.22#language

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the clarification! Closing the PR.

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.

2 participants