Skip to content

Add zkTLS prediction market example#34

Open
critesjosh wants to merge 6 commits intonextfrom
add-zktls-prediction-market
Open

Add zkTLS prediction market example#34
critesjosh wants to merge 6 commits intonextfrom
add-zktls-prediction-market

Conversation

@critesjosh
Copy link
Copy Markdown
Contributor

@critesjosh critesjosh commented Apr 2, 2026

Summary

Adds a complete private prediction market example on Aztec: binary outcome markets (e.g. "Will BTC be above $50k by July 1?") with real token collateral, provable solvency, and trustless CoinGecko price resolution via Primus zkTLS attestations.

Architecture

  • Complete-set model for provable solvency: mint_sets(n) deposits n collateral and mints n YES + n NO shares; burn_sets(n) reverses it; redeem(n) pays out winning shares 1:1 after resolution. Invariant: total_collateral = total_yes = total_no always holds.
  • Private CLOB (Central Limit Order Book) for peer-to-peer trading: place_order deposits collateral and stores a limit order publicly with maker identity hidden in an encrypted partial note; take_order fills the order by minting a complete set and distributing YES to one party and NO to the other; cancel_order reclaims collateral via a secret preimage (order_id = Poseidon2(cancel_secret)).
  • zkTLS resolution: ECDSA verification of Primus attestations in a private circuit, with trusted attester pinning (Poseidon2 hash of attester pubkey stored at deployment), URL allowlisting, and a 7-day resolution window.
  • Real token collateral via defi-wonderland/aztec-standards Token contract with auth witness flow.

Privacy properties

  • Maker/taker identities: private (hidden in partial notes)
  • Share balances: private (encrypted notes)
  • Redemption: private
  • Order price/amount/side: public (necessary for book to function)

What's included

  • Noir contract (src/main.nr): complete sets, CLOB, token integration, zkTLS resolution (~650 lines)
  • Order struct (src/order.nr): Packable impl packing is_buy_yes into LSB of price field, with unit tests
  • Price parser (src/price.nr): ASCII decimal to integer cents, with unit tests
  • TypeScript scripts: attestation parsing, URL hash computation, deployment/resolution demo
  • Integration tests (tests/): deployment, mint/burn sets, place/take/cancel orders, resolution, redemption, guard rails
  • React webapp (webapp/): full trading UI with embedded + extension wallet support, CLOB order book, in-browser attestation generation via Primus SDK, session persistence via localStorage

Test plan

  • cd prediction-market-zktls && yarn install
  • yarn ccc compiles contract and generates TypeScript bindings
  • yarn test:noir passes Noir unit tests (price parser, order pack/unpack)
  • yarn test passes integration tests against local Aztec network (deployment, complete sets, CLOB orders, resolution, redemption)
  • cd webapp && yarn install && yarn dev starts the webapp locally

🤖 Generated with Claude Code

critesjosh and others added 6 commits April 1, 2026 22:16
…rimus price attestations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ateral

Replace AMM-based pricing (CSMM) with a complete-set model where users
mint/burn YES+NO share pairs backed 1:1 by collateral tokens. Integrates
defi-wonderland/aztec-standards Token contract for real token transfers.
Adds resolution window, private ECDSA verification, and provable solvency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ss API

Scripts and tests now use TokenContract.deployWithOpts constructor_with_minter
instead of deploying with initial supply. Token distribution uses mint_to_private.
Auth witness creation updated to wallet.createAuthWit(account, { caller, action })
pattern with authWitnesses passed in send options.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Store Poseidon2 hash of the Primus attester's secp256k1 public key in
contract storage at deployment. resolve_market now rejects attestations
from unknown signers, closing the gap where any self-generated key pair
could resolve the market.

Switch attestation generation from proxy-TLS to MPC-TLS mode (mpctls),
where client and attester collaboratively compute TLS session keys so
neither party can unilaterally forge data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace AMM with a private Central Limit Order Book (CLOB) for
peer-to-peer limit orders with full identity privacy. Add React
webapp with embedded/extension wallet support, session persistence,
order book UI, and in-browser zkTLS attestation generation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant