Charli3

Author: Emir Olgun

Date: 10 October 2023

Introduction

Oracles are essential for blockchains. Blockchains can not interact with the outside world and only way to connect the blockchain and the outside world is through oracles. Blockchain projects can have actual impacts on the real world and can also bring real world assets to the blockchain.

Cardano for a long time, lacked an oracle service. Chainlink and Charli3 announced they were working on oracle projects on Cardano in recent years. Charli3 finally launched its oracle on Cardano mainnet this year. We will take a deep dive into Charli3 oracle in this document.

Features

Charli3 currently offers an input oracle, which fetches off-chain data to on-chain smart contracts. Currently Charli3 offers an oracle that fetches ADA to USD exchange rate information to the Cardano mainnet. [Image1] This transaction is an Update Node transaction and it was done by one of the nodes recently with a Node NFT and a datum attached to the UTxO with information of ADA to USD exchange rate. [Image2] This is the datum of the Node UTxO with information of the exchange rate. [Image3] Here we can see the aggregate transaction that calculates the exhcange rate. This transaction updates the datum of Feed and Aggregate NFTs. [Image4] This is the datum of aggregate UTxO. It has the Public Key Hashes(PKH) of the wallets that can feed node UTxO to the contract. and the rewards for these wallets.

How It Works

In order to understand how Charli3 Oracles work, we need to have a basic understanding of Cardano's Smart Contracts and Extended UTxO model.

Cardano Smart Contracts

A smart contract is, in the most basic terms, an executable program running on the blockchain. This program is a contract that checks for certain conditions, which are pre-determined, to execute a transaction. The importance of smart contracts is they provide trust between opposite parties of the transaction as the conditions of the contract can be seen by anyone and these conditions are not alterable. If the conditions of the smart contract cannot be met, the funds locked in the smart contract can never be accessed by anyone, it is absolutely impossible. Cardano smart contracts can access some information about transactions, which are:

  • Datum: Piece of data attached to the UTxO

  • Redeemer: Piece of data attached to the input.

  • Context: Piece of data representing information about the spending transaction.

Extended UTxO Model

UTxO Model

Cardano is using Unspent Transaction Model for its ledger on contrary to blockchains like Ethereum which they are Account-Based blockchains. In Cardano, each transaction has inputs and outputs. The transaction input is the unspent output of a previous transaction. Assets are stored on the ledger in unspent outputs, rather than in accounts.

A transaction output is made up of an address and a value. The address is the key to spend this unspent transaction output and the value is the amount of ADA in this output. So when you look inside your Cardano wallet, you are seeing different UTxOs that has your address inside them.

A transaction input is the output of a previous transaction. Transaction inputs are made up of a pointer and a cryptographic signature which acts as the unlocking key. The pointer inside the input points back to a previous transaction output, and the key unlocks this output. When that outpu is unlocked, it is marked as spent by the blockchain and new unspent outputs are created. Now we can learn the EUTxO or Extended UTxO model.

EUTxO Model

Extended UTxO model adds a bunch of different features to the UTxO Model. One important feature is addresses in the EUTxO model can contain arbitrary logic in the form of scripts. The transaction looks up the script provided by the output address and executes the script if the transaction is allowed to use the output as an input. Another fetaure of the EUTxO model is the outputs can also include an arbitrary data in addition to a value and an address so they can carry state information.

How Charli3 Works

On the basic level, an oracle contract works with five different UTxOs. These UTxOs are:

  • Node UTxO: UTxO with datum that includes information about the wallet that can consume it and off-chain data. This UTxO also has a Node NFT to be identified by the contract accordingly.

  • Aggregate UTxO: UTxO with datum that includes information about contract settings, defining how information from the Node UTxOs is processed. This UTxO also has a Aggregate's NFT and a specific amount of C3 tokens. These tokens are used to reward for Node UTxO owners who are consistent.

  • Reward UTxO: This UTxO has individual records for each node's earned rewards, a Reward NFT, and C3 tokens.

  • Feed UTxO: This UTxO stores processed data generated by the Node UTxOs and a Feed NFT.

  • Reference Script UTxO: This UTxO stores contract's scripts on blockchain in order to increase efficiency.

Consensus Algorithm

Charli3 oracles can be fed by a single node or multiple nodes. When the oracle contract executes the Aggregate transaction(transaction that takes in all oracle UTxOs and calculate new Feed UTxO's datum), the contract reads all Node UTxOs and their information is calculated into the final feed by taking the median value of the Node UTxO datums and fed into the Feed UTxO through the consensus algorithm. Nodes whose input datums do not exceed the Mean Absolute Deviation and Standard Deviation values of the contract are rewarded.

Writers Opinion on the Oracle Contract

Charli3 oracle is designed to only accept inputs from pre determined wallets. This is done by specific NFTs with the wallet information and the oracle settings. The security mechanism for the feeders have three checkpoints which are:

  • Node NFT with wallet information.

  • Oracle settings with authorized walelts.

  • Possession of the Node NFT.

With these multiple barriers, input from a non-authorized wallet is impossible. Charli3 oracle rewards the nodes that feed accurate data consistently and discards the data fed by corrupted nodes. A concern comes to mind is if the majority of nodes feed corrupted data, the consensus algorithm will probably process this corrupt data data just like a %51 attack on a blockchain. Blockchains avoid this issue with their almost infinite number of nodes. An oracle with a large number of nodes can be almost as safe as the blockchain but that creates another issue, running cost. When we checked the oracle transactions on a blockchain explorer, we found that the update node transaction cost is 0.21 ADA for each node operator. As these node operators are compensated for these expenses, these costs increase the running cost of the oracle. An oracle with 1000 nodes and if these nodes update information every 30 minutes, just the update Node transaction cost is around 2500 USD per day. Here is the basic equation that shows the relationship between number of nodes, the oracle settings and the cost:

$kNS=C$

k: constant N: number of nodes S: oracle settings, mainly the update frequency for the nodes.

Conclusion

Charli3 currently offers a very limited oracle service.

Resources

  • Charli3 Oracle Operation

  • https://docs.charli3.io/charli3s-documentation/oracles-operation

  • https://docs.charli3.io/charli3s-documentation/infrastructure

  • https://docs.charli3.io/charli3s-documentation/live-c3-networks

Last updated