FHE Encrypted Limit Orders on Uniswap v4
iceberg-cofhe introduces confidential, iceberg-style limit orders to Uniswap v4 using Fully Homomorphic Encryption (FHE) via the Fhenix coprocessor. Limit order data like trade size and direction are encrypted on-chain and privately stored in the Iceberg hook
— enabling privacy-preserving DeFi trading.
🔒 Built with FHE
🦄 Runs as a Uniswap v4 hook
🚀 Enables private, on-chain limit orders
- Users place encrypted limit orders through the hook (
placeIcebergOrder) by providing encrypted values:liquidity: order sizezeroForOne: swap direction
- The
ticklowerprice is public, just like a traditional iceberg order. It shows the price you wish to execute a swap without exposing trade size or direction. e.g. the order could be 1 or 1,000,000 and it could be buying or selling token0/token1. - Orders are stored in a privacy-preserving mapping, protected by FHE.
- In the
afterSwap()callback the hook evaluates encrypted order conditions without leaking user intent. - Once matching conditions are met, decryption is securely requested to fill the order.
- In the next
beforeSwap()callback, the decryption result is requested.- If the decryption is ready, the order is filled.
- Otherwise, the swap lifecycle continues
Requires foundry.
#manage foundry toolchain
foundryup
#install dependencies using npm/pnpm
pnpm install
#flag is required, or else stack too deep errors!
forge test --via-ir
#verbose logging and stack traces
forge test --via-ir -vvvvOther than writing unit tests (recommended!), you can only deploy & test hooks on anvil
# start anvil, a local EVM chain
anvil
# in a new terminal
forge script script/Anvil.s.sol \
--rpc-url http://localhost:8545 \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--broadcastSee script/ for hook deployment, pool creation, liquidity provision, and swapping.
Fhenix 🔒
Uniswap 🦄
Other 🧊
