Reading | Phala TEE Mining Staking Design

Phala Network
Phala Network

--

1. Introduction

To secure the cloud of Workers and the jobs they are assigned, the network will set Confidence Levels for each worker’s CPU and will require Staking to enable mining. Each worker can only earn value V if it first Stakes a number of PHA tokens based on its CPU score, after which it can enter the mining system and start TEE Mining.

If a worker misbehaves or fails to respond, it will be punished by slashing the V, which strongly incentivizes participants to ensure their workers are running properly and disincentivized attempts to cheat.

2. TEE Mining Roles

3. Role Relationships

4. The Relationship from Worker to StakePool

Chart 1: Worker-StakePool

As shown on Chart 1:

  • When a Worker (such as a, b, or c) is created, the Worker needs to authorize a particular Operator address (such as A) to manage the computing node.
  • An Owner (such as A) can create one or more StakePools (such as Pool 1).
  • Because A is both the Owner of Pool 1 and the Operator of Workers {a,b,c}, Workers {a,b} can be bound to Pool 1. The PHA in Pool 1 can then be allocated to Workers (a,b) as their Stake to enable mining. Similarly, A can bind worker c to Pool 2 and use Stake in Pool 2 to enable c’s mining.
  • Similarly, B is the Owner of Pool 3, so the Workers {d,e} which are managed by B can be bound to Pool 3.

Impossible relationships:

Worker c authorized A as Operator, so it cannot also authorize B at the same time. If Worker c wants to transfer control to B, it must first stop mining for A;

Pool 2 has been created by and is bound to A, therefore B cannot have a relationship with Pool 2. Owner B can create and manage Pool 3 by itself.

5. Assignment of Stake from Pools to Workers

Chart 2–1: Staker-Worker

As shown in Chart 2–1, let’s assume that Owner A manages Pool 1, and Pool 1 has bound Workers {a,b,c}; Owner B manages Pool 3, and Pool 3 has bound Workers {d.e}, and:

  • A sets a 50% commission rate for Pool 1, and personally Stakes 20k PHA to Pool 1
  • B sets Pool 3 with a commission rate of 40% , and personally Stakes 10k PHA to Pool 3

Assume that the minimum stake amounts (from CPU scoring) for workers a, b, c, d, e are: 10k, 12.3k, 10k, 5k and 5k. We can see that Pool 1 does not have enough to Stake all the Workers that are bound, but Pool 3 has enough to Stake their Workers.

Then their best strategies are:

  • Pool 1 stakes 12.3k to b and sets b to start working
  • Pool 3 stakes 5k to each of d and e, and sets both d and e to start work

We know that some people have the capacity to provide Worker CPUs, but do not have funds to Stake them, while other people have ample funds to Stake but don’t have the capacity to run Workers. In order to ensure as many suitable Workers are adequately Staked and mining as possible, we created the StakePool protocol to allow third-party Stakers to add PHA to Pools which can be assigned to stake various Workers.

Suppose Staker and Staker stake 0.3k and 13k respectively to Pool 1, and Staker and Staker stake 0.5k and 20k respectively to Pool 3:

Chart 2–2: Staker-Worker

As shown in Chart 2–2, we can see that both Pool 1 and Pool 3 can now meet minimum stake requirements for all workers that are bound, and they can even over-stake the workers at this time. (Over-staking increases mining rewards, but each additional PHA brings fewer additional returns. It is more profitable to spread stake over many workers than to use it to overstake a smaller number of workers.)

At this time, the PHA in the StakePools will be divided into two states: Deposited (staking) and Free (not staking)

In actual operation, each Pool Owner can set a maximum stake amount for the Pool to prevent the pool’s stake share from being maliciously diluted:

  • When the total PHA in the pool is below the maximum stake amount, any Staker can join by contributing PHA
  • When the total PHA amount has reached the maximum stake amount, additional PHA will not be accepted

6. Reward Settlement Flow

When TEE mining rewards are generated, the mining module will generate statistics and perform settlements based on the current network Workers and distribute the rewards for each Worker to their corresponding StakePool. The PHA rewards credited to the StakePool will be automatically divided into two parts based on the commission rate of the pool. The commission portion is deposited into the pool’s Owner address, and the remainder is deposited into the Staker’s addresses. The Staker’s shares of the reward are apportioned based on their relative share of the Pool’s total stake.

In the example below, we assume that at block 42 the Khala network produced 64 PHA rewards for Workers. Assume our five Workers {a,b,c,d,e} are the entire network, are all online and working to receive their share, and that their accumulated V values are proportional to their staked amounts as listed above. The TEE Mining module will calculate the rewards due per Worker {a,b,c,d,e}, recording them into Pool 1 and Pool 3 as Pool Reward, will settle commission amounts due to the Owners for running the workers and the pool, and will apportion the remaining amount as Pool Revenue to all Stakers in the Pool based on their share of the Pool’s Stake, as follows.

Chart 3: Reward-Pool

The settlement formula for the Owner and StakePool portions is:

  • Owner Commission = Pool Reward * commission rate
  • Pool Revenue = Pool Reward * (1-commission rate)

The Pool Revenue is allocated to each Staker based on their individual Pool Share (their share of the total pool):

  • Pool Share = Staker’s stake / Pool total stake

