JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
Back to the library
区块链 2014

以太坊:下一代智能合约与去中心化应用平台

维塔利克·布特林

把一台可编程的计算机,放进区块链里——代码,就成了无人能拦的合约。

Choose your version
In depth · the introduction

要是区块链能做的不只是转账呢——要是你能往里头放一段程序,一段会自己运行、且无人能关掉的程序,会怎样?

把这个想法拆开看

比特币给了世界一本共享的账本,陌生人无须银行,便能让它保持诚实。可它的账本,其实只做一件事:记录谁给谁转了多少钱。以太坊问了一个更大的问题——要是这本账本,还能装下程序呢?

这就是它的全部想法。以太坊是一台单一的、共享的计算机,它同时活在成千上万台机器之上。你可以往它上面,上传一小段程序,叫作「智能合约」;从此,它便完全按所写的那样运行,对每个人都一模一样,没有哪家公司托管它,也没有关机键。钱、规则与代码,住在了同一个地方。

它从哪里来

2013 年末,一位十九岁的程序员、比特币撰稿人——维塔利克·布特林——传出了一份白皮书。他的论点是:人们总想把新功能一个一个地硬塞进比特币,可真正需要的,是一条内建了完整编程语言的区块链,好让任何人都能写出他想要的任何功能。这个项目是由一群人、而非一个人创立的;加文·伍德(Gavin Wood)撰写了严谨的技术规范(即「黄皮书」)、并构建了早期的软件,另有数人共同创立了这项事业。以太坊于 2015 年 7 月上线。

它为何重要

一旦区块链能运行程序,你就能搭建那些过去需要一个「受信任的中间公司」的东西——并改由代码来执行它们。一份合约,可以把钱托管起来、只在条件满足时才放行;它可以举办一场拍卖、发行一种数字代币,或协调一个团体的共有资金。因为这段程序,不过是一份人人都能读、却无人能偷偷篡改的合约,你便无须信任那个运营方——根本就没有运营方。这一转变,从「信任公司」到「核查代码」,正是其后那整个代币与去中心化金融世界得以建起的根基。

一台自动售货机

想象一台自动售货机。它装着货物和钱,遵循固定的规则——投进正确的硬币、按下按钮,零食就掉出来——而且它对每个人都一视同仁,无须店主在场。智能合约,就是一台由代码做成的自动售货机:它持有价值,遵循写进它的规则,自动地、以同样的方式服务任何人。下方的小工具,让你给这样一台机器喂进一笔交易、看它运行起来——也看看它中途「燃料」耗尽时,会发生什么。

一个针对「调用小合约存入一个值」这笔以太坊交易的可交互面板:两根滑块设定 STARTGAS(燃料预算)与 GASPRICE(每单位燃料支付的以太),一根彩色条形图把预算拆成交易字节耗费的燃料、代码运行耗费的燃料,以及退还的燃料。当 STARTGAS 足以覆盖花费时,合约执行完成,未用燃料被退还,仅消耗掉的费用归矿工;当 STARTGAS 太低时,它燃料耗尽,所有状态改动被回滚,可全部费用仍被矿工拿走。

它所处的位置

以太坊,直接站在中本聪的比特币之上(本馆亦有收录):它保留了那本共享的、防篡改的账本,并在其上加了一门编程语言。它对自己的难处,也很诚实——2016 年,一份名为「The DAO」的著名合约被一个 bug 抽空,社区选择以一次硬分叉来逆转它,这把链一分为二,也表明「代码即法律」自有其被人定下的边界。从这套设计里,长出了今天加密世界大半赖以建立的数字代币、市场与去中心化金融应用。

The original document
Original source text
Vitalik Buterin · “A Next-Generation Smart Contract and Decentralized Application Platform” · written 2013–2014 · ethereum.org
Introduction
What Ethereum intends to provide is a blockchain with a built-in fully fledged Turing-complete programming language that can be used to create “contracts” that can be used to encode arbitrary state transition functions.
The introduction reviews Bitcoin as the first realisation of decentralised consensus, then argues that the same machinery can support far more than currency once the transaction language is made expressive.
Ethereum Accounts
In Ethereum, the state is made up of objects called “accounts”, with each account having a 20-byte address and state transitions being direct transfers of value and information between accounts.
Each account holds four fields — a nonce, an ether balance, contract code (if any), and storage — replacing Bitcoin's stateless UTXO set with explicit, persistent account state.
Messages and Transactions
The STARTGAS and GASPRICE fields are crucial for Ethereum's anti-denial of service model. … The fundamental unit of computation is “gas”; usually, a computational step costs 1 gas.
A transaction names a ceiling on the computation it may consume (STARTGAS) and a price per unit (GASPRICE); the product is the maximum fee. If execution exhausts the gas, it reverts — but the fee is still paid.
The State Transition Function — APPLY(S, TX) → S′
Check if the transaction is well-formed … the signature is valid, and the nonce matches the nonce in the sender's account. If not, return an error.
If the value transfer failed because the sender did not have enough money, or the code execution ran out of gas, revert all state changes except the payment of the fees, and add the fees to the miner's account.
[ … ]
Applications & remaining sections
The full paper continues through code execution and the virtual machine, token systems, financial and non-financial applications, decentralised autonomous organisations, scalability concerns and conclusions — and is kept current at the source below.
Vitalik Buterin · Ethereum White Paper · 2014