bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 2쪽 중 1쪽
Phala Network: A Secure Decentralized Cloud
Computing Network Based on Polkadot
Hang Yin Shunfan Zhou Jun Jiang
March 7, 2022
1 Introduction
Nowadays the security of the permissionless blockchain is typically guaranteed
by state replication over consensus algorithms. Though this approach works
well for blockchain, it also means that everything on the blockchain is public,
which brings a problem: confidential information cannot be handled by the
blockchain. The lack of confidentiality greatly limits the usage of blockchain in
processing sensitive business and user data. For example, stock traders usually
do not want to reveal their positions or order history. What’s more, all of the
privacy-related DApps on the Ethereum cannot comply with the General Data
Protection Regulation and thus will be prevented in European Union.
Several methodologies have been proposed to address the privacy problem.
Monero and Zcash implemented private transaction by ring signature [13] and
zk-SNARK [11] technology, but their methods can only provide privacy for cryp-
tocurrencies and are hard to be extended to general-purpose smart contracts.
MPC (Multi-Party Computing) can theoretically run arbitrary programs with-
out revealing intermediate states to the participants, with the expense of a per-
formance overhead of 10 6 times [9], which makes it impractical for real world
use cases.
A new approach is to utilize special hardware, i.e., Trusted Execution En-
vironment (TEE) [8]. TEE is a special area in some processors that provides a
higher level of security including isolated execution, code integration, and state
confidentiality. Naive TEE as a computing platform has several shortages, such
as the lack of a reliable time source and availability guarantee.
Ekiden [9] fixed these problems by introducing a TEE-blockchain hybrid
architecture and implemented a high performance confidential smart contract
platform. However, contracts in Ekiden are isolated, which means the contracts
cannot interoperate with each other, let alone external blockchains. Interoper-
ability is a keystone of modern smart contracts. For example, 8 of the top 10
contracts in Ethereum, the largest smart contract platform in the world, rely
on functions invocations or money transferring to at least one other contract.
Without interoperability, contracts cannot read information or call functions
from other smart contracts. What’s more, the use of self-defined tokens, one
1
SGX Enclave
Code
Users
RA Quote
RA Quote
signed by Intel
TLS
Figure 1: Intel SGX remote attestation procedure.
of the most common cases in smart contract usages, is unachievable if all the
contracts cannot access the token contract.
In this paper, we present Phala Network, a novel cross-chain interoperable
confidential smart contract network as a Polkadot parachain [10]. We intro-
duce an Event Sourcing / Command Query Responsibility Segregation[4, 3]
architecture into a TEE-blockchain hybrid system to achieve cross-contract and
cross-chain interoperability for confidential smart contracts. We further de-
signed a Libra-Polkadot bridge to implement a privacy-preserving Libra Coin
by confidential contract.
2 Background
2.1 Intel SGX: A TEE Implementation
Intel SGX [6] is a popular implementation of TEE. It runs code inside a special
“Enclave” so that the execution of the code is deterministic, i.e., not affected
by other processes or underlying operating system, and the intermediate states
is not leaked. In a properly set up system, Intel SGX can defend the attacks
from the OS layer and hardware layer.
To ensure the execution is finished as expected inside an enclave, a proof
can be generated according to a protocol called Remote Attestation . The
hardware can generate an attestation quote based on the details of hardware,
firmware, the code being executed inside the enclave, and other user-defined
data produced by the code. The quote is signed by the trusted hardware with
credentials embedded during the production process.
Next, the generated attestation quote is sent to the Intel Remote Attestation
Service. Intel will sign the quote iff the signing credentials are valid. As each
credential is uniquely bound to an Intel CPU unit, fake attestation quotes will
2
never pass the Remote Attestation Service check.
Finally, the attestation quote signed by Intel serves as the proof of a success-
ful execution. It proves that specific code has been run inside an SGX enclave
and produces certain output, which implies the confidentiality and the correct-
ness of the execution. The proof can be published and validated by anyone with
generic hardware.
Intel SGX and the Remote Attestation protocol is the foundation of confiden-
tial contract. Except for Intel SGX, there are also alternative implementation
choices like AMD SEV [1] and ARM TrustZone [2].
2.2 Event Sourcing and CQRS
Event Sourcing is a software design pattern. Instead of storing the latest state of
the data, the events causing state transition are recorded in an append-only log.
The events are timestamped and can be replayed to reconstruct the state of any
time. Since the events are timestamped, the state of the system is deterministic.
Command Query Responsibility Segregation (CQRS) is a design pattern by
which the read operations and write operations are handled separately. In a
CQRS and Event Sourcing combined system, the write operations are recorded
as the events and the read operations can be served by the current view of the
state. This pattern make a system easy to scale up and avoid conflicts.
For native CPU performance and better security, each confidential contract
is bound to only a single or a small set of TEEs as the executor. By this design,
the contract state is isolated from each other without consistency guarantee. It
becomes a trouble for cross-contract and even cross-chain interoperability.
While it’s hard to keep a strong consistency over the states, contracts can
still communicate by passing messages to each other on the premise that state
transition is still deterministic. In an Event Sourcing / CQRS design, the com-
mands can be initiated from users or contracts and are timestamped on the
blockchain strictly. It guarantees the global state is deterministic and therefore
enables message passing between contracts. Message passing is a primitive to
implement higher level interoperability like contract invocation and token trans-
ferring. The read-only operations are not timestamped for better performance.
3 Confidential Contract
Phala Network aims to build a platform for general-purpose privacy-preserving
Turing-Complete smart contracts. The basic requirements for such a platform
could be as follows.
• Confidentiality .Unlike the existing blockchains for smart contracts, Phala
Network avoids the leakage of any input, output, or intermediate state of con-
fidential contract. Only authorized queries to the contract will be answered.
• Code Integrity .Anyone can verify that an output is produced by a specific
smart contract published on the blockchain.
3
• State Consistency . Anyone can verify that an execution happened at a
certain blockchain height, which implies the output of the execution is subject
to a certain chain state.
• Availability .There must not be a single point of failure such as disconnec-
tion of the miner.
• Interoperability .Contracts can interoperate with each other and external
blockchains.
The existing TEE solutions, e.g., Intel SGX, can only prevent the leakage
of sensitive information during the execution of isolated programs, and provide
no guarantee on availability or verification of input data. Thus it requires a
carefully-designed infrastructure to integrate TEE into blockchain to meet the
requirements above.
We are going to introduce the design of Phala Network and how it fulfills
the above requirements in the following sections.
3.1 Abstraction of Confidential Contract
A typical smart contract can be regarded as a state machine of a current state
sn and a state transition function f , which takes input event en and last state
sn−1 to produce the latest state sn:
sn = f (sn−1, en)
Since the state transition process happens inside the enclave, any of its
intermediate states remains invisible to outside. We can further encrypt the
reached state and input event to prevent the attackers from inferring the internal
state of contract with event replay.
Let csn be the cipher of sn and cen be the cipher of en, the state transition
function of a confidential contract p can be represented as:
csn = p(csn−1, cen) (1)
p(csn−1, cen) = Enc
f
Dec(csn−1), Dec(cen)
(2)
where Enc and Dec can be carefully-chosen symmetric encryption and de-
cryption functions subject to the contract.
Unlike the existing smart contract, a confidential contract doesn’t expose
any information outside the enclave by default. To answer authorized queries,
we introduce a query function q which takes the current encrypted state csn,
query parameters paras and user’s identity I (usually a pubkey) as input and
returns the response r:
r = q(csn, paras, I)
The confidential contract must first validate the identity of the user and
then respond to her query. Apart from the queries from users, the contract may
4
Phala
Network
Blockchain
Polkadot
Gatekeepers
Miners
Figure 2: Roles in the protocol.
also accept a special query producing side effects. The side effects include the
egressing data that can be posted back to the blockchain by miners.
4 The Protocol
There are a few roles involved in the protocol as shown in Figure 2.
• Users. Users invoke, query and deploy smart contracts. Users interact with
smart contracts via Blockchain and W orker Nodes. They can verify the
blockchain as well as the cryptographic evidence on the blockchain indepen-
dently by running a light client or full node. No special hardware, i.e., TEE,
is needed for users to use the confidential contracts.
• W orker Nodes.Worker Nodes run confidential contracts in TEE-compatible
hardwares. Worker Nodes are off-chain. In each node, a special program
called pRuntime is deployed to the enclave. The runtime has a builtin VM to
run contracts. It also cooperates with the blockchain to support the contracts
in full life cycle. Worker Nodes can be further divided into three roles:
• Genesis Node. Genesis Node helps bootstrap the network and set up
the cryptographic configuration. There’s only one Genesis Node and it’s
destroyed after the launch of Phala Network.
• Gatekeepers. Gatekeepers manage the secrets to ensure the availability
and security of the network. Gatekeepers are dynamically elected on the
blockchain and they stake a large amount of Phala token. They are re-
warded for being online and slashed in case of misbehavior because there
5
must be a certain number of functional Gatekeepers running at any time.
• Miners. Miners execute the confidential contracts. They get paid by
providing their computing resources to the users. Unlike Gatekeepers,
Miners only need to stake a small amount of the Phala token and can
join and exit the network as they want.
• Remote Attestation Service. Remote Attestation Service is a public ser-
vice to validate if a Worker Node has deployed pRuntime correctly. The
cryptographic evidence produced by the service can prove a certain output is
produced by pRuntime running inside a TEE. IAS [5] is Intel SGX’s remote
attestation service implementation.
• Blockchain. Blockchain is the backbone of Phala Network. It stores the
identities of the Worker Nodes, the published confidential contracts, the en-
crypted contract state, and the invocation transactions from users and other
blockchains. When plugged into a Polkadot parachain slot, it’s capable to
interoperate with other blockchains through the Polkadot relay chain.
4.1 System Design
We first propose an important property which works as the basis of the following
system design.
All worker nodes are non-Byzantine nodes. As illustrated above, each
worker node runs a special program pRuntime in its TEE. The pRuntime, as
the name suggests, works as the runtime environment for confidential contracts.
It exports a set of APIs for contracts to access the state resources, manages
the connections to the blockchain and answers user queries securely. pRuntime
implements the Phala Network protocol described in this paper. Since the
integrity of pRuntime is guaranteed by the remote attestation service, this iso-
lation promises that no Byzantine fault can happen unless both the TEE and
pRuntime are compromised, and an adversarial worker node can only launch a
Denial-of-Service attack, which can be further detected by our responsiveness
monitoring protocol.
In our system, the executors, i.e., miners, are stateless, which means the
latest state of a confidential contract has to be got by sequentially executing all
the input events on the blockchain or from a cached contract state and the events
after that. All the inputs have to be first published to the blockchain and in
this way, the blockchain works as the canonical source of contract inputs, which
implies Event Sourcing design pattern. We further utilized the idea of CQRS
in the design of the protocol to accelerate the users’ queries to the contracts.
pRuntime maintains a set of secrets durning its life cycle. Contract states
are encrypted and checkpointed on the blockchain with a symmetric key. Each
pRuntime registers its identity on the blockchain and establishes secure connec-
tions to users with an asymmetric key pair. Since each pRuntime registers itself
on the blockchain, any user can validate its identity. These secrets never go
outside the pRuntime.
6
Blockchain
Contract
Code
Deploy
Registry
Encrypted
State
pRuntime
Contract
Users TLS
pRuntime Identity
RA Quotes
Intel Root Cert
Hardware
Firmware
Code
Custom data: commit to
the Enclave Identity
Signed
RA Quote
Figure 3: RA and communication.
4.2 Node Registration
All the Worker Nodes are required to be registered on the blockchain before
participating in mining or Gatekeeper election.
Remote attestation provides a building block to verify the execution as well
as its output of a certain code inside the enclave. However, running such attes-
tation on each execution is time inefficient. In Phala Network we adopt a better
protocol. The attestation measures the pRuntime instance and the generated
unique identity during the registration, instead of each execution. In this way,
a single attestation is sufficient to ensure the future behavior of the pRuntime.
1. The host program of the worker node n (i.e. Miner or Gatekeeper) calls
pRuntime.GetIdentity to generate a key pair as an identityIn(pkn, skn).
skn is kept inside the enclave and pkn is revealed to the host.
2. The host calls pRuntime.GetRAQuote to generate a remote attestation
quote q with the commitment to pkn and other necessary metadata.
3. The host submits q to Remote Attestation Service and get the signed
quotes qsigned.
4. The host submits ( qsigned, pkn) to the blockchain. The blockchain then
accepts and stores the information after validation.
The registered pRuntime instances are non-Byzantine. The pRuntime in-
stance and the generated identity is measured by the attestation. It implies
pRuntime runs in a TEE and the identity is generated securely. Since the
privkey is unknown to any party expect the instance, nobody can pretend to be
a registered pRuntime.
With the identity registered, a TLS-like channel between the requester and
the target pRuntime can be established. The identities published on the blockchain
serve as the PKI to avoid MitM attack. As the pRuntime is non-Byzantine in
7
such a communication channel, the pRuntime can be trusted without further
need of remote attestation. This trick improves the efficiency and flexibility of
code execution in the runtime.
The metadata contains other necessary information, for example, the net-
work endpoint of the node like libp2p multiaddrs. The registration has an ex-
piration date to prevent vulnerabilities discovered in the future. Worker nodes
can renew it by redo the registration process including generating a new identity
and do the remote attestation.
4.3 State Encryption
Confidential contract runs on pRuntime and the states are persisted on the
blockchain to ensure the availability. As the information on the blockchain are
public, the saved states have to be encrypted. In Phala Network, each contract
(ci) is associated with a symmetric key called Contract Key (kci ).
Contract keys are generated by Gatekeepers inside pRuntime. To run a
contract, a registered miner should get the corresponding contract key from
Gatekeepers. The miner reads the latest contract states and decrypt it with
the contract key during initialization. Then the updated states are encrypted
and saved to the blockchain in the future. Gatekeepers hold the contract keys
as a part of their states. Gatekeepers share a symmetric key called Root Key
(kr). The Gatekeeper states are also encrypted and saved to the blockchain like
miners. All the keys are used by and kept in pRuntime.
The details of key management are discussed in below subsections. We fur-
ther propose a few improvements including key rotation (in “Key Rotation”
subsection) and a distributed key generation (DKG) scheme in “Open Ques-
tions” section.
4.4 Blockchain Launch
In the blockchain launch phase, the blockchain will load the initial distribution
of the native token and start the election of Gatekeepers. A Genesis Node assists
the launch of the blockchain.
1. Before the genesis block, the Genesis Node runs pRuntime.Bootstrap to
generate a key pair as the identity of the node, and a symmetric key,
namely Genesis Identity Ig(pkg, skg) and the genesis Root Key k(0)r . The
runtime reveals pkg but keeps skg and k(0)r privately.
2. Start the blockchain with pkg. In this stage pkg is published in the genesis
block and is used for other worker nodes to establish secure channels to
the Genesis Node. k(0)r is kept inside the Genesis Node and is used to
store secrets necessary to run the network on the blockchain. The initial
native token distribution is loaded in the genesis block.
8
3. The blockchain is at pre-launch phase after the genesis block. Governance
module is enabled but other modules including confidential contract are
still disabled until the Gatekeepers are elected.
4. Worker Nodes who want to participate in Gatekeeper election can fol-
low the Node Registration scheme to register their identities on the
blockchain. Then ngatekeepers (a chain parameter between tens to hun-
dreds) Gatekeepers will be elected during the pre-launch phase. This can
be done on-chain via an Polkadot-style NPoS validator election (see Ap-
pendix II for details).
5. When the election is finished, the Gatekeepers send a request to the Gen-
esis Node for k(0)r through a TLS connection. The Genesis Node only
answers the requests from the selected Gatekeeper. Gatekeepers confirms
their readiness the on the blockchain.
6. The Genesis Node retires and self destroys when it sees the confirmations
of the Gatekeepers from the blockchain. In case there are unresponsive
Gatekeepers, the election will expire and restart after the deadline.
So far Gatekeepers have their identity registered on the blockchain and k(0)r
has been distributed to all the Gatekeepers’ runtime. Then k(0)r will be used to
deploy nodes and contracts in the future.
Periodical key rotation is necessary for forward secrecy. The root key at era
n is denoted by k(n)r . We will discuss the details in “Key Rotation” subsection.
4.5 Deploy Worker Nodes
Both miners and Gatekeepers have to follow the “Node Registration” scheme
to join the network. The protocol ensures the nodes are non-Byzantine. So
we only consider responsiveness failures. To ensure the service quality, all the
worker nodes must stake a certain amount of the Phala token and could be
slashed once it fails to meet the responsive requirements. We will discu프로젝트로 돌아가기