Uniswap v4 hook stack that adds privacy-preserving swaps, EigenLayer AVS-backed validation, and cross-chain swap plumbing. This README explains what the project does, how EigenLayer is integrated (with exact contract touchpoints), and how to deploy and operate it.
CrossGuardHook is a Uniswap v4 hook stack designed to make swaps more private and verifiable while remaining chain-agnostic. It adds a commit–reveal flow to hide intent (reducing MEV), leans on EigenLayer AVS operators for batch validation and security, and provides scaffolding to hand off swap payloads across chains via a bridge adapter. The core hook (DarkPoolHook) intercepts swaps, enforces timing/validity, and coordinates with AVS/task managers. Companion managers (DarkPoolServiceManager, DarkPoolTaskManager) plug directly into EigenLayer middleware (AVSDirectory, Registry/Stake/Allocation managers, Rewards, PermissionController) to gate operator participation, tally responses, and emit reward events. Cross-chain support is abstracted behind ICrossChainBridge, keeping bridge risk isolated.
- Commit–reveal swaps (MEV mitigation): Users commit swap intent, wait a minimum block delay, then reveal to execute; the hook enforces timing and authenticity.
- EigenLayer-secured validation: AVS operators validate swap batches; stake-backed security and potential slashing provide economic assurances.
- Cross-chain swap scaffolding: The hook can emit cross-domain swap payloads via a pluggable bridge interface.
src/DarkPoolHook.sol: Uniswap v4BaseHook. Owns commit–reveal state, before/after swap hooks, and cross-chain handoff. References EigenLayer managers for validation.src/DarkPoolServiceManager.sol: Extends EigenLayerServiceManagerBase. Connects to AVSDirectory, Registry/Stake/Allocation managers, Rewards, and PermissionController. Tracks task rewards and records operator validations.src/DarkPoolTaskManager.sol: Issues validation tasks, enforces quorum, and checks operator validity throughSERVICE_MANAGER.isValidOperator.- Interfaces:
src/interfaces/IDarkPoolServiceManager.sol,IDarkPoolTaskManager.sol,ICrossChainBridge.sol. - Docs:
docs/overview.md(high-level) plus any additional integration notes.
- Hook references AVS managers:
DarkPoolHookconstructor takesIDarkPoolServiceManagerandIDarkPoolTaskManagerand stores them as immutables. In_beforeSwap, it can derive a batch hash and (stub) create a validation task when AVS is configured. - Operator validity checks:
DarkPoolTaskManager.respondToTaskcallsSERVICE_MANAGER.isValidOperator(msg.sender, 0)to ensure responders are active EigenLayer operators for the quorum. - Service manager ↔ EigenLayer middleware:
DarkPoolServiceManagerinheritsServiceManagerBasefrom EigenLayer middleware and wires these contracts:IAVSDirectoryfor AVS registrationIRegistryCoordinator+IStakeRegistryfor operator IDs and stake weightsIAllocationManagerfor stake allocations to operator setsIRewardsCoordinatorfor reward distribution plumbingIPermissionControllerfor access control to AVS actionsISlashingRegistryCoordinator(via base) for slashing integration
- Stake and quorum checks:
isValidOperatorusesRegistryCoordinator.getOperatorIdandStakeRegistry.getCurrentStakevsminimumStakeForQuorumto gate operator participation. - Task validation flow:
recordTaskValidationis called by the task manager to log operator participation; rewards can later be computed/distributed through EigenLayer reward submission flows. - Reward path (simplified):
distributeTaskRewardemitsTaskValidationRewardedper operator; comments note where to plug intocreateOperatorDirectedAVSRewardsSubmission. - Slashing posture: While on-chain slashing logic is not fully implemented here, the design expects objective faults to be enforced through EigenLayer’s slashing/coordinator stack.
- Commit: User calls
commitSwapwith pool params, amount, deadline, and secret. Hook storesCommitDatakeyed by hash. - Wait: Enforced
commitPeriod(owner-set, bounded byMIN_COMMIT_PERIOD/MAX_COMMIT_PERIOD). - Reveal: User calls
revealAndSwapwith the secret; hook recomputes the hash, checks deadline and period, then marks revealed. - Before-swap validation:
_beforeSwapensures commit period elapsed and (optionally) derives a batch hash for AVS validation. - Execute swap: In production this would call
poolManager.swap; the current code is a scaffold for integration. - After-swap:
_afterSwapcan initiate cross-chain handling and marks the commit as executed.
- Task creation (stubbed in hook): batch hash can be derived per committed swap set.
- Task responses: Operators call
DarkPoolTaskManager.respondToTask, which:- Verifies operator via EigenLayer stake/quorum (
SERVICE_MANAGER.isValidOperator). - Records response and tallies counts; when quorum is hit, emits
TaskCompleted. - Notifies
SERVICE_MANAGER.recordTaskValidationto persist operator participation.
- Verifies operator via EigenLayer stake/quorum (
- Rewards: Owner can set
taskRewards;distributeTaskRewardemits reward events (integration point for EigenLayer rewards coordinator).
_afterSwapdetects encoded cross-chain payload inhookDataand delegates to_handleCrossChainSwap._handleCrossChainSwapdecodes target chain, recipient, amount, computes aswapHash, and emitsCrossChainSwapInitiated.- Actual bridge call is intentionally abstracted behind
ICrossChainBridge.
commitPeriod: set viasetCommitPeriod(bounded 1–100 blocks).- Pool gating:
setPoolEnabledto allow dark-pool swaps per pool ID. - Bridge target:
setCrossChainBridge. - AVS rewards:
setTaskRewardanddistributeTaskRewardon the service manager. - Quorum thresholds:
createNewTasktakesquorumThreshold; operator validity tied to EigenLayer stake data.
- Prereqs: Foundry, Solidity 0.8.24+, deployed Uniswap v4
PoolManager, EigenLayer core (DelegationManager, AVSDirectory, AllocationManager, Stake/Registry coordinators, RewardsCoordinator, PermissionController, Slasher), and a bridge implementingICrossChainBridge. - Deploy AVS middleware (if not reusing existing): EigenLayer registry/ stake/ allocation infra plus slashing + rewards components.
- Deploy this stack:
DarkPoolTaskManager(args: serviceManager, owner).DarkPoolServiceManager(args: EigenLayer middleware addresses, taskManager).DarkPoolHook(args: poolManager, serviceManager, taskManager, owner).
- Wire + configure:
- Register the AVS in
AVSDirectory. - Set commit period, enable desired pools, set bridge.
- Configure task reward amounts and quorum policy.
- Ensure operators register/allocate stake to the AVS quorums.
- Register the AVS in
- Dry-run:
forge build && forge test(optionally with--gas-report), thenforge scriptagainst an Anvil fork.
- Register as operator:
DelegationManager.registerAsOperator(...). - Receive delegations from stakers.
- Allocate stake to AVS operator sets:
AllocationManager.modifyAllocations(...). - After delay, register to sets:
registerForOperatorSets(...)onSlashingRegistryCoordinator. - Keep stake fresh: call
StakeRegistry.updateOperatorsForQuorum(...)(or use AVS-Sync if available). - Respond to tasks: call
respondToTaskonDarkPoolTaskManagerwith batch hash + response; meet quorum.
- ReentrancyGuard on externals; Ownable + Pausable for emergency control.
- Commit–reveal enforced by block-based delays to mitigate pre-trade MEV.
- Operator gating via EigenLayer stake/quorum checks; rewards/slashing rely on accurate stake updates.
- Bridge abstraction keeps chain assumptions explicit; bridge contract must be audited.
- Unit/integration:
forge test(covers hook/service/task managers and mocks). - Gas:
forge test --gas-report. - Extend with bridge adapter edge cases and AVS signature verification once integrated.
src/: Core contracts (DarkPoolHook,DarkPoolServiceManager,DarkPoolTaskManager, interfaces).test/: Unit and integration tests; mocks for pool manager, bridge, operators.docs/: Additional docs (overview.md, integration guides).lib/: Dependencies (EigenLayer middleware, Uniswap v4 core/periphery, OZ, forge-std).script/: Deployment or simulation scripts (if present).
- Build:
forge build - Test:
forge test - Format (if enabled):
forge fmt
MIT