← Back to index

ContextCoin (CTX) Formal Specification

This document provides a formal specification for the ContextCoin (CTX) smart contract on the Solana blockchain. The goal is to precisely define the program's behavior, state transitions, and invariants to allow for rigorous analysis, testing, and formal verification.

State Space

The state of the system is defined by a tuple $S = (O, M, T, S_s, B, C, E, R)$, where:

Invariants

The following system-wide invariants must always hold true.

  1. $0 \leq S_s \leq T$: The number of CTX tokens sold must always be within the bounds of total supply.
  2. The escrow balance is always greater than or equal to 0.

Instructions and State Transitions

InitializeIco

BuyTokens

SellTokens

WithdrawFromEscrow

CreateResourceAccess

AccessResource

Security Properties

  1. Double Spending Prevention: It is impossible to spend the same tokens more than once. This is guaranteed by the SPL Token program and Solana's transaction execution model.
  2. Authorization: Only the owner of the ICO is allowed to withdraw from the escrow account.
  3. Fee Control: The server sets access fees for the resource, and the program ensures the correct fee is paid.
  4. Token Supply Guarantee: The program guarantees that no new tokens can be minted past the total supply amount.
  5. Rate Limiting Guarantee: By combining per-request payments, the servers can add rate limiting mechanics and increase the costs of exploitation.

Conclusion

This formal specification provides a rigorous description of the ContextCoin program. It enables the creation of tools for testing, verification, and improved trust in the program's correctness. Future work will involve building more complex models and proofs.