REM Reading Report

REM Reading Report & Future Plan

Overview

REM & PoUW

REM(Resource-Efficient Mining) is a new blockchain mining framework that uses trusted hardware(Intel SGX) to achieve a fraction of the waste of PoW. It’s partially decentralized, and it achieves security guarantees similar to PoW. Its key idea, Proof-of-Useful-Work(PoUW), involves miners providing trustworthy reporting on CPU cycles they devote to inherently useful workloads. In a PoUW system, users can utilize their CPUs for any desired workload, and can simultaneously contribute their work towards securing a blockchain.

Fundamental impediment of PoW

As Satoshi Nakamoto put Proof-of-Work(PoW) in BitCoin, PoW is widely used in blockchain so that the consensus can prevent an attacker from gaining majority power by cheaply masquerading as multiple machines. However, PoW in blockchains are wasteful, and it even has another name: Proof of Waste. PoWs serve no useful purpose beyond consensus and incur huge monetary and environmental costs, which is against FinTech’s demand.

PoET

Many attempts have been made to create a more resource useful consensus. However they have serious limitations.
Intel recently introduced a new instruction set architecture extension in Intel CPUs called Software Guard Extension(SGX). SGX permits the execution of trustworthy code in an isolated, tamper free environment, and can prove remotely that outputs represent the result of such execution. And Intel proposed another innovative consensus: Proof of Elapsed Time(PoET). However, PoET presents two notable technical challenges: broken chip problem(an attacker that can corrupt a single SGX-enabled node can win every consensus round and break the system completely) and stale chip problem(miners tend to power mining rigs with cheap, outmoded SGX-enabled CPUs used solely for mining). REM addresses both the stale and broken chip problems.

SGX

SGX enables process execution in a Trusted Execution Environment(TEE), and specifically in SGX in a protected address space known as an enclave. An enclave protects the confidentiality and the integrity of the process from certain forms of hardware attack and other processes on the same host, including privileged processes like operating systems. SGX signs quotes in attestations using a group signature scheme called Enhanced Privacy ID or EPID, and Intel made the design choice that attestations can only be verified by accessing Intel’s Attestation Service(IAS), a public Web service maintained by Intel whose primary responsibility is to verify attestations upon request.

PoUW and REM

two key assumptions

The basic idea of PoUW, and thus REM, is to replace the wasteful computation of PoW with arbitrary useful computation. Since it is only partially decentralized, it relies for security on two key assumptions about the hardware manufacturer’s behavior: First, Intel correctly manages identities, specifically that it assigns a signing key(used for attestations) only to a valid CPU. Second, Intel does not blacklist valid nodes in the network, rendering their attestations invalid when the IAS is queried.
If Intel didn’t follow the two assumptions and was detected in any context, the company’s reputation and the perceived utility of SGX would be undermined and Intel would gain little revenue. So generally we can trust Intel SGX.

the architecture of REM

Figure1
There are three types of entities in the ecosystem of REM: a blockchain agent, one or more REM miners, and one or more useful work clients.
The useful work clients supply useful workloads to REM miners in the form of PoUW tasks, each of which encompass a PoUW enclave and some input.
The blockchain agent collects transactions and generates a block template, a block lacking the proof of useful work(PoUW). A REM miner will attach the required PoUW and return it to the agent. The agent then publishes the full block to the P2P network, making it part of the blockchain and receiving the corresponding reward.

Figure2
Although CPU cycles would have been a more accurate metric, they are vulnerable to manipulation. The operating system may set their values arbitrarily and even have them double-count cycles. Therefore, REM chose instruction counting for securely evaluating effort with the existing tools available in SGX.
The workflow of the PoUW toolchain is as shown below: First, the useful work code (usefulwork.cpp), C / C++ source code, is assembled while reserving a register as the instruction counter. Next, the assembly code is rewritten by the toolchain such that the counter is incremented at the beginning of each basic block (a linear code sequence with no branches) by the number of instructions in that basic block. The count is performed at the beginning of a block rather than its end to prevent a cheater from jumping to the middle of a block and gaining an excessive count.

Figure3
PoUW attestations is formed with two-layer hierarchical attestations. Zhang et al hard-code only a single program’s fingerprint into the blockchain, a static-analysis tool called compliance checker. The compliance checker runs in a trusted environment and takes a user-supplied program as input.
Every PoUW then includes two parts: The useful work program attestation on the mining success, and an attestation from the compliance checker of the program’s compliance. Note that the compliance attestation and the program’s attestation must be signed by the same CPU. Otherwise an attacker that compromises a single CPU could create fake compliance attestations for invalid tasks.

REM读书报告中文版

概述

REM与PoUW

REM(资源节约型挖矿)为一种新型的使用可信任硬件(Intel SGX)的区块链挖矿框架,大幅度减少了工作量证明(PoW)的浪费。部分去中心化的REM实现了与PoW类似的安全性保证。其核心思想,有效工作量证明(PoUW),使得矿工提供所贡献的有效工作负载的CPU周期的可信任证明。在PoUW系统中,用户可以将CPU用于任何期望工作负载,同时贡献其工作来使得区块链更安全。

工作量证明的重大缺陷

