Skip to content

Fix domain separator miscalculation under delegatecall - #439

Open
DefiAudit0x wants to merge 2 commits into
transmissions11:mainfrom
DefiAudit0x:fix/issue-415-domain-separator-delegatecall
Open

DefiAudit0x wants to merge 2 commits into
transmissions11:mainfrom
DefiAudit0x:fix/issue-415-domain-separator-delegatecall

Conversation

@DefiAudit0x

@DefiAudit0x DefiAudit0x commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #415

Problem

DOMAIN_SEPARATOR() returns the cached INITIAL_DOMAIN_SEPARATOR whenever block.chainid == INITIAL_CHAIN_ID — even when the token is executed via delegatecall from another contract. In that context address(this) is the calling proxy, not the token, so the cached separator (computed at deployment for the token's own address) is wrong, and permit() reverts with INVALID_SIGNER for otherwise valid signatures.

Fix

Cache the verifying contract address at deployment (INITIAL_VERIFYING_CONTRACT = address(this)) and return the cached separator only when the chain id matches and address(this) == INITIAL_VERIFYING_CONTRACT; otherwise recompute it via computeDomainSeparator().

Test

Adds src/test/ERC20Delegatecall.t.sol: a minimal proxy (implementation address in the EIP-1967 slot, so the token's storage layout is untouched) that delegatecalls the token, plus three tests: testPermitViaDelegatecall, which signs a permit over the proxy's domain separator and calls permit through the proxy; testDomainSeparatorViaDelegatecall, which asserts the separator returned through the proxy equals the recomputed proxy-context separator; and testPermitViaDelegatecallWithTokenSeparatorReverts, which asserts a permit signed over the token's own separator reverts with INVALID_SIGNER through the proxy.

  • With this fix: all three pass.
  • Without this fix: all three fail (the permit reverts with INVALID_SIGNER, the separator assertion fails, and the negative case unexpectedly succeeds).

Verified locally with solc 0.8.15 / forge 1.9.0. Note: the repo's existing testFail* tests no longer run under forge 1.9.0 (Foundry removed the testFail prefix in v1.0), so the full suite runs but 278 tests fail on the pre-existing testFail* removal; the new tests are written in the current style and pass standalone.

Cache the verifying contract address at deployment and recompute the domain separator when address(this) differs, so permit() works through delegatecall proxies. Adds a regression test that calls permit via a delegatecall proxy.
Add a direct DOMAIN_SEPARATOR() assertion through the proxy and a negative case (permit signed over the token\u2019s own separator must revert via the proxy). All three tests pass with the fix and fail without it.
@DefiAudit0x
DefiAudit0x marked this pull request as ready for review November 18, 2026 17:56
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.

Domain separator is miscalculated when delegatecalled

1 participant