An individual Staker’s revenue allotment can be calculated as:

  • Staker’s Reward = Pool Revenue * Pool Share

Which is the same as:

  • Staker’s Reward = (Pool Reward * (1-commission rate)) * (Staker’s stake / Pool stake)

If the Owner themselves also stake, they will earn their share of the Pool Revenue as well as the Owner Commission.

The Pool total stake includes the sum of Deposited (Staked) and Free (Unstaked).

With Owners, Pools, and Workers as shown in Chart 3, and the 64 PHA from block 42 allocated per Worker as shown in the Chart, the result is 34 PHA to Pool 1 and 30 PHA to Pool 2.

The Owners receive their Commission portion for running the pools and Workers as follows:

The remaining Pool Reward is now Pool Revenue to be paid out to all Stakers based on Pool Share (again, if the Owners Staked, then they are also Stakers and get paid their share.) In our example, this plays out like this:

7. Pool Exit Stake Settlements

If the Owner wants to quit mining and withdraw all their own staked PHA, they first suspend mining. After the stop is initiated, the funds that were staking those Workers will undergo a 7-day freeze period in the StakePool, after which the balance will be unfrozen and will be returned. The Owner cannot withdraw other Stakers’ deposits.

Chart 4–1: Withdraw-1

As shown in Chart 4–1, when the Owner cancels mining, the StakePool immediately suspends computing for all Workers and associated stakes immediately enter a “Freeze period”. After 7 days, the PHA contributed by for Owner A, Staker , and Staker will be refunded in full.

Stakers can request withdrawal of their funds at any time, and if there are idle funds in the StakePool (Free), they will receive their withdrawal immediately. However, if Staker’s withdrawal amount is greater than the idle funds in StakePool (Free), Staker will immediately obtain the Free funds and the remainder of the withdrawal will need to wait:

Chart 4–2: Withdraw-2

As shown in Chart 4–2, Staker initially staked 20k in Pool 3..When they submit a withdrawal for 10k of their stake, Pool 3 immediately sent the 0.5k balance of the Free PHA to Staker . The remaining 9.5k of staked PHA will wait for the following:

  • A 3-day buffer period begins at the initial withdrawal. During this period, if new PHA are added to the StakePool as Free or if some Worker Mining is stopped (which will Free the funds staking that miner), then PHA will be unlocked immediately to the Staker who initiated the withdrawal. There may be multiple deposits or Worker stoppages until enough PHA is Free to meet the withdrawal.
  • If the withdrawal request is still not met after 3 days, all Workers in this Pool will be automatically stopped and enter a 7-day Freeze period which cannot be interrupted by anyone. After 7 days, the withdrawal transaction will be completed.
  • In other words, when a Staker initiates a withdrawal, they will receive their funds in no more than 10 days, but may receive some or all of their funds in 3 days or less, depending on Free funds.

Assume that more funds are contributed to the StakePool:

Chart 4–3,withdraw
  • As shown in Figure 4–3, after Staker stakes an additional 5k PHA to Pool 3, the Pool’s Free funds increased by 5k, and Staker immediately receives an additional 5k towards their withdrawal.
  • If, after waiting 3 days, the necessary 4.5k of funds are still not Free, the system is forced to terminate all the mining activities of Pool 3, and will automatically send the remaining 4.5k to Staker after the 7-day unfreeze period.

Summarizing:

  • When the actual StakePool Owner initiates the suspension of all mining or cancels all Staking to dissolve the pool, withdrawal of all Stakes will be triggered. There will be a 7-day unfreeze period after which all PHA in the StakePool will be refunded to the Stakers.
  • When a Staker initiates a withdrawal of their own Stake, the system will determine whether the Pool has Free funds, and if so, it automatically return them to the Staker;
  • If there is insufficient Free funds, the Owner of the Pool has 3 days to arrange for the PHA that Staker wants returned (from an existing or new Staker), or else to free funds by idling Worker(s) to Free their allotted stake. If the replenishment of funds can meet the withdrawal request, the remaining Workers will not be interrupted;
  • If Free funds are not sufficient to meet the withdrawal, the system will be forced to suspend all mining activities in this Pool in order to complete the withdrawal for the Staker (7 days after all Workers are stopped).

About Phala

Phala Network tackles the issue of trust in the computation cloud.

This blockchain is a trustless computation platform that enables massive cloud processing without sacrificing data confidentiality. Built around TEE-based privacy technology already embedded into modern processors, Phala Network’s distributed computing cloud is versatile and confidential. By separating the consensus mechanism from computation, Phala ensures processing power is highly scalable but not wasteful. Together, this creates the infrastructure for a powerful, secure, and scalable trustless computing cloud.

As a member parachain of the Polkadot cross-chain ecosystem, Phala will be able to provide computing power to other blockchain applications while protecting the data layer, enabling possibilities like privacy-protected DeFi trading positions and transaction history, co-computing DID confidential data, developing light-node cross-chain bridges, and more.

On-chain services currently being developed on Phala Network include Web3 Analytics: high-performance smart contracts from Phala to enable highly concurrent mass data analytics with privacy, paving the way for an alternative to Google Analytics that inherently respects individual confidentiality.

🍽 — Subscribe | Website | Twitter | Github
🥤 — Discord | Forum | Telegram |Italiano |Français | Persian

--

--