test: add signature_sets unit tests and fix createSingleSignatureSetFromComponents#313
test: add signature_sets unit tests and fix createSingleSignatureSetFromComponents#313gorusys wants to merge 3 commits intoChainSafe:mainfrom
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 minor bug in the 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 introduces a comprehensive suite of unit tests for signature set verification and updates the createSingleSignatureSetFromComponents function. Feedback focuses on adhering to the repository style guide, specifically regarding the use of assertions, out-pointers for large structs, and passing large arguments by constant pointer. Additionally, several lines in the new tests exceed the 100-column limit, and an improvement was suggested for a test case to ensure it validates individual struct fields rather than just the final verification result.
| pub fn createSingleSignatureSetFromComponents(pubkey: *const PublicKey, signing_root: Root, signature: BLSSignature) SingleSignatureSet { | ||
| return .{ | ||
| .pubkey = pubkey, | ||
| .pubkey = pubkey.*, |
There was a problem hiding this comment.
The function createSingleSignatureSetFromComponents violates several rules from the Repository Style Guide:
- Assertions: All function arguments must be asserted (Line 51). This function currently has no assertions. Even for simple constructors, the guide requires an average of two assertions per function to ensure data integrity.
- Out-pointers: For structs larger than 16 bytes (this struct is ~224 bytes), the guide recommends initialization in-place using an out-pointer to avoid intermediate copy-move allocations and stack growth (Line 318).
- Pass-by-pointer: Arguments larger than 16 bytes (like
Rootat 32 bytes andBLSSignatureat 96 bytes) should be passed as*constto avoid unnecessary copies (Line 314).
While the function signature is not part of this diff, consider refactoring it to adhere to these safety and performance standards.
| const signature = sign(secret_key, &signing_root); | ||
| const public_key = secret_key.toPublicKey(); | ||
| var pubkeys = [_]PublicKey{public_key}; | ||
| const set = createAggregateSignatureSetFromComponents(pubkeys[0..], signing_root, signature.compress()); |
There was a problem hiding this comment.
This line exceeds the 100-column limit (it is 108 columns), violating the Repository Style Guide (Line 400). Please wrap the function call.
const set = createAggregateSignatureSetFromComponents(
pubkeys[0..],
signing_root,
signature.compress(),
);
References
- Hard limit all line lengths, without exception, to at most 100 columns. (link)
| const public_key = secret_key.toPublicKey(); | ||
| signing_root[31] ^= 0xff; | ||
| var pubkeys = [_]PublicKey{public_key}; | ||
| const set = createAggregateSignatureSetFromComponents(pubkeys[0..], signing_root, signature.compress()); |
There was a problem hiding this comment.
This line exceeds the 100-column limit (108 columns), violating the Repository Style Guide (Line 400).
const set = createAggregateSignatureSetFromComponents(
pubkeys[0..],
signing_root,
signature.compress(),
);
References
- Hard limit all line lengths, without exception, to at most 100 columns. (link)
| const signing_root = [_]u8{1} ** 32; | ||
| const signature = sign(secret_key_a, &signing_root); | ||
| var pubkeys = [_]PublicKey{secret_key_b.toPublicKey()}; | ||
| const set = createAggregateSignatureSetFromComponents(pubkeys[0..], signing_root, signature.compress()); |
There was a problem hiding this comment.
This line exceeds the 100-column limit (108 columns), violating the Repository Style Guide (Line 400).
const set = createAggregateSignatureSetFromComponents(
pubkeys[0..],
signing_root,
signature.compress(),
);
References
- Hard limit all line lengths, without exception, to at most 100 columns. (link)
| try std.testing.expect(try verifySingleSignatureSet(&from_fn)); | ||
| try std.testing.expect(try verifySingleSignatureSet(&literal)); |
There was a problem hiding this comment.
The test 'createSingleSignatureSetFromComponents matches equivalent struct literal' should explicitly verify that the fields of the created struct match the expected values. Simply verifying the signature is a weak check for a factory function.
try std.testing.expect(from_fn.pubkey.isEqual(&literal.pubkey));
try std.testing.expectEqual(literal.signing_root, from_fn.signing_root);
try std.testing.expectEqual(literal.signature, from_fn.signature);
try std.testing.expect(try verifySingleSignatureSet(&from_fn));
| try std.testing.expect(try verifySingleSignatureSet(&set)); | ||
| } | ||
|
|
||
| test "verifySingleSignatureSet returns false when signing root does not match signed message" { |
There was a problem hiding this comment.
can we make this group of similar tests using table driven approach to reduce verbose test code?
| .signing_root = signing_root, | ||
| .signature = signature.compress(), | ||
| }; | ||
| try std.testing.expect(!try verifySingleSignatureSet(&set)); |
There was a problem hiding this comment.
nit:use expectEqual false for negative check
No description provided.