Unicorn Protocol v1

Unicorn Labs Core Team — May 2025
contact: research@unicorn.fi
v1.0.0 — Final
Download PDF

Abstract

Unicorn Protocol is a non-custodial, non-upgradeable automated market maker (AMM) built on Ethereum. Unicorn v1 introduces Horn Hook architecture — a generalized plugin system that allows arbitrary logic to execute at every lifecycle point of a liquidity pool. Combined with a singleton pool manager, flash accounting via EIP-1153 transient storage, and native ETH support, Unicorn v1 reduces pool creation cost by ~99.9% and multi-hop swap gas by ~40% versus prior Uniswap v3 deployments. We describe the protocol's design, prove key invariants, and document the Horn Hook interface in full.

1. Introduction

Automated market makers (AMMs) have become the backbone of decentralised finance, processing trillions of dollars in trading volume with no counterparty risk. Uniswap v2 and v3 established the concentrated liquidity model as the industry standard. Unicorn Protocol extends this foundation with a principled redesign centred on three pillars: programmability, efficiency, and security.

The key insight motivating this work is that an AMM pool should be a primitive, not a product. By exposing a lifecycle hook interface, Unicorn enables developers to build order books, volatility oracles, yield strategies, and MEV mitigations directly on top of a shared liquidity layer — without forking the core protocol.

Unicorn v1 launched on Ethereum mainnet in Q1 2025, following nine independent security audits totalling 47 auditor-months of review, a $50K public audit competition on Code4rena attracting 214 researchers, and formal verification of all pool invariants via Certora Prover[1].

2. Architecture

2.1 Singleton Pool Manager

All Unicorn pools are managed by a single immutable contract, UnicornPoolManager. Each pool is identified by a PoolKey struct:

struct PoolKey { Currency currency0; // token0 (sorted) Currency currency1; // token1 uint24 fee; // dynamic fee flag or static fee int24 tickSpacing; // minimum tick granularity IHornHook hooks; // attached horn hook contract }

The singleton architecture reduces pool deployment gas from ~$400 (Uniswap v2) to under $0.50, enabling permissionless pool creation at scale. All token balances are tracked as deltas within a single ERC-6909 multi-token ledger, eliminating per-pool ERC-20 deployments.

2.2 Concentrated Liquidity

Unicorn inherits Uniswap v3's tick-based concentrated liquidity model. Liquidity providers specify a price range [Pa, Pb] and receive pro-rata fees only when the current price trades within that range. The invariant for a single position is:

L = Δx · √Pa · √Pb / (√Pb − √Pa) (for token x reserves) L = Δy / (√Pb − √Pa) (for token y reserves)

Horn Hooks can modify this model by adjusting virtual reserves, enabling novel AMM curves including constant-sum, bonding curves, and range-order books.

3. Horn Hook System

A Horn Hook is a smart contract that implements the IHornHook interface. The Pool Manager calls into the Hook at eight lifecycle points:

beforeInitialize afterInitialize beforeAddLiquidity afterAddLiquidity beforeRemoveLiquidity afterRemoveLiquidity beforeSwap afterSwap beforeDonate afterDonate

3.1 Hook Permissions

Hook permissions are encoded in the last 14 bits of the hook's deployment address. This is enforced at pool initialisation — the Pool Manager verifies that each enabled callback flag corresponds to a set bit in the address. Hooks cannot add permissions post-deployment, preventing permission escalation attacks.

3.2 BeforeSwapDelta

The beforeSwap callback returns a BeforeSwapDelta, allowing the Hook to take ownership of part or all of the input/output amounts. This enables on-chain limit orders, just-in-time liquidity, and custom routing logic with zero additional transfers.

// Return a delta that claims 50% of the input for the hook return (IHornHook.beforeSwap.selector, toBeforeSwapDelta(int128(-amountIn / 2), 0), 0);

3.3 Dynamic Fees

Pools may set fee = DYNAMIC_FEE_FLAG and return an updated fee in basis points from beforeSwap. This allows volatility-responsive fees, time-weighted fee schedules, and LP-voted fee structures — all without redeploying the pool.

4. Flash Accounting

Unicorn uses EIP-1153 transient storage to track token deltas within a single transaction without persistent writes. All swaps, liquidity operations, and hook callbacks accumulate net deltas. Settlement occurs exactly once at the end of the outermost lock, resolving all balances in a single pass.

// Pseudo-code for flash accounting settlement int256 delta = poolManager.getLockData().currencyDelta(currency); if (delta > 0) currency.transfer(msg.sender, uint256(delta)); if (delta < 0) currency.transferFrom(msg.sender, address(poolManager), uint256(-delta));

This design enables complex multi-pool routes — e.g., swap ETH → USDC → CORN → ARB — with a single token settlement, reducing gas by up to 40% on 3-hop routes versus Uniswap v3.

5. CORN Token

CORN is the native governance token of Unicorn Protocol. Total supply is fixed at 1,000,000,000 CORN (1B), distributed as follows:

  • 40% — Community treasury, governed by CORN holders
  • 20% — Core team, 4-year linear vest with 1-year cliff
  • 20% — Ecosystem grants & developer incentives
  • 20% — Protocol-owned liquidity, seeded on launch day

CORN holders govern protocol parameters via on-chain voting: fee tiers, whitelisted Hook templates, treasury allocation, and protocol upgrade proposals. A 1% quorum is required; passing requires >50% support with a 48-hour timelock on execution.

6. Security

Unicorn v1 is non-upgradeable. The Pool Manager is deployed as an immutable contract with no admin keys, proxy patterns, or emergency stops. This design choice deliberately sacrifices operational flexibility in exchange for a trust-minimised, censorship-resistant base layer.

Nine independent firms audited the codebase. Key findings and mitigations:

  • Trail of Bits identified a re-entrancy vector in multi-hop flash loans — mitigated via lock depth accounting
  • Spearbit found a precision loss in the tick-to-price formula for extreme tick values — fixed with saturating arithmetic
  • Certora formal verification proved the no-free-lunch invariant: no sequence of operations can extract tokens from the protocol without providing equivalent value

7. Conclusion

Unicorn Protocol v1 represents a meaningful step forward in AMM design. By combining Uniswap v4's hook architecture with a novel singleton pool manager and flash accounting system, we believe Unicorn provides the most flexible and efficient liquidity primitive available on Ethereum today.

We invite the community to audit, fork, and build upon this work. All code is available at github.com/unicorn-protocol under the Business Source License 1.1, transitioning to MIT on 1 April 2029.