Skip to content

Virtual permit2 fetch for chains with different create2 paths.#187

Open
reednaa wants to merge 1 commit into
mainfrom
permit2-virtual
Open

Virtual permit2 fetch for chains with different create2 paths.#187
reednaa wants to merge 1 commit into
mainfrom
permit2-virtual

Conversation

@reednaa

@reednaa reednaa commented Jun 10, 2026

Copy link
Copy Markdown
Member

Description

Makes the Permit2 contract address overridable in InputSettlerEscrow so the settler can be deployed on chains where Permit2 does not live at the canonical address.

Previously the Permit2 address was a hardcoded constant (0x000000000022D473030F116dDEE9F6B43aC78BA3). That address is the product of an EVM-specific deterministic CREATE2 deployment and cannot be reproduced on chains with different address derivation (e.g. Tron). This PR replaces the constant with an internal pure virtual hook, _PERMIT2(), that defaults to the canonical address, and points the single call site in _openForWithPermit2 at it.

Subclasses can now override _PERMIT2() to return a chain-specific Permit2 address — mirroring the existing _domainName() / _domainVersion() override pattern. There is no constructor change, so existing deterministic CREATE2 deployment addresses and salts on EVM chains are unaffected.

Changes:

  • src/input/escrow/InputSettlerEscrow.solconstant PERMIT2_PERMIT2() virtual getter; call site updated.
  • test/input/escrow/InputSettlerEscrowPermit2Override.t.sol (new) — proves a subclass override is honored and that openFor collects inputs end-to-end through the overridden Permit2 (fuzzed).
  • snapshots/*.json — regenerated gas snapshots.

Related Issues

Additional Notes

  • The hook is pure because the default returns a literal; overrides returning a compile-time constant remain pure-compatible.

Summary by CodeRabbit

Release Notes

  • Tests

    • Added test coverage for Permit2 address override verification and token settlement routing
  • Chores

    • Updated test snapshots for settler configurations
    • Refactored internal escrow contract to support configurable Permit2 address resolution

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "enabled"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

This PR enables chain-specific Permit2 address overrides by replacing a hardcoded constant with an overridable virtual function in InputSettlerEscrow. A comprehensive test demonstrates the override mechanism works correctly, and snapshot values are updated accordingly.

Changes

Permit2 address override mechanism

Layer / File(s) Summary
Permit2 override function abstraction
src/input/escrow/InputSettlerEscrow.sol
Remove hardcoded PERMIT2 constant and introduce _PERMIT2() as an internal pure virtual function. Update _openForWithPermit2 to call _PERMIT2().permitWitnessTransferFrom(...) instead of the constant reference.
Permit2 override test suite
test/input/escrow/InputSettlerEscrowPermit2Override.t.sol
Add InputSettlerEscrowExposed and InputSettlerEscrowPermit2Override helper contracts that override _PERMIT2() to return an alternate address. Implement test_open_for_permit2_routes_through_overridden_address to verify escrowing occurs through the overridden Permit2 instance using vm.etch code injection.
Snapshot parameter updates
snapshots/inputSettler.json, snapshots/outputSettler.json
Update preset parameter values for order IDs, escrow amounts, timestamp bounds, and coin-fill variants across all snapshot keys.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • frangio
  • pepebndc

Poem

🐰 Constants hardcoded, now they bend,
A virtual function becomes a friend,
Chain-specific Permits now can sway,
Tested through and through today!
Hop skip jump — override your way! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change: making Permit2 address overridable for chains with different CREATE2 paths.
Description check ✅ Passed The description comprehensively covers the purpose, implementation details, test coverage, and related issues, following the template structure with all critical sections addressed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch permit2-virtual

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

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

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/input/escrow/InputSettlerEscrow.sol (1)

277-284: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix forge formatting failure on the chained Permit2 call.

forge fmt --check is failing on Line 277-Line 284, which blocks CI. Reformat this call to match the formatter’s expected chained style.

Proposed formatting-only fix
-        _PERMIT2().permitWitnessTransferFrom(
+        _PERMIT2()
+            .permitWitnessTransferFrom(
             permitBatch,
             transferDetails,
             signer,
             Permit2WitnessType.Permit2WitnessHash(order),
             Permit2WitnessType.PERMIT2_PERMIT2_TYPESTRING,
             signature
         );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/input/escrow/InputSettlerEscrow.sol` around lines 277 - 284, The chained
call to _PERMIT2().permitWitnessTransferFrom is misformatted and failing forge
fmt; reformat the expression so the receiver and method call are split per the
formatter's chained-call style: put _PERMIT2() then a dot and the method name on
the next line, place each argument (permitBatch, transferDetails, signer,
Permit2WitnessType.Permit2WitnessHash(order),
Permit2WitnessType.PERMIT2_PERMIT2_TYPESTRING, signature) on its own line with
trailing commas, and close with the matching ); ensuring indentation and no
extra trailing spaces so forge fmt passes.

Source: Pipeline failures

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/input/escrow/InputSettlerEscrow.sol`:
- Around line 277-284: The chained call to _PERMIT2().permitWitnessTransferFrom
is misformatted and failing forge fmt; reformat the expression so the receiver
and method call are split per the formatter's chained-call style: put _PERMIT2()
then a dot and the method name on the next line, place each argument
(permitBatch, transferDetails, signer,
Permit2WitnessType.Permit2WitnessHash(order),
Permit2WitnessType.PERMIT2_PERMIT2_TYPESTRING, signature) on its own line with
trailing commas, and close with the matching ); ensuring indentation and no
extra trailing spaces so forge fmt passes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: abfa99a0-0dcd-4783-bf36-4bb6300a3be9

📥 Commits

Reviewing files that changed from the base of the PR and between f94e849 and b2d43ab.

📒 Files selected for processing (4)
  • snapshots/inputSettler.json
  • snapshots/outputSettler.json
  • src/input/escrow/InputSettlerEscrow.sol
  • test/input/escrow/InputSettlerEscrowPermit2Override.t.sol

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.

1 participant