Careers

Technical Overview of C3: Everything you need to know

Technical Overview of C3: Everything you need to know

C3 is a self-custodial exchange that utilizes a hybrid architecture combining off-chain and on-chain components for maximum performance and security. The off-chain component handles instant trade processing and matching, while the on-chain component handles trade settlement. This innovative hybrid architecture allows C3 to offer a trading platform that is both performant and accessible, similar to traditional exchanges, while remaining trustless and non-custodial at all times. This means that C3 users can enjoy the security and autonomy of a self-custodial exchange without compromising on the functionality, performance, and ease of use that they have come to expect from traditional exchanges.

Moreover, the on-chain component of C3 is designed to provide broad compatibility and accessibility by supporting multiple signing algorithms and cryptographic curves. This allows C3 to support all wallets and blockchain networks, giving users maximum flexibility and versatility in terms of how they choose to custody their assets and from which blockchain networks they prefer to access C3.

How C3 works

Architecture Components

C3’s architecture is structured into three layers. The first one is the access layer, where users can interact with C3 either directly through traditional APIs or via C3’s frontend. The second layer is a middleware off-chain component that handles most of the computation, providing optimal performance for C3, and the third layer is the on-chain component where trustless trade settlement and other verifications are carried out.

C3 Architecture Overview

C3 Off-Chain Component

C3 enables high-performance and efficient trading thanks to its advanced middleware consisting of an exchange server that operates off-chain. This off-chain component hosts the Central Limit Order Book (CLOB) and serves as the trading hub where trade operations are received, approved, and matched by the risk engine and matching engine, respectively. The off-chain Risk Engine is responsible for approving and validating trade orders and other account operations, including borrow requests from the lending pool for margin spot trading. If an account falls below the required maintenance margin, liquidators can initiate the liquidation process by verifying the request through the off-chain Risk Engine. The off-chain Order Book and Matching Engine receive and process trade orders in real-time using a specific matching logic to match limit and market orders. All trades are recorded in a database, while matched trades are sent to the blockchain for settlement.

C3 benefits from having an off-chain component in the following ways:

  • Faster Trade Execution: C3 offers low-latency trading as off-chain matching engines can process trades much faster than on-chain order books by not being constrained to blockchain speeds.
  • No Gas Costs: Orders are posted and canceled for free without having to pay on-chain transaction fees thanks to the off-chain matching process.
  • Scalability: Off-chain matching engines can handle a much larger volume of trades than on-chain order books, making it ideal for high-volume trading markets.
  • Privacy: Off-chain order books keep trade activity private, allowing traders to keep their open trades confidential.
  • Advanced Features: Off-chain servers can be leveraged to implement sophisticated features such as advanced order types including TWAP, VWAP, and conditional orders.


C3 On-Chain Component

C3’s on-chain smart contract architecture is what enables it to remain trustless and self-custodial. This on-chain component verifies every single matched trade by validating the signatures of both buyer and seller and the health of their accounts before allowing settlement to take place and transferring ownership of the traded assets.  The same validation process applies to all other operations, including borrows, lends, liquidations, and withdrawals.

C3 Smart Contracts:
C3’s on-chain component consists of two smart contract applications, the Cross-collateral Clearing Engine and the Health Calculator, which are deployed on the Algorand blockchain and serve as C3's settlement layer.

C3 On-Chain Smart Contracts

The Cross-collateral Clearing Engine is the core smart contract of C3. It manages the funds deposited by users, approves and executes all trade settlements, as well as facilitates withdrawal, borrow, lend, and liquidation operations. This contract uses cryptographic primitives to verify user signatures when processing these operations. In addition, the contract has an embedded Lending Pool that allows users to lend their deposits to margin traders and earn yield. This Lending Pool provides the funding needed to power margin trading in C3’s spot markets.

Only the C3 settlement key, held in the off-chain component, can interact with the Cross-collateral Clearing Engine smart contract. Upon completion of off-chain operations, such as a matched trade, the off-chain component sends a transaction to the smart contract containing in its data the signed instructions from the users involved in the trade. The Cross-chain Collateral Engine verifies the buyer’s and seller’s signatures and checks with the Health Calculator to ensure the accounts have enough health before accepting the trade and transferring ownership of the traded assets.

The Health Calculator smart contract serves as C3’s on-chain risk engine. It calculates the health of all C3 accounts by using the on-chain Pyth price feed to determine the value of all assets held in each account. This makes the Health Calculator completely independent from the off-chain risk engine.

As can be appreciated, the entire off-chain logic is replicated on-chain without relying on any calculation done off-chain. This ensures that, despite the work being done by the off-chain component, C3 remains entirely trustless and self-custodial. Each operation must be signed by the user’s key for the on-chain component to approve it and the operation must be financially valid as determined by the on-chain health calculations.

C3 Security

