fix: correct loop iteration syntax in MuSig2Sign#1108
fix: correct loop iteration syntax in MuSig2Sign#1108Olexandr88 wants to merge 1 commit intolightninglabs:masterfrom
Conversation
Summary of ChangesHello, 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
This change is not needed. The code is already correct. See https://go.dev/doc/go1.22#language
There was a problem hiding this comment.
Thanks for the clarification! Closing the PR.
Fix invalid loop iteration over slice length in MuSig2Sign