Cartesi PoS and Noether Network
What is PoS?
Unlike PoW, which requires a lot of computing resources, PoS relies on the staking of nodes to generate blocks. The probability of a node generating a block is related to the proportion of ownership rights to the total staked of the entire network. The implementation process is usually that the network randomly selects a proposer, and other validators verify and accept the node’s proposal. At this time, the network reaches a consensus and the proposer produces a block. Generally speaking, the probability of a validator producing a block and the income obtained are related to the amount of stake in the network. Users can also entrust their rights to the validator node to obtain a certain income.
What is Noether’s delegation?
Cartesi network is a PoS network. Before Noether goes online, users need to run a node by themselves in order to participate in the network consensus. The probability of node block generation and the income obtained are related to the staking proportion in the network. The lower the stake the amount will lead to a decrease in the frequency of nodes producing blocks. Therefore, there will be some barriers for users to participate in the Cartesi PoS network. At this time, the Noether network provides users with a good choice. Noether is a side chain that provides availability for data, while Cartesi machine is a virtual machine running off-chain, making full use of off-chain computing power to obtain large throughput and cheap storage fees, both of which together provide high-performance layer2 service. Noether delegation is a pledge delegation service launched by the Cartesi team that allows users to participate in the Cartesi PoS network in the early stage. The node runner creates a pool to accept user delegation. In other protocols, users delegate their stakes to nodes to get rewards and unstake, which lasts for 7–28 days. In the Cartesi PoS network, the time for users to delegate or undelegate their stakes is 6 hours, and the income obtained by the user’s delegation is real-time. Compared to other PoS networks, there is no need to wait for a long time.
How is Cartesi pool running?
Cartesi pools are created by a factory contract deployed by Cartesi on the Ethereum network. When the pool creator creates the pool on the browser, a PoS contract controlled by multiple smart contracts and commissioned by users is generated on the Ethereum mainnet. The components that randomly select block participants based on PoS are defined in the contract, including five main contracts, including BlockSelector.sol, PoS.sol, RewardManager.sol, Staking.sol, and StakingImpl.sol. Among them, BlockSelector defines the process of block generation; PoS defines the consensus process of the entire Noether network, and manages the interaction between Staking, BlockSelector and RewardManager; RewardManager defines how to distribute block rewards to block producers selected by BlockSelector; Staking and StakingImpl define the interactive process of users staking their own rights and interests. Next, we analyze the details of each contract implementation in detail.
The most important logic in the BlockSelector contract is produceBlock(), which checks whether the user address is eligible to generate blocks. If a new block is to be produced, the target difficulty update must be completed; at the same time, an index is maintained in the network. When a block is generated, the system will update the current difficulty and update the index value. canProduceBlock will judge the current difficulty, user address and stake weight to confirm whether the user is eligible to produce blocks. If the check is passed, the private function _blockProduced(_index) will be called to generate blocks. Otherwise, the user is not eligible to produce blocks.
RewardManager defines two methods, reward() defines the reward distribution, getCurrentReward() calculates the current reward that needs to be distributed, and the operator is the PoS contract address instead of EOA.
There are two main methods defined in StakingImpl, one is stake and the other is unstake. The Stake method defines two variables, maturing and releasing, which represent deposits waiting to be staked and equity waiting to be unstaked. After waiting for the staked stake to mature, the staked variable will increase the stake that has met the maturity conditions. When canceling the pledge, because Cartesi allows users to access their rights at any time in the PoS network design, when the number of tokens in the mature period is greater than the number of tokens to be canceled, it will be subtracted from maturing first, and when the number of maturing tokens is less than the amount to be canceled when the number of tokens is staked, it will be subtracted from staked at this time.
The PoS contract is the most important contract in Noether. The contract instantiates Staking, BlockSelector, and RewardManager, and controls RewardManager to decide to whom to send rewards through BlockSelector. The worker will confirm whether it is authorized by msg.sender. If authorized, the worker will call produceBlock() to produce the block when the block production conditions are met, and call the pos.rewardManager.reward(user, currentReward) method according to the rewardManager to distributed the block reward. The relationship between the PoS contract and other contracts is shown in the figure below.
Compared with PoW, PoS will no longer require a lot of computing resources. The Cartesi Noether network supports users to stake and unstake, and users only need to wait for a short maturity period instead of waiting for days. The Noether network combined with the Cartesi Machine improves the throughput and storage space of the Layer 2 network, and has high scalability. This article analyzes the contract details of the Cartesi PoS network, PoS contract is the most core contract in the Cartesi network. It includes the details of how blocks are produced, how rewards are distributed, and the details of user stake and unstake at the code level. The Cartesi PoS network updates the difficulty value of the network in real time and produces blocks according to the stake of the pool, and distributes rewards to users in the pool.