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