Repository navigation
Fix domain separator miscalculation under delegatecall - #439
Open
DefiAudit0x wants to merge 2 commits into
Open
DefiAudit0x wants to merge 2 commits into
DefiAudit0x wants to merge 2 commits into
Conversation
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
marked this pull request as ready for review
November 18, 2026 17:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #415
Problem
DOMAIN_SEPARATOR()returns the cachedINITIAL_DOMAIN_SEPARATORwheneverblock.chainid == INITIAL_CHAIN_ID— even when the token is executed viadelegatecallfrom another contract. In that contextaddress(this)is the calling proxy, not the token, so the cached separator (computed at deployment for the token's own address) is wrong, andpermit()reverts withINVALID_SIGNERfor 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 andaddress(this) == INITIAL_VERIFYING_CONTRACT; otherwise recompute it viacomputeDomainSeparator().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 callspermitthrough the proxy;testDomainSeparatorViaDelegatecall, which asserts the separator returned through the proxy equals the recomputed proxy-context separator; andtestPermitViaDelegatecallWithTokenSeparatorReverts, which asserts a permit signed over the token's own separator reverts withINVALID_SIGNERthrough the proxy.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 thetestFailprefix in v1.0), so the full suite runs but 278 tests fail on the pre-existingtestFail*removal; the new tests are written in the current style and pass standalone.