PHALA 백서

PHALA

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 2쪽 중 2쪽

ss the details about staking and monitoring in “Responsiveness Monitoring” section. As Gatekeepers store the root key and need to be always online, they have to meet a higher standard and need to stake a larger amount. They are rewarded for keeping online and could be slashed otherwise. 4.6 Deploy the Contract The bytecode of the compiled contract is published on the blockchain and then loaded by a user-specified miner to its pRuntime. The Gatekeepers generate a symmetric encryption key for each newly published contract. The key is shared with the corresponding pRuntime for state encryption. More specifically: 1. The developer publish the contract ci to the blockchain 9 2. Once Gatekeepers notice the publish of ci, they generate a corresponding contract key kci for contract states encryption. 3. Gatekeepers save kci to the blockchain as a part of the chainstate en- crypted with Root Key k(n)r 4. The developer finds an available miner to load the contract. The developer can either run his miner so that no extra fee is needed, or rent one from a resource market (see “Economic Design Paper” for more details). 5. The miner runtime connects to Gatekeeper through a secure connection and asks for kci by pRuntime.GetContractKey. The miner’s pRuntime will use kci to encrypt the contract state and save it to the blockchain periodically. We will discuss the details in “Execute the Contract” and “State Recover” section. 4.7 Key Rotation The Gatekeepers are re-elected in each era according to the election rule (Ap- pendix II). While rotating the Gatekeepers, the root key is also rotated. Let Gn−1 and Gn be the Gatekeepers set before and after the election at era n. The root key will be rotated as follows: 1. Gn is elected on-chain by the governance module in the last block of each era. Simultaneously two leaders ln−1 ∈ Gn−1 and ln ∈ Gn are randomly chosen. The randomness comes from the random beacon in the block. 2. Any communication between miners and Gatekeepers is blocked until the key rotation is done. 3. Once the block is finalized, ln−1 and ln collaboratively generate the next root key k(n)r by a DH-like key exchange protocol with salts. ln−1 de- crypts the Gatekeeper states and re-encrypt with k(n)r and save it to the blockchain. ln broadcasts k(n)r to other members in Gn by a secure commu- nication channel. Gn members will confirm the readiness on-chain when they received k(n)r . 4. Once all the Gn members have confirmed and ln−1 has updated the Gate- keeper states, the blockchain will generate a “Key Rotation Ready” event so that miners can resume the communication with the new Gatekeepers. Simultaneously the Gn−1 members who are not still in Gn will notice the event and perform self destruction. 5. There’s an expiration time for the key rotation procedure in case of the un- responsiveness. In such case, the unresponsive Gatekeepers will be slashed and the procedure should start over. 10 Phala Network Enclave Runtime Users Polkadot Relay Chain Ingressive Events Chainview Side-Effect Egressing Eventsɠ ɡ ɢ ɣ Figure 4: Execute the contract. All the off-chain key management and encryption is handled by thepRuntime of the Gatekeepers. The key rotation protocol starts from the first block in an era and ends after the final on-chain confirmation. Durning this period no new contract can be deployed to the miners because the communication between miners and Gatekeepers is blocked. However the delay caused by the protocol is trivial compared with the length of an era. In the best case, the delay is 2 round-trip- time (two on-chain confirmations). Contract keys can be rotated in a simpler way. The miner generates a new contract key and re-encrypt the states with the new key. Then it can send the new contract key to Gatekeepers in a secure channel, and save the states to the blockchain. The two actions are combined in a single transaction to make then atomic. Root key and contract key rotation ensures the forward secrecy of the confi- dential state (for both Gatekeeper state and contracts state). The keys for the obsolete data are destroyed once the rotation is done. 4.8 Execute the Contract We adopt an Event Sourcing / CQRS style architecture for the contract execu- tion. Read queries and write commands are segregated. The contract state is determined by the write commands which have multiple sources: user invocations, blockchain events, and ingressive messages from the relay chain. In a naive design, we ask all the write commands to be recorded ex- plicitly on the blockchain. The commands are denoted byIngressive Eventsto pRuntime. As the events on the blockchain are ordered naturally, the blockchain becomes a canonical source of events. 1. The miner (host) ingests the ingressive events to the runtime by calling 11 pRuntime.SyncBlockchain. The incoming events are paired with cryp- tographic evidence which is validated by a light-weight Substrate client inside pRuntime. It ensures the integrity of the incoming events. 2. The runtime picks out the events targeting the contract deployed inside and feeds the contract. The execution of the contract produces a view of the Chainstate, namely Chainview 3. At any time, users can query Chainview by pRuntime.Query. The iden- tity of the caller is attached to the queries so that the contract can decide whether to answer or not based on its customized authorization policy. The response to the query includes the query result as well as a commit- ment to the current blockchain state (e.g. height) and the contract state. In other words, all the outputs are subject to a certain blockchain state. 4. The runtime also produces various side-effects which is accessible bypRuntime.DumpSideEffect. A basic kind of side-effect is the encrypted contract state update pro- duced periodically by pRuntime. With the full contract state, a new miner doesn’t need to sync the data by replaying the entire blockchain history. Another kind of side-effects is outgoing messages targeting other contracts or blockchains, namely Egressing Events. The ability to post messages to external entities is the building block for contract interoperability. The submitted events are eventually dispatched to the target contract, or other blockchains by the Polkadot ICMP (Interchain Message Pass- ing, https://research.web3.foundation/en/latest/polkadot/ICMP/). Min- ers (host) are responsible to post the side-effects back to the blockchain. To invoke a contract the user needs to generate a shared secret key with the miner who runs the contract. This can be done via a non-interactive Diffie- Hellman key exchange scheme with her private key and the miner’s registered public key [12]. The key is used for future communication and then the user can submit the encrypted payload to the blockchain. The invocation events are processed by pRuntime once they arrive at the miner node. As invocation payloads are included in a block, the blockchain is naturally a canonical source of events. All the contract invocations initiated by users, smart contracts, and other blockchains are timestamped and treated equally by the executor. It therefore makes a unified interface for contract interoperability. The downside of the architecture is that the confirmation of the commands happens after the confirmation of the block. The performance of the blockchain becomes the bottleneck for contract invocations. However, the read-only queries are made into the runtime directly and the performance is not bounded by the blockchain. This is possible because the queries don’t modify the contract state. Miners are responsible to ensure the communication between pRuntime and the blockchain. A monitoring scheme is needed to ensure the connectivity. In the worst case (e.g. miner shutdown) the contract execution can be resumed by another miner. 12 4.9 State Recover A single miner is sufficient to run a contract. Though miners are incentivized to run contracts in the long term, the miner may still becomes unresponsive due to network or power outage rarely. In such a case another miner can recover the saved state from the blockchain and resume execution. As mentioned in section “Execute the Contract”, one of the side-effects pro- duced by pRuntime is the periodical contract state update. The dumped state is encrypted by kci and stored on the blockchain. In the case of miner unavailable, a new miner can recover the latest dumped contract state from the blockchain and decrypt it with kci . After recovering the state, the runtime can further replay the rest of the events on the blockchain until reaches the chain tip. 4.10 Responsiveness Monitoring Both Gatekeepers and miners are required to keep the responsiveness to keep the functionality of Phala Network. Gatekeepers have to maintain a high level of responsiveness because the root key is kept inside the Gatekeepers runtime and must be available at any time. As long as Gatekeepers can serve the contract key for miners, the availability of the contracts can be guaranteed. So unresponsive miners are not as harmful as unresponsive Gatekeepers to the system. We adopt a Polkadot-like unresponsiveness detection algorithm [7]. Both Gatekeepers and miners produce side-effects by their runtime. They have to at least post the state updates periodically to the blockchain within an interval. So all the submitted side-effects can be used as a counter of the online activities. Then we can determine if a node n is unresponsive in an era by cn < 14 maxn′ cn′ where cn is the activity counter for node n and n′ is all the connected worker nodes in the era. For the detailed design of slash, please refer to Economic Design Paper. 5 Open Question Security improvements: • Alternative TEE hardware: Though we use Intel SGX as the reference for the current design, we don’t make any assumptions about the hardware. Potential TEE hardware includes AMD SEV, ARM Turstzone, and some open-source implementations in progress. When we support any alternatives the different TEE can work together transparently. • Threshold key sharing on Gatekeeper root keys: The confidentiality of all the confidential contracts is derived from the root key. However root keys are replicated among all the Gatekeepers in current design, meaning a compro- mised TEE could compromise the whole system. A more robust ways is to 13 apply a threshold secret sharing scheme (e.g. Shamir’s) on the root key. A distributed key generation scheme (DKG) can be used instead of selecting a leader to generate the key in the key rotation protocol. • Contract key backup by secret sharing scheme: To avoid catastrophes where Intel SGX breaks entirely (e.g. Intel bans all the Remote Attestation request from our side), we can utilize a secret sharing scheme to distribute the Root Key to the Gatekeepers, or maybe two generations of the Gatekeepers. In such a case, we can wait for the deployment of an alternative TEE system. Then the secret holders can collaborate to ingest the key to recover the execution of Phala Network. Optimizations: • Redundant miners for a contract: Currently one contract is only associated with one miner. The state recovery still takes some time though the availabil- ity is guaranteed. With ¿1 miners, as the contract execution is deterministic, the miners can compete to run the contract and checkpoint the states on the blockchain. The blockchain can always accept new states and reject redun- dant submissions. • State storage prune • Layer 2 state sharing References [1] Amd secure encrypted virtualization (sev). https://developer.amd.com/ sev/. [2] Arm trustzone technology. https://developer.arm.com/ip-products/ security-ip/trustzone. [3] Command and query responsibility segregation (cqrs) pattern. https:// docs.microsoft.com/en-us/azure/architecture/patterns/cqrs. [4] Event sourcing design pattern. https://docs.microsoft.com/en-us/ azure/architecture/patterns/event-sourcing. [5] Intel sgx: Remote attestation. https://software.intel.com/en-us/ sgx/attestation-services. [6] Intel software guard extensions. https://www.intel.com/content/ www/us/en/architecture-and-technology/software-guard- extensions.html, 2019. [7] Polkadot slashing mechanisms. https://research.web3.foundation/en/ latest/polkadot/slashing/amounts/, 2019. [8] Trusted execution environment. https://en.wikipedia.org/wiki/ Trusted_execution_environment, 2019. 14 [9] Raymond Cheng, Fan Zhang, Jernej Kos, Warren He, Nicholas Hynes, Noah Johnson, Ari Juels, Andrew Miller, and Dawn Song. Ekiden: A platform for confidentiality-preserving, trustworthy, and performant smart contracts. In 2019 IEEE European Symposium on Security and Privacy (EuroS&P), pages 185–200. IEEE, 2019. [10] Wood Gavin. Polkadot: Vision for a heterogeneous multi-chain framework. 2016. [11] Eli Ben Sasson, Alessandro Chiesa, Christina Garman, Matthew Green, Ian Miers, Eran Tromer, and Madars Virza. Zerocash: Decentralized anony- mous payments from bitcoin. In 2014 IEEE Symposium on Security and Privacy, pages 459–474. IEEE, 2014. [12] Philipp Schindler, Aljosha Judmayer, Nicholas Stifter, and Edgar Weippl. Distributed key generation with ethereum smart contracts. [13] Nicolas Van Saberhagen. Cryptonote v 2.0. https://cryptonote.org/ whitepaper.pdf, 2013. 15
프로젝트로 돌아가기