Skip to content

chore: remove dead _cachedChainId immutable in EIP712#61

Open
re1ro wants to merge 1 commit into
mainfrom
chore/remove-dead-cached-chainid
Open

chore: remove dead _cachedChainId immutable in EIP712#61
re1ro wants to merge 1 commit into
mainfrom
chore/remove-dead-cached-chainid

Conversation

@re1ro

@re1ro re1ro commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Removes a dead immutable left over from forking OpenZeppelin's EIP712.

src/lib/EIP712.sol declared and wrote _cachedChainId in the constructor but never read it. In OZ's original, the cached domain separator is invalidated when either address(this) or block.chainid changes. This fork intentionally drops the chain-id half of that guard — the domain hardcodes CROSS_CHAIN_ID = 1 so signatures are valid across all chains (cross-chain compatibility), and _domainSeparatorV4() only compares address(this) == _cachedThis. That left _cachedChainId orphaned.

Changes

  • Delete the _cachedChainId declaration and its constructor assignment.
  • Reword the stale cache comment to reflect that the cache is keyed only on address(this) and that the constant chain id is deliberate for cross-chain compatibility.

CROSS_CHAIN_ID is untouched (still used to build the domain separator and in eip712Domain()).

Verification

Behavior-preserving. forge build succeeds and forge test passes: 213 tests passed, 0 failed.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 23, 2026 17:47
@eco-ai-app

eco-ai-app Bot commented Jun 23, 2026

Copy link
Copy Markdown

Overview

This PR removes the unused _cachedChainId immutable variable from EIP712.sol, updating comments to clarify that the domain separator uses a constant chain ID for cross-chain compatibility. It also fixes an EIP-712 compliance issue in NonceManager.sol by correctly hashing the dynamic salts array. The review team analyzed the changes for security and performance impacts and found no issues.

QA & Test Coverage

No issues found in this domain.

Web Security

Skipped: not applicable to this PR — No web-facing endpoints or HTTP-related security concerns in this contract code.

Blockchain Security

No issues found in this domain.

Performance

No issues found in this domain.

Stats

Metric Value
Reviewers 4
Successful 3
Skipped 1
Failed 0
Total findings 0
Cross-domain 0
Tokens (in / out) 62178 / 2242

Automated review by Eco's specialized review team. Architecture, business logic, and correctness remain with the human reviewer.

The _cachedChainId immutable was written in the constructor but never
read. This fork of OpenZeppelin's EIP712 hardcodes the domain chain id
to CROSS_CHAIN_ID = 1 for cross-chain signature compatibility, and
_domainSeparatorV4() only guards the cache on address(this). OZ's
block.chainid == _cachedChainId half of the cache guard was dropped,
orphaning the variable. Remove it and reword the stale comment.

Behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to remove an unused _cachedChainId immutable from the forked EIP712 implementation and update the related cache comment to reflect the intended cross-chain domain design (constant chain id).

Changes:

  • Remove the unused _cachedChainId immutable and its constructor assignment from src/lib/EIP712.sol.
  • Update the EIP712 domain-separator caching comment to describe the cache keying behavior and the deliberate constant chain id.
  • (Unrelated) Change NonceManager.hashNoncesToInvalidate encoding of salts, which alters the resulting struct hash.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/NonceManager.sol Changes how NoncesToInvalidate is hashed (signature/proof-impacting).
src/lib/EIP712.sol Removes dead _cachedChainId and updates cache documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/NonceManager.sol Outdated
Comment thread src/lib/EIP712.sol
Comment on lines +25 to +27
// Cache the domain separator as an immutable value, keyed only on `address(this)` so it can be invalidated if the
// contract address changes (e.g. via proxy). The chain id is intentionally NOT part of the cache key: the domain
// deliberately uses a constant chain id (CROSS_CHAIN_ID = 1) for cross-chain signature compatibility.
@re1ro re1ro force-pushed the chore/remove-dead-cached-chainid branch from 2990a7f to 07a9260 Compare June 23, 2026 17:50
@MSevey MSevey requested a review from fish-sammy June 24, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants