Darkpool orderbook running inside a Flare Compute Extension (TEE)
Corex is a darkpool spot exchange built on Flare Confidential Execution. Instead of putting the matching engine and internal account state directly on chain, Corex routes user actions into a trusted execution environment that can process deposits, maintain balances, privately match orders, and authorize withdrawals while keeping the exchange logic off the public mempool path.
The user experience is split between onchain settlement and TEE execution.
Users deposit assets into CorexCustody through CorexInstructionSender, and
those deposits are synchronized into the TEE-managed exchange state. Orders can
be submitted either through the onchain instruction flow or as direct EIP-712
signed intents sent to the runtime. Once inside the enclave, Corex maintains
account balances, tracks open and filled orders, and runs deterministic private
matching for the configured market, giving the system a darkpool execution
model rather than a fully transparent onchain order book.
Withdrawals are designed around a stricter trust boundary than a normal app
backend. The runtime validates the user request, checks balances and nonces,
and only then uses the configured TEE signer to authorize the final
finalizeWithdraw(...) custody release onchain. On the frontend side, users
can inspect markets, balances, orders, and activity through wallet-authorized
read routes, so the demo exposes both the confidential execution path and the
operator/developer observability needed to understand what the system is doing.
For the hackathon version, Corex is deployed around a single market on Flare Coston2 with a full local stack: contracts, proxy, TEE runtime, smoke tests, and a Next.js trading frontend. The goal is to show a credible pattern for a TEE-backed darkpool where custody remains onchain, price-time matching remains private to the execution environment, and the user still interacts through familiar wallet signing flows.
Corex is built as a multi-part system rather than a single smart contract app. The architecture is split into the following pieces:
frontend/): a Next.js 16 + React 19 interface with wagmi, viem,
and Reown AppKit for wallet connection, market views, balances, orders,
transfer flows, and direct signed intent submission.corex-tee/contract/): CorexInstructionSender handles
user entrypoints and emits TEE instructions through Flare’s registry, while
CorexCustody escrows tokens and verifies TEE-authorized withdrawals.corex-tee/go/): a Go-based Corex engine that decodes
instructions, maintains in-memory exchange state, runs the private darkpool
matcher, exposes read APIs, verifies direct EIP-712 order and withdraw
intents, and signs withdrawal authorizations with the configured TEE key.corex-tee/docker-compose.yaml): ext-proxy, Redis, and
the extension container bridge onchain instruction events into the local TEE
runtime and expose result polling for contract-backed actions.getState, contract-backed withdraw, and
direct POST /withdraw-intent.Some of the most important implementation details are around signatures and boundary enforcement:
Operationally, the demo is meant to be reproducible. The repo includes the contract deploy path, extension registration flow, tunnel-based TEE registration, runtime docs, API docs, and frontend docs so the system can be stood up locally against Flare Coston2 and inspected end to end.

