Overview
TokenSwap is the first service-matching application built with OpenContract. It matches Buyers that need AI inference capacity with Sellers that can provide otherwise-idle API, subscription, bundle, or committed capacity during a defined future time window. The traded object is an AI Usage Ticket, not an API key and not a financial token. A ticket is a non-transferable right to consume a bounded AI inference service under an agreed policy:- a provider and model tier;
- a start and end time window;
- a maximum spend and/or usage allowance;
- reserved throughput, rate limits, and concurrency;
- allowed use and content policy;
- availability, refund, and penalty rules;
- evidence, receipt, and logging requirements.
In TokenSwap, usage tokens are model input, cached-input, and output units. They are unrelated to any future OpenContract protocol or governance token.
Why TokenSwap Uses OpenContract
A conventional API proxy can route requests and collect payment, but it does not create a neutral, auditable agreement between a capacity Buyer and Seller. TokenSwap applies OpenContract’s service-contract primitives to continuous machine-delivered work:
TokenSwap is not forced into the ordinary one-time-delivery settlement formula. It is a specialized
usage_capacity contract whose payment is calculated from signed usage, reserved availability, and SLA credits.
Participants
Each participant has a defined responsibility and a corresponding trust boundary: facts or decisions that cannot be established by that participant’s claim alone.
The Gateway Operator is a distinct protocol role. OpenContract may operate the first Gateway, but the contract must not assume that OpenContract and the Gateway Operator are permanently the same entity. Future tickets may select an OpenContract-operated TEE, a qualified third-party TEE, or another approved gateway implementation.
Separation of Control
TokenSwap separates money and adjudication from secrets and execution:OpenContract controls
- ticket creation, matching, and lifecycle state;
- Buyer escrow, Seller Stake, and Dispute Bond;
- the committed policy hash and approved TEE measurement;
- receipt checkpoints and the final evidence commitment;
- deterministic settlement and escalation to dispute resolution;
- refunds, payouts, and slashing.
TEE Gateway controls
- the Seller’s scoped upstream credential;
- Buyer request authentication and replay protection;
- request and response plaintext inside the protected execution boundary;
- time-window, quota, rate-limit, and model-policy enforcement;
- provider invocation;
- quota state and receipt sequence;
- receipt signing and evidence-log commitments.
AI Usage Ticket
A ticket is a policy-bound capacity contract. Its canonical serialization is hashed, andpolicyHash is committed through OpenContract before credential provisioning or usage begins.
Core ticket fields
maxCost is required even when a ticket also specifies token allowances. Input, cached-input, output, and multimodal units may have different prices and throughput weights; a token count alone is not a safe financial limit.
Pricing model
The preferred contract separates capacity reservation from actual use:- The Reservation Fee compensates the Seller for holding capacity available, even if the Buyer does not use it.
- The Usage Charge is calculated only from verified receipts.
- Unused Usage Escrow is refunded.
- Seller failure reduces the Availability Factor and may trigger SLA credits or stake slashing.
- Seller Stake should cover credible replacement-cost exposure, not only a fixed percentage of ticket price.
TEE Attestation and Credential Provisioning
The Seller does not encrypt a credential to a permanent platform key. It provisions the credential only after verifying a fresh TEE instance: The Seller-provided credential should be:- dedicated to one ticket or a narrowly bounded ticket pool;
- restricted to agreed models, endpoints, projects, and regions where supported;
- protected by an upstream hard spend and throughput limit;
- short-lived or immediately revocable;
- deleted or revoked when the ticket closes.
Request Lifecycle
Every accepted request is authorized by the Buyer and processed against the committed policy: Rejected and failed requests also produce signed denial receipts. Standard status classes include:outside_window;invalid_signature;nonce_replayed;buyer_rate_limited;quota_exhausted;policy_rejected;provider_rate_limited;provider_error;gateway_unavailablewhen externally provable.
Usage Receipts
Public usage receipt
The settlement-safe receipt excludes prompt and response plaintext:Private evidence envelope
Evidence that may expose Buyer content is encrypted separately:Evidence Storage and Checkpointing
Every receipt must be durable, but every full receipt does not need to be stored in OpenContract or posted on-chain.Periodic checkpoint
The TEE submits a checkpoint after a configured number of receipts, elapsed time, or uncommitted value:- the TEE signature and measurement are approved;
policyHashmatches the ticket;- sequence ranges are continuous;
- the receipt hash chain connects to the previous checkpoint;
- cumulative usage never decreases;
- remaining quota never increases except through an explicit contract amendment;
- the checkpoint is newer than the last accepted state.
maxUncheckpointedExposure limits the value the TEE may consume without a successful checkpoint. When the threshold is reached, new calls pause until the checkpoint is accepted.
Final receipt
At expiry or exhaustion, the TEE revokes or deletes the credential and signs the final state:Evidence Chain
The complete cooperation record is:Crash-safe metering
The TEE persists acall_intent and reserves quota before invoking the provider. It finalizes the receipt only after receiving provider usage metadata. If the TEE crashes after the provider may have charged the Seller but before finalization, recovery exposes an indeterminate call rather than silently dropping it. The provider request ID and billing record are then used for reconciliation.
TEE sealed storage protects confidentiality but does not by itself prevent an operator from restoring an old encrypted snapshot. Recovery must reject any quota or sequence state older than the latest OpenContract checkpoint. Upstream hard spending limits remain the final loss bound.
Verification and Disputes
TokenSwap resolves deterministic evidence before recruiting Backup Agents:
Backup Agents do not vote on cryptographic facts such as whether a signature is valid or whether a timestamp falls inside a window. They adjudicate only evidence that deterministic verification cannot resolve.
TEE attestation proves that approved code issued the invocation and receipt under the committed policy. It does not cryptographically prove which model weights an upstream provider executed internally. Model-integrity claims therefore use combined evidence rather than TEE evidence alone.
Settlement
At ticket close:- The TEE submits the final receipt and evidence root.
- OpenContract verifies the TEE signature, measurement, policy hash, checkpoint continuity, and deterministic SLA calculations.
- The Buyer approves or enters the optimistic review window.
- A dispute posts the configured Dispute Bond and identifies the contested receipt range or SLA claim.
- Deterministic checks run first; unresolved claims recruit qualified dispute resolvers.
- OpenContract pays verified usage and earned reservation fees, refunds unused escrow, applies SLA credits, returns or slashes Seller Stake, and resolves the Dispute Bond.
fully_met, partially_met, or none_met for compatibility with Working Contract outcomes, but the payout amount comes from usage-capacity settlement rules rather than an unweighted count of acceptance criteria. An all-unclear dispute must not default automatically to full Seller payment.
Protection and Verification Matrix
TokenSwap uses several complementary controls. Encryption protects confidentiality, isolation limits access, hashes bind data and state, signatures authenticate actors and receipts, and attestation authenticates the TEE execution environment. No single control proves that the complete system is correct.Trust Model
Properties TokenSwap targets
- The Buyer never receives the Seller credential.
- The Seller does not receive Buyer prompt plaintext from the Gateway.
- The ordinary OpenContract backend cannot read the credential, prompt, response, or TEE signing key.
- The Buyer cannot create billable usage without signing a request.
- The Seller cannot deny Buyer-authorized successful calls that have Buyer-held receipts.
- The Gateway Operator cannot change code or policy without changing the attested measurement or policy hash.
- OpenContract cannot create a valid TEE receipt without the attested receipt key.
- Credential scope, upstream limits, checkpoints, escrow, and stakes bound the loss from failures that cryptography cannot prevent.
Residual trust and failure modes
TEE execution does not prevent:- the Gateway Operator from stopping the machine or blocking its network;
- hardware, firmware, side-channel, or attestation-service failures;
- bugs in approved Gateway code or provider adapters;
- the Seller revoking a credential during the service window;
- the upstream provider misreporting or internally changing a model;
- policy-compliant but harmful or illegal requests.
MVP and Evolution
Closed MVP
The first test may use one Buyer and one Seller, one provider adapter, test-value escrow, and an OpenContract-operated Gateway. Its purpose is to validate the ticket lifecycle and evidence semantics:- create and match an AI Usage Ticket;
- commit a policy hash;
- provision a dedicated, capped, revocable credential;
- authenticate Buyer requests;
- enforce window, quota, and rate limits;
- generate usage and denial receipts;
- build a receipt hash chain and periodic roots;
- submit a final receipt;
- exercise approval, a simulated dispute, and settlement.
gatewayType: platform.
TEE-Ledger
Move receipt signing, quota state, sequence state, and checkpoint construction into an attested environment. Add sealed-state recovery and rollback protection.TEE Gateway
Move credential provisioning and the complete Buyer-to-provider request path into the TEE. Buyer requests and provider responses remain encrypted outside the attested environment.Verification TEE and open supply
Add pre-listing and pre-window verification of Seller access, multiple qualified Gateway Operators, provider billing reconciliation, supplier authorization classes, and redundant TEE deployments.Non-goals
TokenSwap is not:- an API-key marketplace;
- an account- or subscription-sharing product;
- a transferable claim on future cash flows;
- a prediction market;
- a secondary market for an OpenContract protocol token;
- proof that an upstream provider internally executed particular model weights;
- a replacement for provider terms, supplier authorization, privacy review, or applicable regulation.