fix: scalarmul by 0 on twisted edwards curves#1551
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a division by zero panic that occurs when performing scalar multiplication by zero on twisted Edwards curves. The issue was in the halfGCD function which calls ecc.PrecomputeLattice without handling the zero scalar case.
- Adds a hot path in
halfGCDto handle zero scalar inputs by returning all zero outputs - Expands test coverage to include zero scalar inputs across all curve configurations
- Removes unused test code that was no longer needed
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| std/algebra/native/twistededwards/hints.go | Adds zero scalar check to prevent division by zero in halfGCD function |
| std/algebra/native/twistededwards/curve_test.go | Enhances tests to cover zero scalar cases and removes unused varScalarMul struct |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When requesting for decomposition of zero scalar, then add hot path which avoids calling ecc.PrecomputeLattice directly as it panics due to division by zero. Checked that this unsafe way of calling
ecc.PrecomputeLatticewas only done here, everywhere else the parameters are either constants (through curve parameters) or we explicitly set the scalar to be 1 if it is 0 and later switch between actual and dummy result.Fixes #1547
Thanks for @lucasmenendez and @p4u for reporting!
Type of change
How has this been tested?
Expanded current tests to include zero inputs.
Checklist:
golangci-lintdoes not output errors locally