Skip to content

Add domain to secretToScalar - #818

Open
andrew-fleming wants to merge 4 commits into
OpenZeppelin:release/v0.3.0-alpha.1-rc.0from
andrew-fleming:add-domain-secretToScalar
Open

Add domain to secretToScalar#818
andrew-fleming wants to merge 4 commits into
OpenZeppelin:release/v0.3.0-alpha.1-rc.0from
andrew-fleming:add-domain-secretToScalar

Conversation

@andrew-fleming

@andrew-fleming andrew-fleming commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #792

Summary by CodeRabbit

  • Security Enhancements

    • Added domain separation to ElGamal secret-to-scalar and encryption-key derivation.
    • Prevented account identifiers from being directly reused to derive encryption scalars.
    • Centralized account-ID derivation for consistent behavior across modules.
  • Documentation

    • Clarified hashing boundaries and safe reuse of secret material.
  • Tests

    • Added coverage for domain-separation tags, argument ordering, and collision prevention.

@andrew-fleming
andrew-fleming requested review from a team as code owners August 21, 2026 07:42
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6aa9098f-ab6a-4c66-b669-89e4a6ed1157

📥 Commits

Reviewing files that changed from the base of the PR and between 677f352 and 7544633.

📒 Files selected for processing (5)
  • contracts/src/crypto/ElGamal.compact
  • contracts/src/crypto/test/ElGamal.test.ts
  • contracts/src/token/ConfidentialFungibleToken.compact
  • contracts/src/token/test/ConfidentialFungibleToken.test.ts
  • contracts/src/utils/Utils.compact

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


Walkthrough

The change adds domain separation to ElGamal scalar and encryption-key derivation. Account-ID derivation remains an untagged, globally consistent hash delegated through Utils. Tests verify separation and tag ordering.

Changes

Domain-separated key derivation

Layer / File(s) Summary
Domain-separated scalar derivation
contracts/src/crypto/ElGamal.compact, contracts/src/crypto/test/ElGamal.test.ts
secretToScalar hashes a fixed tag and secret as a two-element vector before reduction. Tests verify separation from account identifiers and the tag position.
Account-ID and encryption-key integration
contracts/src/token/ConfidentialFungibleToken.compact, contracts/src/token/test/ConfidentialFungibleToken.test.ts, contracts/src/utils/Utils.compact
The token module delegates computeAccountId to Utils. Encryption-key derivation uses the ElGamal domain tag. Documentation records the account-ID hashing contract.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 75446

The change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Suggested reviewers: 0xisk

Poem

I’m a rabbit with a tagged little key,
Hashing secrets where domains must be.
Account IDs keep their global trail,
While private paths no longer sail
On the same hash without a veil.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #792 by domain-separating secretToScalar from account-ID hashing and adding supporting tests and documentation.
Out of Scope Changes check ✅ Passed The implementation, utility reuse, documentation, tests, and formatting changes directly support the linked issue and stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (3 skipped: 3 unsupported.)
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding domain separation to secretToScalar.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@andrew-fleming andrew-fleming changed the title Add domain secret to scalar Add domain to secretToScalar Aug 21, 2026
@andrew-fleming
andrew-fleming changed the base branch from main to release/v0.3.0-alpha.1-rc.0 August 21, 2026 22:22
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.

H-01 Account Identifiers And Encryption Secrets Share Undomain-Separated Hash

1 participant