Skip to content

test(utils): add unit tests for domain computation utilities#299

Merged
spiral-ladder merged 7 commits intoChainSafe:mainfrom
lodekeeper-z:test/domain-utils
Apr 11, 2026
Merged

test(utils): add unit tests for domain computation utilities#299
spiral-ladder merged 7 commits intoChainSafe:mainfrom
lodekeeper-z:test/domain-utils

Conversation

@lodekeeper-z
Copy link
Copy Markdown
Contributor

Summary

Add 8 unit tests for domain.zig — the domain computation utilities used in BLS signature verification.

Tests added

Test Coverage
computeDomain - domain type is first 4 bytes Verifies domain structure per spec
computeDomain - different domain types Cross-domain isolation
computeDomain - different fork versions Fork version affects domain
forkVersion - before fork epoch Returns previous version
forkVersion - at/after fork epoch Returns current version
computeForkDataRoot - deterministic Same inputs → same output
computeForkDataRoot - different inputs Input sensitivity

Motivation

domain.zig had 0 test coverage despite being critical for signature verification correctness. These functions compute the BLS signing domain per the consensus spec.

🤖 Generated with AI assistance

Add 8 unit tests for domain.zig covering:
- computeDomain: domain type in first 4 bytes, different types/versions
  produce different domains, fork data root portion is non-zero
- forkVersion: returns previous version before fork epoch, current at/after
- computeForkDataRoot: deterministic output, different inputs produce
  different roots

🤖 Generated with AI assistance
@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 introduces a suite of unit tests for the domain computation utilities, which are critical components for BLS signature verification. By establishing these tests, the codebase now has baseline coverage for these functions, ensuring that domain structure and fork versioning logic adhere to the consensus specifications.

Highlights

  • Test Coverage: Added 8 comprehensive unit tests to the domain computation utilities in src/state_transition/utils/domain.zig.
  • Functionality Verified: Validated domain structure, fork version selection logic, and deterministic fork data root computation.

🧠 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
Contributor

@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 introduces a comprehensive suite of unit tests for domain and fork utility functions in src/state_transition/utils/domain.zig, covering domain computation, fork versioning, and fork data root generation. The review feedback identifies an opportunity to simplify a manual loop in the computeDomain test by using std.mem.all, which would improve code readability and better align with the project's style guidelines regarding simplicity and developer experience.

Comment thread src/state_transition/utils/domain.zig Outdated
Comment on lines +49 to +53
// Remaining 28 bytes should be from fork data root (non-zero due to hashing)
var all_zero = true;
for (domain[4..32]) |b| {
if (b != 0) { all_zero = false; break; }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The manual loop to check if the remaining bytes are non-zero can be simplified using std.mem.all. This improves readability and conciseness, aligning with the repository's style guide emphasis on simpler designs and good developer experience.

    try testing.expect(!std.mem.all(u8, domain[4..32], 0));
References
  1. Good style advances safety, performance, and developer experience. Declare variables at the smallest possible scope, and minimize the number of variables in scope. Don't introduce variables before they are needed. (link)

Fork SSZ container uses snake_case field names (previous_version,
current_version), not camelCase. Also fix zig fmt formatting.

🤖 Generated with AI assistance
@lodekeeper-z lodekeeper-z requested a review from a team as a code owner March 30, 2026 07:36
GrapeBaBa
GrapeBaBa previously approved these changes Apr 3, 2026
Copy link
Copy Markdown
Collaborator

@spiral-ladder spiral-ladder left a comment

Choose a reason for hiding this comment

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

made some opinionated refactors (eg. removing what i think are redundant tests) mainly aimed at reducing slop tests that bloat LoCs, cc @GrapeBaBa, can retroactively update this if you think there's some glaring mistakes

@spiral-ladder spiral-ladder merged commit bb37a46 into ChainSafe:main Apr 11, 2026
13 checks passed
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.

3 participants