AegisJIT: 3 custom SwapVM opcodes on 1inch Aqua. ZK humans pay less, bots pay surge, whales capped.
AegisJIT is a self-custodial just-in-time liquidity vault whose pricing logic lives inside the 1inch SwapVM interpreter. A Maker keeps their capital in two ERC-4626 vaults (USDC and WETH) and ships a single Aqua order whose bytecode is executed by AegisSwapVMRouter, a SwapVM router extended with three custom opcodes. Everything a trade pays is decided by that bytecode, so router.asView().quote() and swap() return the same amounts to the wei: every custom opcode is view-safe, with no storage writes on the quote path.
The three opcodes:
0x2A ZKIdentityGuard (46-byte args). A taker can attach a zero-knowledge proof of personhood to takerData: a World ID Orb proof (type 1) or an Anon Aadhaar Groth16 proof generated from the Aadhaar Secure QR (type 2). The opcode routes the payload to the matching verifier adapter. The proof is bound to the taker address (signal) and its nullifier stays with the first address that used it, so one person is one trader. In tiered mode nothing ever reverts: a valid proof buys the verified-human tier, no proof means the taker is priced as a bot. A strict mode and an optional jurisdiction check exist for compliance use. After the first proof a 33-byte binding claim replaces the proof for the epoch, which costs about 5k gas instead of 225k (World ID) or 288k (Aadhaar). Aggregators can trade on behalf of a verified user with an EIP-712 authorization.
0x9A JITVaultReserves (86-byte args). Reads the Maker's real ERC-4626 balances by staticcall and exposes only lambda = 25% of them per execution and per 600-second window (a token-bucket budget), with a 2x virtual concentration around the current price. A 500,000 USDC whale reverts with JITExposureCapExceeded; four 25% executions in one block fill once and revert three times. The other 75% never leaves the vault and keeps earning. A hook withdraws the exact slice just in time and re-deposits the proceeds in the same transaction.
0x7A VolatilitySurgeFee (20-byte args). A dynamic LVR and toxic-flow fee: 0.30% base, halved to 0.15% for verified humans, plus a 1.5% marginal surge on flow beyond 1% utilisation of the active reserves. The flow bucket is on a fixed time grid, so splitting an order inside a window buys nothing: five 10k trades pay the same fee as one 50k trade and receive slightly less. Rounding always favours the Maker, which keeps the curve sub-additive and monotonic.
Identity stack. World ID runs through IDKit 4.x with relying-party-signed requests; on World Chain Sepolia the adapter verifies proofs through the chain's real World ID Router (proofs come from World App or the World ID Simulator). Locally and on Ethereum Sepolia, Semaphore depth-30 proofs are generated in the browser and checked by World ID's own SemaphoreVerifier. Anon Aadhaar proofs are produced by a local prover from a signed Secure QR after an in-browser RSA-2048 check; the QR never leaves the user's machine. Both passes land on the identical fee tier.
What is proven. 128 Hardhat tests with real Groth16 proofs and 19 Foundry property tests cover quote == swap, exact-in/exact-out symmetry within 2 wei, sub-additivity against split orders, monotonicity, tier differentiation and the lambda cap. A judge demo script runs the scenarios end to end with real proofs in about 17 seconds.
What is live. Ethereum Sepolia: 15 source-verified contracts and a recorded 10-scenario run. World Chain Sepolia: 13 verified contracts and a 10-scenario run that includes a real World ID proof executed on-chain (582,931 gas against a 335,741 gas bot baseline). A hosted dashboard decodes the live order from Aqua's Shipped event, quotes every profile (human, bot, split attacker, whale), shows the surge bucket and the vault exposure, and lets a judge verify through the World ID Simulator against the real router: https://aegis-jit.niklabh811.workers.dev. Code, byte layouts and the threat model are in the repo: https://github.com/niklabh/aegis-jit-amm.
Honest limits. USDC and WETH are mintable mocks on the testnets, the Aadhaar signer is a published test key rather than UIDAI's, the Aadhaar circuit's timestamp and state public signals can still link trades across epochs.
The repo was started from template https://github.com/1inch/swap-vm-template.git Thats why it has old commits. The real work started from commit id 29ba759565c54a1fd5cc1d2665dc5d796014e086.
Contracts. AegisSwapVMRouter inherits 1inch's SwapVM (v1.0.1/1.0.2) and AquaOpcodes and overrides _dispatch(ctx, opcode, args): opcodes 0x2A, 0x9A and 0x7A go to three instruction libraries in contracts/instructions/, everything else falls through to the stock interpreter. The libraries work only on SwapVM's Context struct (balanceIn/balanceOut, amountIn/amountOut, isExactIn, maker, taker, takerData via tryChopTakerArgs), use SwapVM's own 1e7-bps fee precision, and never write storage on the quote path, which is what makes router.asView().quote() equal to swap(). AegisJITStrategy builds the order bytecode on-chain, AegisJITVaultHook does the just-in-time ERC-4626 withdraw and re-deposit around Aqua.pull/push, AegisZKForwarder is a reference aggregator that trades for a verified user with an EIP-712 TakerAuthorization. Identity verifiers hide behind one IZKVerifier interface: WorldIDAdapter (calls a World ID router's 6-argument verifyProof) and AnonAadhaarAdapter (vendored snarkjs Groth16 verifier, BN254 ecPairing). The router runtime is 22.6 KB of the 24,576-byte EIP-170 limit, so opcode argument layouts are packed by hand (46, 86 and 20 bytes) and the order bytecode is compiled by a TypeScript ProgramBuilder that mirrors SwapVM's [opcode][len][args] framing.
Identity payloads. A takerData payload is a 22-byte takerTraits header plus a typed envelope: type 1 World ID (root, epoch, nullifierHash, proof[8], 320 bytes) or type 2 Anon Aadhaar (timestamp, epoch, pubkeyHash, proof[8], 352 bytes), each optionally followed by the EIP-712 authorization. The header encodes slice offsets that depend on the payload length, so the UI keeps one header per payload type and appends a fresh proof. The proof signal is the taker address; the nullifier is bound to the first address that used it. After the first proof a 33-byte binding claim costs one storage read instead of a pairing (5k gas instead of 225k or 288k).
World ID. In the browser the World ID tab generates a Semaphore v3 depth-30 proof with snarkjs over the public PSE artifacts (self-hosted, same verification key as World ID's SemaphoreVerifier) and checks it by eth_call before attaching it. For real World ID, IDKit 4.x (IDKitRequestWidget with the orbLegacy preset, allow_legacy_proofs and signal = taker) talks to World App or the World ID Simulator; IDKit 4 requires every request to be signed with the app's relying-party key, so a small server signs rp_context with @worldcoin/idkit-core/signing. That server is the local prover process in development and a Cloudflare Worker on the hosted dashboard; the key never reaches the browser. On World Chain Sepolia the adapter is wired to the chain's real World ID Router and the recorded run executed a Simulator proof on-chain.
Anon Aadhaar. The Aadhaar Secure QR is decoded with zxing-wasm, decompressed with pako, parsed and RSA-2048-verified with Web Crypto in the browser, then proven with the official Anon Aadhaar v2 circuit (artifacts ~620 MB, SHA-256 pinned, about 12 seconds and a few GB of RAM per proof) by a prover on 127.0.0.1 only, so QR data never leaves the machine. Tests and demos use a signed test QR from a published test signer, clearly marked as not UIDAI. Nullifiers rotate per 24-hour epoch with a grace window.
Tooling. Hardhat + Mocha (128 tests, real proofs included), Foundry property tests (19) through a SwapVMImport shim and a forge-std sync step, hardhat-dependency-compiler for 1inch's sources, TypeChain, viem in the UI. Vite + React + Tailwind dashboard: a disassembler that decodes the live order from Aqua's Shipped event frame by frame, a quote simulator per taker profile with an independent TypeScript mirror of the opcode math checked against the chain, a split-attack sandbox on evm_snapshot/evm_revert, and a vault exposure panel. Deployment scripts are resumable with checkpoints, verify through Etherscan API V2 (Worldscan is chainid 4801 on the same API), and the public-chain demo runner writes demo.json after every scenario. The dashboard is hosted on Cloudflare Workers as static assets plus the signing Worker; the client switches to same-origin endpoints whenever it is not served from a loopback host.
Partner technologies. 1inch Aqua and SwapVM gave us a shared liquidity layer with programmable orders, so the whole protocol is three opcodes and a hook rather than a new AMM. World ID gives Sybil resistance with a nullifier we can bind on-chain; Anon Aadhaar (PSE) gives Indian users a sovereign alternative on the same tier; the USDC side of the Maker's capital sits in an ERC-4626 vault and keeps earning while 75% of it is never exposed.
Hacky bits worth knowing. (1) Hardhat executes eth_call at the latest block timestamp while the next block is at least one second later, so any per-second fee decay breaks quote == swap; both the surge bucket and the lambda budget therefore live on a fixed time grid, constant inside a window and leaking one threshold per elapsed window. (2) The hosted World ID Simulator only resolves apps registered in the production Developer Portal; our first app lived in the staging portal and the Simulator reported "App not found", so the first live run injected the app metadata into the Simulator's page store from the browser console, after which we re-registered the app and redeployed the adapter cleanly. (3) Public load-balanced RPC replicas can lag a block, which made one pre-swap quote look wrong; the demo runner now pins every read to the block of its latest receipt. (4) The fee mirror in the UI is a deliberate second implementation of the opcode math, so a mismatch shows up as a red badge instead of a silent wrong number.

