精通以太坊 | 什么是以太坊
Ethereum is often described as "the world computer.” But what does that mean Let’s start with a computer science–focused description, and then try to decipher that with a more practical analysis of Ethereum’s capabilities and characteristics, while comparing it to Bitcoin and other decentralized information exchange platforms (or "blockchains" for short).
From a computer science perspective, Ethereum is a deterministic but practically unbounded state machine, consisting of a globally accessible singleton state and a virtual machine that applies changes to that state.
From a more practical perspective, Ethereum is an open source, globally decentralized computing infrastructure that executes programs called smart cONTracts. It uses a blockchain to synchronize and STOre the system’s state changes, along with a cryptocurrency called ether to meter and constrain execution resource costs.
The Ethereum platform enables developers to build powerful decentralized applications with built-in economic functions. While providing high availability, auditability, transparency, and neutrality, it also reduces or eliminates censorship and reduces certain counterparty risks.
以太坊平台使开发人员能够构建具有内置经济功能的强大的去中心化应用程序。在提供高可用性，可审计性，透明度和中立性的同时，它还减少或消除了审查并降低了某些交易双方的风险。Compared to Bitcoin与比特币比较
Many people will come to Ethereum with some prior experience of cryptocurrencies, specifically Bitcoin. Ethereum shares many common elements with other open blockchains: a peer-to-peer network connecting participants, a Byzantine fault–tolerant consensus algorithm for synchronization of state updates (a proof-of-work blockchain), the use of cryptographic primitives such as digital signatures and hashes, and a digital currency (ether).
Yet in many ways, both the purpose and construction of Ethereum are strikingly different from those of the open blockchains that preceded it, including Bitcoin.
Ethereum’s purpose is not primarily to be a digital currency payment network. While the digital currency ether is both integral to and necessary for the operation of Ethereum, ether is intended as a utility currency to pay for use of the Ethereum platform as the world computer.
Unlike Bitcoin, which has a very limited scripting language, Ethereum is designed to be a general-purpose programmable blockchain that runs a virtual machine capable of executing code of arbitrary and unbounded complexity. Where Bitcoin’s Script language is, intentionally, constrained to simple TRUE/false evaluation of spending conditions, Ethereum’s language is Turing complete, meaning that Ethereum can straightforwardly function as a general-purpose computer.
与具有非常有限的脚本语言的比特币不同，以太坊被设计为通用可编程区块链，其运行能够执行任意和无限复杂代码的虚拟机。比特币的脚本语言被故意限制为对支出条件的简单的真/假评估，以太坊的语言是图灵完备的，这意味着以太坊可以直接起到通用计算机的作用。Components of a Blockchain区块链的组成部分
The components of an open, public blockchain are (usually):
A peer-to-peer (P2P) network connecting participants and propagating transactions and blocks of verified transactions, based on a standardized "gossip" protocol
Messages, in the form of transactions, representing state transitions
A set of consensus rules, governing what constitutes a transaction and what makes for a valid state transition
A state machine that processes transactions according to the consensus rules
A chain of cryptographically secured blocks that acts as a journal of all the verified and accepted state transitions
A consensus algorithm that decentralizes control over the blockchain, by forcing participants to cooperate in the enforcement of the consensus rules
A game-theoretically sound incentivization scheme (e.g., proof-of-work costs plus block rewards) to economically secure the state machine in an open environment
One or more open source software implementations of the above ("clients")
All or most of these components are usually combined in a single software client. For example, in Bitcoin, the reference implementation is developed by the Bitcoin Core open source project and implemented as the bitcoind client. In Ethereum, rather than a reference implementation there is a reference specification, a mathematical description of the system in the Yellow Paper (see Further Reading). There are a number of clients, which are built according to the reference specification.
In the past, we used the term "blockchain" to represent all of the components just listed, as a shorthand reference to the combination of technologies that encompass all of the characteristics described. Today, however, there are a huge variety of blockchains with different properties. We need qualifiers to help us understand the characteristics of the blockchain in question, such as open, public, global, decentralized, neutral, and censorship-resistant, to identify the important emergent characteristics of a "blockchain" system that these components allow.
Not all blockchains are created equal. When someone tells you that something is a blockchain, you have not received an answer; rather, you need to start asking a lot of questions to clarify what they mean when they use the word "blockchain." Start by asking for a description of the components in the preceding list, then ask whether this "blockchain" exhibits the characteristics of being open, public, ETC.
并非所有区块链都是相同的。当有人告诉你某些东西是区块链时，你还没有得到答案;相反，你需要开始提出很多问题来澄清他们使用“区块链”这个词时的真正表达含义。首先要求对前面列表中的组件进行描述，然后询问这个“区块链”是否具有开放，公开等特征。The Birth of Ethereum以太坊的诞生
All great innovations solve real problems, and Ethereum is no exception. Ethereum was conceived at a time when people recognized the power of the Bitcoin model, and were trying to move beyond cryptocurrency applications. But developers faced a conundrum: they either needed to build on top of Bitcoin or start a new blockchain. Building upon Bitcoin meant living within the intentional constraints of the network and trying to find workarounds. The limited set of transaction types, data types, and sizes of data storage seemed to limit the sorts of applications that could run directly on Bitcoin; anything else needed additional off-chain layers, and that immediately negated many of the advantages of using a public blockchain. For projects that needed more freedom and flexibility while staying on-chain, a new blockchain was the only option. But that meant a lot of work: bootstrapping all the infrastructure elements, exhaustive testing, etc.
Toward the end of 2013, Vitalik Buterin, a young programmer and Bitcoin enthusiast, started thinking about further extending the capabilities of Bitcoin and Mastercoin (an overlay protocol that extended Bitcoin to offer rudimentary smart contracts). In October of that year, Vitalik proposed a more generalized approach to the Mastercoin team, one that allowed flexible and scriptable (but not Turing-complete) contracts to replace the specialized contract language of Mastercoin. While the Mastercoin team were impressed, this proposal was too radical a change to fit into their development roadmap.
In December 2013, Vitalik started sharing a whitepaper that outlined the idea behind Ethereum: a Turing-complete, general-purpose blockchain. A few dozen people saw this early draft and offered feedback, helping Vitalik evolve the proposal.
Both of the authors of this book received an early draft of the whitepaper and commented on it. Andreas M. Antonopoulos was intrigued by the idea and asked Vitalik many questions about the use of a separate blockchain to enforce consensus rules on smart contract execution and the implications of a Turing-complete language. Andreas continued to follow Ethereum’s progress with great interest but was in the early stages of writing his book Mastering Bitcoin, and did not participate directly in Ethereum until much later. Dr. Gavin Wood, however, was one of the first people to reach out to Vitalik and offer to help with his C programming skills. Gavin became Ethereum’s cofounder, codesigner, and CTO.
本书的两位作者都收到了白皮书的早期草稿并对其进行了评论。 Andreas M. Antonopoulos对这个想法很感兴趣，并向Vitalik询问了许多关于使用单独的区块链来强制执行在智能合约执行上的共识规则以及图灵完备语言含义的问题。Andreas 继续以极大的兴趣关注着以太坊的发展，但是当时他还在写《Mastering Bitcoin》一书的早期阶段，直到很久以后才直接参与以太坊。然而，Gavin Wood博士是第一批接触Vitalik并用他的C 编程技能提供帮助的人之一。 Gavin成为以太坊的联合创始人，联合设计者和CTO。
As Vitalik recounts in his "Ethereum Prehistory" post:
This was the time when the Ethereum protocol was entirely my own creation. From here on, however, new participants started to join the fold. By far the most prominent on the protocol side was Gavin Wood…
这是以太坊协议完全是我自己创造的时候。然而，从现在开始，新的参与者开始加入这一行列。到目前为止，协议方面最突出的是Gavin Wood ……
Gavin can also be largely credited for the subtle change in vision from viewing Ethereum as a platform for building programmable money, with blockchain-based contracts that can hold digital assets and transfer them according to pre-set rules, to a general-purpose computing platform. This started with subtle changes in emphasis and terminology, and later this influence became stronger with the increasing emphasis on the “Web 3” ensemble, which saw Ethereum as being one piece of a suite of decentralized technologies, the other two being Whisper and Swarm.
通过将以太坊视为构建可编程货币的平台（通过区块链的可以保存数字资产并根据预先设定的规则转移资产的合同） 到将以太坊视为一个通用计算平台，Gavin也可以在很大程度上归功于愿景的细微变化。 。这开始于重点和术语的微妙变化，随后越来越强调“Web 3”集合，将以太坊视为一组去中心化技术的一部分，另外两个是Whisper和Swarm，这种影响变得更强。
Starting in December 2013, Vitalik and Gavin refined and evolved the idea, together building the protocol layer that became Ethereum.
Ethereum’s founders were thinking about a blockchain without a specific purpose, that could support a broad variety of applications by being programmed. The idea was that by using a general-purpose blockchain like Ethereum, a developer could program their particular application without having to implement the underlying mechanisms of peer-to-peer networks, blockchains, consensus algorithms, etc. The Ethereum platform was designed to abstract these details and provide a deterministic and secure programming environment for decentralized blockchain applications.
Much like Satoshi, Vitalik and Gavin didn’t just inVENt a new technology; they combined new inventions with existing technologies in a novel way and delivered the prototype code to prove their ideas to the world.
The founders worked for years, building and refining the vision. And on July 30, 2015, the first Ethereum block was mined. The world’s computer started serving the world.
创始人工作多年，构建和完善愿景。 2015年7月30日，第一个以太坊区块被开采/挖矿。世界计算机开始为世界服务。NoteVitalik Buterin’s article "A Prehistory of Ethereum" was published in September 2017 and provides a fascinating first-person view of Ethereum’s earliest moments.You can read it at https://vitalik.ca/general/2017/09/14/prehistory.html.NoteVitalik Buterin的文章“以太坊的史前史”于2017年9月出版，为以太坊最早的时期提供了一个吸引人的第一人称视角。你可以在这里阅读 https://vitalik.ca/general/2017/09/14/prehistory.html.Ethereum’s Four Stages of Development以太坊的四个发展阶段
Ethereum’s development was planned over four distinct stages, with major changes occurring at each stage. A stage may include subreleases, known as "hard forks," that change functionality in a way that is not backward compatible.
The four main development stages are codenamed Frontier, Homestead, Metropolis, and Serenity. The intermediate hard forks that have occurred (or are planned) to date are codenamed Ice Age, DAO, Tangerine Whistle, Spurious Dragon, Byzantium, and Constantinople. Both the development stages and the intermediate hard forks are shown on the following timeline, which is "dated" by block number:
四个主要的发展阶段的代号为Frontier，Homestead，Metropolis和Serenity。到目前为止（或计划）发生的中间硬分叉代号为Ice Age，DAO，Tangerine Whistle，Spurious Dragon，Byzantium和Constantinople。发展阶段和中间硬分叉都显示在以下时间轴上，该时间轴按区块编号“标注日期”：
Frontier—The initial stage of Ethereum, lasting from July 30, 2015, to March 2016.
Ice Age—A hard fork to introduce an exponential difficulty increase, to motivate a transition to PoS when ready.
Homestead—The second stage of Ethereum, launched in March 2016.
DAO—A hard fork that reimbursed victims of the hacked DAO contract and caused Ethereum and Ethereum Classic to split into two competing systems.
Tangerine Whistle—A hard fork to change the gas calculation for certain I/O-heavy operations and to clear the accumulated state from a denial-of-service (DoS) attack that exploited the low gas cost of those operations.
Spurious Dragon—A hard fork to address more DoS attack vectors, and another state clearing. Also, a replay attack protection mechanism.
Metropolis Byzantium—Metropolis is the third stage of Ethereum, current at the time of writing this book, launched in October 2017. Byzantium is the first of two hard forks planned for Metropolis.
After Byzantium, there is one more hard fork planned for Metropolis: Constantinople. Metropolis will be followed by the final stage of Ethereum’s deployment, codenamed Serenity.
在Byzantium之后，还有一个为Metropolis计划的硬分叉：Constantinople（君士坦丁堡）。Metropolis之后将是以太坊部署的最后阶段，代号为Serenity（宁静）。Ethereum: A General-Purpose Blockchain以太坊：通用区块链
The original blockchain, namely Bitcoin’s blockchain, tracks the state of units of bitcoin and their ownership. You can think of Bitcoin as a distributed consensus state machine, where transactions cause a global state transition, altering the ownership of coins. The state transitions are constrained by the rules of consensus, allowing all participants to (eventually) converge on a common (consensus) state of the system, after several blocks are mined.
Ethereum is also a distributed state machine. But instead of tracking only the state of currency ownership, Ethereum tracks the state transitions of a general-purpose data store, i.e., a store that can hold any data expressible as a key–value tuple. A key–value data store holds arbitrary values, each referenced by some key; for example, the value "Mastering Ethereum" referenced by the key "Book Title". In some ways, this serves the same purpose as the data storage model of Random Access Memory (RAM) used by most general-purpose computers. Ethereum has memory that stores both code and data, and it uses the Ethereum blockchain to track how this memory changes over time. Like a general-purpose stored-program computer, Ethereum can load code into its state machine and run that code, storing the resulting state changes in its blockchain. Two of the critical differences from most general-purpose computers are that Ethereum state changes are governed by the rules of consensus and the state is distributed globally. Ethereum answers the question: "What if we could track any arbitrary state and program the state machine to create a world-wide computer operating under consensus"
以太坊也是一个分布式状态机。但是，以太网不仅仅跟踪货币所有权状态，而是跟踪通用数据存储的状态转换，比如可以保存任何可表示为键值元组的数据的存储。键值数据存储保存任意值，每个值由某个键引用;例如，键“Book Title”引用的值“Mastering Ethereum”。在某些方面，这与大多数通用计算机使用的随机存取存储器（RAM）的数据存储模型具有相同的目的。以太坊拥有存储代码和数据的内存，并使用以太坊区块链来跟踪内存随时间的变化情况。与通用存储程序计算机一样，以太坊可以将代码加载到其状态机中并运行该代码，将结果状态更改存储在其区块链中。与大多数通用计算机存在的两个重要区别是，以太坊状态变化受共识规则的约束，并且状态是全球分布的。以太坊回答了这个问题：“假如我们可以跟踪任意状态并对状态机进行编程以创建一个在共识下运行的全球计算机，那会怎么样？”Ethereum’s Components以太坊的组件
In Ethereum, the components of a blockchain system described in Components of a Blockchain are, more specifically:
在以太坊中，Components of a Blockchain中描述的区块链系统的组件更具体地说有：
Ethereum runs on the Ethereum main network, which is addressable on TCP port 30303, and runs a protocol called ÐΞVp2p.
Ethereum’s consensus rules are defined in the reference specification, the Yellow Paper (see Further Reading).
Ethereum transactions are network messages that include (among other things) a sender, recipient, value, and data payload.
Ethereum state transitions are processed by the Ethereum Virtual Machine (EVM), a stack-based virtual machine that executes bytecode (machine-language instructions). EVM programs, called "smart contracts," are written in high-level languages (e.g., Solidity) and compiled to bytecode for execution on the EVM.
Ethereum’s state is stored locally on each node as a database (usually Google’s LevelDB), which contains the transactions and system state in a serialized hashed data structure called a Merkle Patricia Tree.
Ethereum uses Bitcoin’s consensus model, Nakamoto Consensus, which uses sequential single-signature blocks, weighted in importance by PoW to determine the longest chain and therefore the current state. However, there are plans to move to a PoS weighted voting system, codenamed Casper, in the near future.
Ethereum currently uses a PoW algorithm called Ethash, but this will eventually be dropped with the move to PoS at some point in the future.
Ethereum has several interoperable implementations of the client software, the most prominent of which are Go-Ethereum (Geth) and Parity.
以太坊的状态以数据库（通常是Google的LevelDB）的形式存储在每个本地节点上，该数据库包含称为Merkle Patricia Tree的序列化哈希数据结构中的交易和系统状态。
The following references provide additional information on the technologies mentioned here:
The Ethereum Yellow Paper: https://ethereum.github.io/yellowpaper/paper.pdf
The Beige Paper, a rewrite of the Yellow Paper for a broader audience in less formal language:https://github.com/chronAEon/beigepaper
ÐΞVp2p network protocol: http://bit.ly/2quAlTE
Ethereum Virtual Machine list of resources: http://bit.ly/2PmtjiS
LevelDB database (used most often to store the local copy of the blockchain): http://leveldb.org
Merkle Patricia trees: https://github.com/ethereum/wiki/wiki/Patricia-Tree
Ethash PoW algorithm: https://github.com/ethereum/wiki/wiki/Ethash
Casper PoS v1 Implementation Guide: http://bit.ly/2DyPr3l
Go-Ethereum (Geth) client: https://geth.ethereum.org/
Parity Ethereum client: https://parity.io/Ethereum and Turing Completeness以太坊和图灵完备性
As soon as you start reading about Ethereum, you will immediately encounter the term "Turing complete." Ethereum, they say, unlike Bitcoin, is Turing complete. What exactly does that mean
The term refers to English mathematician Alan Turing, who is considered the father of computer science. In 1936 he created a mathematical model of a computer consisting of a state machine that manipulates symbols by reading and writing them on sequential memory (resembling an infinite-length paper tape). With this construct, Turing went on to provide a mathematical foundation to answer (in the negative) questions about universal computability, meaning whether all problems are solvable. He proved that there are classes of problems that are uncomputable. Specifically, he proved that the halting problem (whether it is possible, given an arbitrary program and its input, to determine whether the program will eventually stop running) is not solvable.
Alan Turing further defined a system to be Turing complete if it can be used to simulate any Turing machine. Such a system is called a Universal Turing machine (UTM).
Ethereum’s ability to execute a stored program, in a state machine called the Ethereum Virtual Machine, while reading and writing data to memory makes it a Turing-complete system and therefore a UTM. Ethereum can compute any algorithm that can be computed by any Turing machine, given the limitations of finite memory.
Ethereum’s groundbreaking innovation is to combine the general-purpose computing architecture of a stored-program computer with a decentralized blockchain, thereby creating a distributed single-state (singleton) world computer. Ethereum programs run "everywhere," yet produce a common state that is secured by the rules of consensus.
以太坊的突破性创新是将存储程序计算机的通用计算架构与去中心化的区块链相结合，从而创建分布式单状态（单例）世界计算机。以太坊程序在任何地方运行，“无处不在”，但却产生了一个由共识规则保护的共同状态。Turing Completeness as a "Feature"作为一个“特征”的图灵完备性
Hearing that Ethereum is Turing complete, you might arrive at the conclusion that this is a feature that is somehow lacking in a system that is Turing incomplete. Rather, it is the opposite. Turing completeness is very easy to achieve; in fact, the simplest Turing-complete state machine known has 4 states and uses 6 symbols, with a state definition that is only 22 instructions long. Indeed, sometimes systems are found to be "accidentally Turing complete." A fun reference of such systems can be found at http://bit.ly/2Og1VgX.
However, Turing completeness is very dangerous, particularly in open access systems like public blockchains, because of the halting problem we touched on earlier. For example, modern printers are Turing complete and can be given FILes to print that send them into a frozen state. The fact that Ethereum is Turing complete means that any program of any complexity can be computed by Ethereum. But that flexibility brings some thorny security and resource management problems. An unresponsive printer can be turned off and turned back on again. That is not possible with a public blockchain.
但是，图灵完备性是非常危险的，特别是在公共区块链等开放式访问系统中，这是因为我们之前提到的停止问题。例如，现代打印机是图灵完备的，可以打印给定文件，将它们发送到冻结状态。以太坊是图灵完备的事实意味着任何复杂程序都可以由以太坊计算。但这种灵活性带来了一些棘手的安全和资源管理问题。无响应的打印机可以关闭并再次打开。而这在一个公共区块链是不可能的。Implications of Turing Completeness图灵完备性的含义
Turing proved that you cannot predict whether a program will terminate by simulating it on a computer. In simple terms, we cannot predict the path of a program without running it. Turing-complete systems can run in "infinite loops," a term used (in oversimplification) to describe a program that does not terminate. It is trivial to create a program that runs a loop that never ends. But unintended never-ending loops can arise without warning, due to complex interactions between the starting conditions and the code. In Ethereum, this poses a challenge: every participating node (client) must validate every transaction, running any smart contracts it calls. But as Turing proved, Ethereum can’t predict if a smart contract will terminate, or how long it will run, without