feat(blsag): Comprehensive overhaul for performance, robustness, and API design - #9
Open
RyderFreeman4Logos wants to merge 15 commits into
Open
Conversation
This commit introduces significant API improvements to the BLSAG module to enhance performance and ergonomics, especially for large rings. BREAKING CHANGE: The `BLSAG` signature struct no longer stores the ring. The `verify` function now requires the ring to be passed as an argument. - `sign` and `verify` now accept ring data via slice reference (`&[RistrettoPoint]`), eliminating clones and increasing flexibility. - `sign` no longer takes `secret_index`. - `verify` and `link` now operate on signature references (`&BLSAG`). - New traits (`SignRef`, `VerifyRef`) were introduced to facilitate these changes without affecting other schemes.
This commit introduces significant API improvements to the BLSAG module and addresses several code quality issues for better performance and ergonomics. BREAKING CHANGE: The `BLSAG` signature struct no longer stores the ring. The `verify` function now requires the ring to be passed as an argument. - `sign` and `verify` now accept ring data via slice reference (`&[RistrettoPoint]`), eliminating clones and increasing flexibility. - `sign` no longer takes `secret_index`. - `verify` and `link` now operate on signature references (`&BLSAG`). - Removed unnecessary `.clone()` calls on `Copy` types in tests. - Fixed lints reported by Clippy for more idiomatic code.
This commit completes the full refactoring of the BLSAG module, introducing significant API improvements, better performance, and robust error handling. BREAKING CHANGE: The `sign` function now returns a `Result<BLSAG, SignatureError>` instead of panicking. The `BLSAG` signature struct no longer stores the ring, and the `verify` function now requires the ring to be passed as an argument. - `sign` and `verify` now accept ring data via slice reference (`&[RistrettoPoint]`). - `sign` no longer takes `secret_index`. - `verify` and `link` now operate on signature references (`&BLSAG`). - Added a comprehensive test suite verifying core security properties. - Fixed all lints reported by Clippy for more idiomatic code.
Extracts the common cryptographic hashing logic from the `sign` and `verify` functions into a shared private helper. This eliminates code duplication, improving maintainability and reducing the risk of future inconsistencies between the two critical operations.
This commit introduces a new `Ring` struct to ensure that rings are always sorted, enabling a binary search for the signers public key. BREAKING CHANGE: The `sign` and `verify` functions now accept a `&Ring` instead of a `&[RistrettoPoint]`. - This change provides a significant performance improvement for the `sign` function by replacing a linear search with a binary search. - The `Ring` struct also provides a foundation for future optimizations, such as pre-computation.
Introduces a `PrecomputedRingData` struct and updates the `sign` and `verify` functions to optionally accept it. This provides a ~12% performance improvement for signing operations with a 2,000-member ring, and lays the groundwork for further optimizations.
Switches the core cryptographic operation from the constant-time `multiscalar_mul` to the faster `vartime_multiscalar_mul`. This is safe as all inputs at this stage are public. Benchmark results show a ~27% performance improvement in signing operations for a 2,000-member ring.
Switches the core cryptographic operation from the constant-time `multiscalar_mul` to the faster `vartime_multiscalar_mul`. This is safe as all inputs at this stage are public. Benchmark results show a ~27% performance improvement in signing operations for a 2,000-member ring.
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
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.
Hi @edwinhere ,
First and foremost, thank you for creating and maintaining this excellent library,
nazgul!While studying and using the library, I identified several opportunities for a deep refactoring of the
blsagmodule, guided by modern Rust design principles for safety, performance, and ergonomics. With the assistance of my AI programming partner, Gemini, I've performed a comprehensive overhaul, and I'm excited to present the results for your review.My core strategy was to focus on making the
blsagmodule a perfect showcase of these principles first, establishing a rock-solid foundation before considering the other modules. The work was done in a series of logical, independent commits to ensure each step is easy to review and understand.Here is a summary of the key improvements:
1. Foundational Test Suite
Before any changes were made, a comprehensive test suite was established to provide a safety net. It goes beyond simple success cases to cover:
2. API & Implementation Overhaul for Robustness and Performance
The main body of work is a significant API and implementation refactoring.
Key Changes:
New
RingStruct & O(log N) Performance:Ringstruct was introduced. It guarantees that the ring members are always sorted by their byte representation.Lightweight Signatures:
BLSAGsignature struct no longer stores the entire ring, making it extremely lightweight and cheap to pass around.verifyfunction now accepts the&Ringas a parameter.Ergonomic & Idiomatic API:
signfunction no longer requires the caller to provide asecret_index, pulling this complexity down into the module.verifyandlinknow operate on references (&BLSAG), avoiding all unnecessary clones.signnow returns aResult<_, SignatureError>instead of panicking when the signer is not found in the ring, making the library safer for consumers.Information Hiding: The
BLSAGstruct's fields were made private to enforce encapsulation and prevent invalid state modifications.3. Advanced Performance Optimizations
After the main refactoring, two further optimization layers were added:
Pre-computation Support:
PrecomputedRingDatastruct. This allows the expensive hashing of public keys to be done once and reused for many signing/verification operations.Vartime Multiplication:
multiscalar_multo the fastervartime_multiscalar_mul. This is safe as all inputs at this stage are public.A Discussion on Next Steps
I've focused on getting
blsagto a state of excellence first. As I'm not a cryptographer, I would be grateful for your expert review of this direction, especially the API changes and the introduction of theRingstruct.If you're happy with this approach, I'd love to discuss the best way to apply these successful patterns to
mlsagandclsag. I am happy to continue the work, or to do the initial "vibe coding" and testing for you to perform the final cryptographic sign-off.Thank you again for your time and for this wonderful project! I look forward to your feedback.