Advanced Blockchain-Based Concepts: 2.1 Ether
Advanced Blockchain-Based Concepts: 2.1 Ether
In the last lecture, we saw one very specific use of the blockchain: as a cryptographically secure
decentralized currency. Blockchain technology, however, is much more powerful, and has seen many
alternative uses. We will discuss one of these today: smart contracts, and their implementation as the
Ethereum protocol. We will also discuss Zerocash, a protocol which aims to provide a cryptocurrency
with provable anonymity.
1 Smart contracts
The basic notion of a smart contract is a program which runs ‘on the blockchain’. What this means
is that generating a new block or verifying the integrity of a block entails executing the program,
and so the smart contract is executed by every participant in the protocol. This public verification
ensures the integrity of the execution.
We can think of Bitcoin itself as a kind of simple smart contract, where the program to be
executed is something like ‘if Alice holds at least n bitcoins, transfer n bitcoins from Alice to Bob’.
Verifying a block entails running this program. Protocols like Ethereum provide much more flexible
and expressive smart contracts, using simple scripting languages.
2 Ethereum
In this section we will describe the operation of the Ethereum protocol for smart contracts.
2.1 Ether
Underlying Ethereum is a currency called ether, which serves two purposes. The first is to incen-
tivize participation. In any blockchain-based system, the integrity of the shared state is guaranteed
by cryptographic proofs of work (usually finding an input which hashes to something ‘nice’). This
is crucial in guaranteeing that the ‘honest majority’ of computational power in the system retains
control of the blockchain. Generating these proofs is inherently expensive, and so in order to incen-
tivize the creation of new blocks, there must be some mechanism by which parties who do so are
compensated, as in Bitcoin. Ethereum presents the additional challenge that the cost of generating
a block depends not only on the proof of work but also on the complexity of any smart contracts
which are executed as a result of the block’s creation. This is resolved in the Ethereum protocol by
associating a cost (in ether) with every step of computation, which is paid to the party that ‘mines’
that block. We will discuss the details of how this works later.
The other use of ether is as an internal cryptocurrency which can be manipulated using smart
contracts. That is, contracts can hold some amount of ether and transfer it elsewhere (including to
other contracts, a form of message passing). This allows for interesting applications such as verifiable
lotteries and decentralized autonomous organizations; the blockchain ensures that all transactions
generated by the contract are as specified in its source code.
2.2 Accounts
In Ethereum, the basic object of state is an account. Every account is associated with a 20-byte
address and an ether balance. There are two different kinds of accounts: externally owned accounts,
1
belonging to users of the system (and controlled by the user’s private key), and contract accounts,
which are ‘autonomous’ accounts controlled by contract code. In addition to the address and ether
balance, therefore, contract accounts have associated with them some code and some storage which
can be accessed and modified by the code.
To create an external account, a user generates a public-private key pair. The address of the
account is generated from (a hash of) the public key, and the account is created by sending a
transaction to that address. To create a contract, the user simply chooses some unused address and
sends a transaction to that address, where the code of the contract is included in the transaction
data.
2
The gas price captures the fact that the ether currency and the computation itself are different
resources, whose costs depend on vastly different factors. For example, if ether drops in value, the
gas price chosen should be increased in order to make participation in the protocol worthwhile.
When a contract sends a message to another contract, the contract receiving the message is
treated as part of the same execution, using up the gas allowance of the sender. For example,
suppose that contract A is executed with gas limit 1000, and uses up 100 gas before calling contract
B, which uses up 300 gas. Then when B returns, the remaining gas is 600. Gas price is maintained
when one contract calls another, which makes it easier for a miner to estimate the reward it obtains
from adding this transaction to a block.
3 Anonymous Bitcoin
The Bitcoin protocol provides some amount of anonymity: payments are conducted between ad-
dresses, and no identifying information about the owner of the address needs to be provided. How-
ever, all of the transactions that take place are public, and so it is possible to determine a lot of
information about the owners of addresses just from the transaction history. Moreover, anybody
engaging in a bitcoin transaction with you can know your entire transaction history. There are two
primary reasons why this is problematic:
• Privacy. Users in the bitcoin network may not want their spending habits and account
balances available to anybody with whom they transact.
• Fungibility. Every bitcoin has an associated history. This can make some bitcoins worth
less than others: for example, bitcoins which were used for criminal activity might be seen
as ‘dirty’ and worth less than ‘clean’ bitcoins. This is an issue because we would like every
bitcoin to have the same value, as with any currency.
3
3.1 Mixnets
One approach to privacy for Bitcoin is the ‘mixnet’. This is a pool of users who shuffle transactions
among themselves in order to hide, to some extent, the source and destination of each individual
transaction. There are multiple problems with this scheme. The first is that it requires some
trust in the mix operator: it is possible for the mix to trace or even steal bitcoins. This can
be somewhat mitigated by chaining multiple independent mixes. Mixnets are still susceptible to
statistical inference attacks, and do not achieve fungibility; indeed, it may be that you receive a
bitcoin out of a mixnet which is less valuable than the one you put in.
3.2 Zerocash
Zerocash aims to solve the privacy problem in a provable way. The scheme uses succinct zero
knowledge proofs (zk-SNARKs) to guarantee both privacy and integrity simultaneously. We describe
a very simplified version of the protocol. To create a coin, the user generates a random serial number
s and a trapdoor r, and computes a commitment cr (s) to s. He then sends a ‘mint transaction’ to
the blockchain, containing cr (s) (but not s or r). The mint transaction will be processed only if
the user pays, say, one bitcoin to some escrow service (which is verified by the miner). The value of
zerocoins is thus dependent on Bitcoin.
To spend a coin, the user sends the serial number s of the coin to the blockchain, along with
a zero knowledge proof of the assertion “I know r such that cr (s) is on the blockchain”. The
spend transaction succeeds if s was not part of any previous spend transaction (preventing double
spending). If the spend succeeds, then the user is paid one bitcoin by the escrow service. Observe
that because s is private when the coin is minted, and cr (s) is private when the coin is spent (by
the zero knowledge guarantee), it is not possible to link the transaction which minted the coin to
the one which spent it.
This scheme only allows users to mint and spend single coin units, and does not demonstrate how
to transfer coins to other users. The Zerocash protocol provides a ‘pour’ operation, which allows
coins to have variable denominations, and ensures that once a coin is transferred from one user to
another, the sender cannot spend the coin. The details of this operation are beyond the scope of
this summary.