中本聪在比特币中使用的工作量证明PoW,被广泛应用于区块链技术,该共识机制可以有效防止恶意攻击者通过低成本地伪装成多台机器以获得大多数权力。然而,区块链的工作量证明是浪费的,它甚至还有一个别名:浪费量证明。除了实现共识,它别无它用,却造成了大量的资金与环境浪费,而这与金融科技的愿景是相违背的。

PoET

为了实现更加节约型的共识机制,已经有许多共识机制进行尝试。不过往往这些共识机制都有非常严格的限制。
近日Intel在其CPU中推行了一种新型指令集扩展结构,称为SGX(Software Guard Extension)。SGX允许可信任代码在隔绝、防干扰的环境中执行,并且远程验证程序执行的输出结果。在SGX的基础上,Intel提出了新的共识机制:运行时间证明(Proof of Elapsed Time, PoET)。然而,PoET有两个显著的技术挑战:芯片沦陷问题和芯片老旧问题。

SGX

SGX使进程执行在可信任执行环境(Trusted Execution Environment, TEE)中,而且SGX中专门有一块受保护的名为enclave(暂译为保护领地)的地址。Enclave保证了进程的机密性和完整性,避免来自硬件的攻击以及其他优先进程如操作系统等影响。SGX在认证过程中使用一种名为强化隐私ID(Enhanced Privacy ID, EPID)的群签名方案。同时Intel决定认证只能通过Intel认证服务(Intel’s Attestation Service)进行,IAS是Intel维持的公共网络服务,其首要责任是验证请求的认证。

PoUW和REM

两个关键假设

PoUW及REM的基本思想是将PoW中浪费的计算量替代为任意有效计算量。因为它是部分去中心化的,所以其安全性依赖关于硬件制造商行为的两个关键假设:第一,Intel正确地进行身份管理,特别是对一个有效CPU只分配唯一的签名密钥(用于认证)。第二,Intel不会针对网络中的节点设立黑名单,不会当IAS请求响应时假装其认证无效。
如果Intel违背上述两条假设中的任意一条,只要被检测出来,其公司的声誉以及用户对SGX的认同会大大削减,Intel得不偿失。所以总体而言我们可以信任Intel SGX。

REM框架

在REM的生态中有三类实体:一位区块链代理,一位或多位REM矿工,以及一位或多位有效工作客户。
有效工作客户将有效工作负载以PoUW任务的形式提供给REM矿工,每一个任务包含一个PoUW enclave以及一些输入。
区块链代理收集处理,生成一个区块模板,一个没有PoUW的区块。REM矿工会附上所需的PoUW的区块并返回该区块。区块链代理随后将完整的区块发布至P2P网络,使其成为区块链的一部分,而矿工也获得对应的奖励。

尽管CPU周期也许是更准确的测量标准,它却易被操控。操作系统可以任意修改其值,甚至可以翻倍。因此,在已有SGX工具的情况下,REM选择对指令计数,以保证评价的安全性。
PoUW工具链的流程如下:首先,有效工作代码,C或C++源码,以汇编形式处理,同时预留一个寄存器作为指令计数器。然后,工具链将汇编代码进行重写,使得计数器在每个基块(无分支的线性代码序列)时根据基块的指令数目进行计数。同时为了保证正确性,工具链还实现了两个强制措施:强制代码不可写入,以及强制单线程操作。

PoUW的认证过程是两级认证。Zhang Fan等人硬编码单个程序的“指纹”(fingerprint)——一种称为一致性检查的静态分析工具——至区块链中。一致性检查在可信任环境中运行,以用户提供的程序作为输入。
每一份PoUW包含两部分:成功挖矿时的有效工作程序认证,以及来自一致性检查的程序一致性认证。注意到一致性认证以及程序认证的签名必须来自同一CPU。否则攻击者可以攻击单个CPU后为无效任务伪造一致性认证。

Personal perspective

虽然在5.1的Why Count Instructions中解释了为什么采用指令计数的方式。

While instructions are reasonable estimates of the CPU effort, CPU cycles would have been a more accurate metric. However, although cycles are counted, and the counts can be accessed through the CPU’s performance counters, they are vulnerable to manipulation. The operating system may set their values arbitrarily, allowing a rational operator, who controls her own OS, to improve her chances of finding a block by faking a high cycle count. Moreover, counters are incremented even if an enclave is swapped out, allowing an OS scheduler to run multiple SGX instances and having them double-count cycles. Therefore, while instruction counting is not perfect, we find it is the best method for securely evaluating effort with the existing tools available in SGX.

不过个人认为还是可以采用执行时间证明(Proof of Execution Time, PoET’)的方法实现共识。CPU的晶振周期与时钟周期是固定的(本来我以为单个机器的机器周期是固定不变的,但是机器周期即为CPU周期,所以才知道是可以由操作系统改变的)。可以使用执行时间÷时钟周期(晶振周期)÷某一常数近似估计指令数目,而不需要专门设计工具链对汇编语言进行计数。
另外,一篇名为Malware Guard Extension: Using SGX to Conceal Cache Attacks(Extend Version)的论文也值得引起我们对SGX安全性的重视。(这篇论文是我近日查找资料时不经意看到的搜狐报道的英特尔 SGX:是用来隐藏恶意软件,而不是保护系统;会泄漏加密密钥后去找的论文,还没有仔细看)