In addition to being self-custodial, trustless, and transparent, C3’s architecture  is designed with in-depth security as a top priority making it a reliable choice for users. C3’s exchange leverages its multi-layered approach to ensure assets are protected. The only way the exchange can interact with the smart contract is through the C3 settlement key, drastically reducing the attack surface of the system. Even if there were to be a smart contract logic vulnerability, the attacker would still need to somehow gain access to the settlement key to exploit the vulnerability. Furthermore, in the event that the C3 settlement key is leaked or that C3 tries to behave maliciously, no damage can be done without the user signature as funds are controlled by the user’s key and all operations, including trades and withdrawals, require the signature of the user.  A malicious actor would need both the user’s key and the C3 settlement  key in order to successfully execute any operation making it impossible for an unauthorized actor to execute an operation without the user's consent.

The system also has strong redundancies to ensure that all operations are thoroughly vetted. The off-chain component approves trades and other operations, but these are then independently re-validated on-chain before they are executed. This double verification of operations makes it nearly impossible for a malicious actor or incorrect logic to execute an operation without it being detected. This ensures that if the off-chain component makes a mistake or acts maliciously, the on-chain risk engine will still need to validate that operation using on-chain information giving the system independent backup checks while making it transparent and auditable. In summary, C3's self-custodial and trustless nature, in combination with its multiple layers of security, make it an extremely reliable exchange.

C3's Multi-Layered Security

C3 Multi-chain Architecture

C3 is built as a natively multi-chain platform, giving users the flexibility to trade and deposit assets from any blockchain using their preferred wallet. This allows market participants from all corners of the crypto-sphere including growing and/or established ecosystems such as Ethereum, BSC, Polygon, Avalanche, Solana and more to use C3 as their main trading venue.

To provide this seamless experience, C3 consolidates asset balances from all the supported blockchains in a single layer. The on-chain component of C3 serves as this unified settlement layer, built on the Algorand blockchain. This provides the system with a unified view of all assets in order to efficiently manage balances and settle trades with full transparency. To consolidate balances, C3 leverages Wormhole’s cross-chain interoperability protocol to process deposits and withdrawals to and from C3’s on-chain component.  

Wormhole:
Wormhole is a system that allows for the exchange of messages between different blockchain networks in a secure and verifiable way. It uses a network of 19 guardians to verify the integrity of the messages submitted to the system. Once a message has received enough observations, it is wrapped in a structure called a Verifiable Action Approval (VAA), which includes signatures and the message payload. This VAA can be used as proof that the message can be consumed by the target contract in the destination chain. Additionally, extra data can be encoded in the VAAs to trigger custom actions in the destination.  C3 leverages Wormhole’s Portal Bridge to lock assets in the smart contract of the blockchain of origin and mint wrapped assets which are automatically deposited into C3’s Cross-collateral Clearing Engine smart contract in Algorand. When a user deposits funds from its wallet to C3, the flow involves the user wallet sending a deposit transaction to Portal, the Wormhole contract in the foreign chain creating a VAA message describing the transfer request, the P2P Guardian Network verifying the request, a relayer inserting the request, and the Wormhole Token Bridge in Algorand issuing wrapped tokens and transferring them directly to C3’s smart contract on behalf of the user’s wallet.

Once funds are deposited into C3’s smart contract, they are under the sole control of the user’s wallet. The smart-contract uses the information provided in the VAA to allocate the funds to the public address of the user. As mentioned previously, each operation must be signed by the user for it to be accepted by the smart contract which verifies that the signature matches the owner of the assets and, given C3’s multi-chain nature, these signatures can come from wallets of any supported blockchain. To support this versatility, the on-chain component of C3 leverages Algorand’s cryptographic primitives to support multiple signing algorithms such as ECDSA and EdDSA, thus covering the cryptography used by most blockchains and cryptocurrencies. This ensures that the C3 on-chain component can verify signatures from virtually any wallet and network, allowing users to access and use C3 from any blockchain and custody solution of their choice.

Algorand: Settlement Layer

C3 uses the Algorand blockchain for its on-chain component and trade settlement. Algorand’s transaction cost is low enough to allow C3 to fully subsidize all on-chain transaction fees. Algorand's high throughput is also capable of processing all trade settlements from matched trades, even at peak volume. Furthermore, Algorand supports cryptographic primitives necessary to verify signatures covering the cryptography of most blockchains without requiring the development of independent smart contracts, reducing C3’s complexity. Algorand's atomicity is also essential for C3, as complex trade settlements require multiple operations to happen atomically. For example, a leveraged trade involves borrowing funds from the lending pool, transferring those funds to the seller, and delivering the sold assets all at once, which is made possible by the concatenation of multiple operations into a single group that all settle atomically on-chain.

The innovative architecture of C3 results in a highly-performant, accessible, and trustless trading platform that truly leverages the fundamental innovations of crypto. By combining the benefits of both off-chain and on-chain components, C3 is able to be as feature-rich as traditional exchanges while also being composable, allowing a range of use cases to be built on top of it. With its hybrid architecture, multi-layered security, and seamless trading experience C3 is paving the way for a new generation of self-custodial exchanges, making it easier than ever for market participants to trade cryptocurrency confidently.