Skip to content

test(access): pad the nullifier domain like the other domains - #1246

Merged
andrew-fleming merged 1 commit into
OpenZeppelin:mainfrom
yash251:yash/441-standardize-test-encodings
Nov 14, 2026
Merged

andrew-fleming merged 1 commit into
OpenZeppelin:mainfrom
yash251:yash/441-standardize-test-encodings

Conversation

@yash251

@yash251 yash251 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Fixes #441

In ShieldedAccessControl.test.ts, buildNullifierHash encoded NULLIFIER_DOMAIN with a bare TextEncoder, while buildAccountIdHash and buildRoleCommitmentHash use encodePadded32. The contract defines nullifierDomain as pad(32, "ShieldedAccessControl:nullifier"), so this switches the helper to encodePadded32 for consistency.

The resulting hash does not change. The domain string is 31 bytes and persistentHash already zero-pads it. I checked this with @midnight-ntwrk/compact-runtime from the lockfile: both encodings give the same persistentHash over [commitment, domain]. So no expected values move.

Test-only change, so I didn't add a CHANGELOG entry. Could a maintainer add the skip-changelog label?

PR Checklist

  • I have read the Contributing Guide
  • I have added tests that prove my fix is effective or that my feature works (test-only change)
  • I have added documentation for new methods or changes to existing method behavior (n/a)
  • I have added a CHANGELOG entry under ## Unreleased, or asked a maintainer to add the skip-changelog label because nothing user-facing changed (asked above)
  • CI Workflows Are Passing

Further comments

biome check passes on the changed file. I don't have the Compact compiler installed locally, so I couldn't run the access test suite; I'm relying on CI for that, backed by the hash check above.

Summary by CodeRabbit

  • Tests
    • Updated shielded access-control test validation to use a 32-byte padded domain when checking nullifier hashes, keeping test expectations consistent with the encoded value.

buildNullifierHash encoded NULLIFIER_DOMAIN with a bare TextEncoder,
while the account and commitment helpers use encodePadded32. The
contract defines nullifierDomain as a zero-padded 32-byte string, so use
the same helper here. The hash is unchanged: persistentHash already
zero-pads the 31-byte value.

Fixes OpenZeppelin#441
@yash251
yash251 requested review from a team as code owners November 14, 2026 04:30
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The buildNullifierHash test helper now pads NULLIFIER_DOMAIN to 32 bytes before hashing it.

Changes: Nullifier domain encoding

Layer / File(s) Summary
Update nullifier hash test helper
contracts/src/access/test/ShieldedAccessControl.test.ts
buildNullifierHash now passes a 32-byte padded NULLIFIER_DOMAIN to persistentHash.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Other

Suggested reviewers: andrew-fleming, 0xisk

Merge Risk: Minimal · up to bd8b0

This is a test-only change that aligns the nullifier hash helper with the contract's 32-byte padded domain. It has no production impact, and CI will exercise it.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: the nullifier domain is padded to 32 bytes, matching the other domain helpers. The raw summary confirms that buildNullifierHash in ShieldedAccessControl.test.ts now applies…
Linked Issues check Passed Issue #441 asks that the nullifier domain in the test helpers be encoded to 32 bytes, as in the review suggestion const bDomain = encodePadded32(NULLIFIER_DOMAIN);. The whole-PR diff (mergeBase 4543…
Out of Scope Changes check Passed The only changed file is contracts/src/access/test/ShieldedAccessControl.test.ts, and the only hunk is the one-line buildNullifierHash encoding change required by #441. No other files or declarati…
Full details: Title check

Explanation

The title names the change: the nullifier domain is padded to 32 bytes, matching the other domain helpers. The raw summary confirms that buildNullifierHash in ShieldedAccessControl.test.ts now applies encodePadded32 to NULLIFIER_DOMAIN. The title is specific and conventional, and the change is test-only, which the title states through the test(access) prefix.

Full details: Linked Issues check

Explanation

Issue #441 asks that the nullifier domain in the test helpers be encoded to 32 bytes, as in the review suggestion const bDomain = encodePadded32(NULLIFIER_DOMAIN);. The whole-PR diff (mergeBase 45437a3 to head bd8b08d) changes one line in buildNullifierHash in contracts/src/access/test/ShieldedAccessControl.test.ts from new TextEncoder().encode(NULLIFIER_DOMAIN) to encodePadded32(NULLIFIER_DOMAIN). This matches the requested change. The other helpers (buildAccountIdHash, buildRoleCommitmentHash) already use encodePadded32, so the test file is now consistent. The author's claim that the hash value is unchanged was not re-verified in this review. The claim does not affect the coding requirement, which is the encoding change itself. The test suite was not run here.

Full details: Out of Scope Changes check

Explanation

The only changed file is contracts/src/access/test/ShieldedAccessControl.test.ts, and the only hunk is the one-line buildNullifierHash encoding change required by #441. No other files or declarations changed. The PR description and checklist items about CHANGELOG and labels are non-coding and do not affect this assessment.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 45437a3 and bd8b08d.

Files selected for processing: 1

  • contracts/src/access/test/ShieldedAccessControl.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@andrew-fleming andrew-fleming left a comment

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.

Thanks @yash251! LGTM

@andrew-fleming
andrew-fleming merged commit f85f1a2 into OpenZeppelin:main Nov 14, 2026
10 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.

Standardize text encodings in tests

2 participants