Skip to content

Commit 8ca631d

Browse files
author
sam bacha
authored
content(mit): blockchain expo
1 parent d26cbe7 commit 8ca631d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+9951
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: default
3+
has_children: true
4+
title: Mit Bitcoin Expo 2015
5+
---
6+
7+
{{< childpages >}}
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
---
2+
layout: default
3+
parent: Mit Bitcoin Expo 2015
4+
title: Andrew Miller
5+
nav_exclude: true
6+
transcript_by: Bryan Bishop
7+
---
8+
9+
{% if page.transcript_by %} <i>Transcript by:
10+
{{ page.transcript_by }}</i> {% endif %} Step by Step Towards Writing a
11+
Safe Contract: Insights from an Undergraduate Ethereum Lab
12+
13+
- Andrew Miller
14+
- Elaine Shi
15+
16+
Next up I want to introduce Elaine Shi and Andrew Miller from University
17+
of Maryland. Andrew is also on the zerocash team.
18+
19+
Okay. I am an assistant professor at the University of Maryland. We all
20+
believe that cryptocurrency is the way of the future and smart
21+
contracts. So students in the future have to program smart contracts.
22+
23+
So that's what I did. I asked some students to program some smart
24+
contracts. I am going to first give some quick background and then I
25+
will talk about the insights that we gained from this lab. Okay.
26+
27+
So I asked my students to work in groups of 4. This is the first time
28+
that this type of lab has been attempted. I asked one of my PhD students
29+
to advise each project group.
30+
31+
In the first phase we had the proposal phase where students developed an
32+
application of choice on top of Ethereum's programming language called
33+
serpent. As the lab went on, we realized that we needed a second phase,
34+
the amendment critique phase.
35+
36+
In the second phase, the instructors- Andrew Miller and myself, and the
37+
graduate TAs. We gave feedback about the applications they created. I
38+
asked the students to form groups and critique each other's
39+
applications.
40+
41+
Based on the feedback, the students amended their designs.
42+
43+
The outcome is that there is good news and bad news. The good news was
44+
that this was an aspiring experience. Both the students and the
45+
instructors learned tremendously throughout the process. Some students
46+
said they really enjoyed learning about cryptocurrency. All project
47+
groups did a really impressive job.
48+
49+
The bad news is that some students didn't enjoy the premature nature of
50+
Ethereum's language. This language is in development. It's poorly
51+
documented and some groups had difficulty setting things up and getting
52+
their application to run on top of this language.
53+
54+
The students created many interesting applications like games where
55+
players play for money, like RPS, Russian roulette, and so on. Escrow
56+
services. Auctions. One group created a parking meter application. Some
57+
groups created stock market applications.
58+
59+
Okay. So what are the lessons learned? At the end of phase 1, we
60+
actually realized that many groups programmed contracts which had
61+
problems with them. They were insecure. And essentially as weak now,
62+
security is difficult. When you write a traditional program, we know all
63+
the ways you can mess up. Here we are programming smart contracts, it
64+
turns out there are new ways to mess up and create bad contracts. Okay.
65+
66+
So as we all know, smart contracts have high value transaction values.
67+
So the security is important. If I am a user, I want to know that my
68+
money will be protected if I send money to the contract. Let me give you
69+
some examples. Partly the purpose of this is to walk through step by
70+
step about how to create a safe cryptocurrency contract.
71+
72+
Before I do that, let's first try to have a very quick overview of the
73+
programming model of Ethereum. Okay. In Ethereum, there's a key concept
74+
called a contract. And the contract would interact with different users.
75+
So the contract can both have both storage and program logic. Okay. A
76+
contract can store messages and money. It has some Turing complete
77+
program logic it can execute. In Ethereum, the idea is that the data of
78+
the contract is going to be stored on the public blockchain. And the
79+
program logic of the contract is going to be executed by all miners on
80+
the network. Okay. So assume the underlying cryptocurrency protocol
81+
maintains its security properties, then one way to think about the
82+
contract is to think of a trusted third party without privacy. Okay, so
83+
is it trusted? It is because, assume the entire network reaches
84+
consensus, and assume that you assume the protocol is secure such that
85+
the majority of the miners will execute an honest reference client. Why
86+
is there no privacy? Well, everything is public and the whole blockchain
87+
is public and all messages are public. Okay.
88+
89+
So the contract would interact with the users and the users can send and
90+
receive money to and from the contract and they can send and receive
91+
messages from the contract. Okay. So I am going to use a rock paper
92+
scissors example to show some mistakes.
93+
94+
So here is how you would write a RPS contract. There are three entry
95+
points to the contract. At player, input and winner. Let's imagine a two
96+
person contract. "At player" would register and then send money to the
97+
contract. So the contract would store their money and their identity.
98+
That's the first step. The second step of the game is a function called
99+
input. This is where the players, the players need to choose something
100+
to play, so I choose paper, so I choose scissors, this is where players
101+
send inputs to the contract. The contract will store their inputs. In
102+
the final step, the contract will decide the winner and send all the
103+
money to the winner. That's a high-level overview.
104+
105+
For instance, here's a typical at player function that students wrote.
106+
If you look at the function a little more carefully, it's very simple.
107+
Self dot storage is the contract storage and when the contract receives
108+
the message it will basically first see whether the amount of money
109+
associated with the transaction is bigger than 1000 ethers. Then it will
110+
see if player 1 has been created. If not, the contract would record
111+
player1's identity and then it would store the money on to the contract
112+
which is the storage winnings equal to .. plus message value...
113+
Similarly, when player two enters. So I hope it is clear what this
114+
function does.
115+
116+
What's the problem with this function? Does anyone see the problem? If
117+
you look at this a little more carefully you will realize that what if a
118+
third player tries to join the contract. What if I make a mistake where
119+
I send less than 1000 ethers? The contract eats the money. So if you are
120+
the user and you are dealing with this contract, you would have to be
121+
very carefully. You do not want to be the third player to send money.
122+
There can be someone concurrently attempting to send money in the same
123+
epic. The users are unprotected.
124+
125+
So here's a second type of mistake. The input function where players
126+
send their choices. Here the program is very simple. It looks at whether
127+
this is player1 or player2 and then it records the player's choice.
128+
What's wrong with this? Okay, if you think about it a little more
129+
carefully, it will become immediate that the problem here is that the
130+
players are sending their choices in cleartext to the contract. So the
131+
messages are sent in the clear and the player's choice is stored in
132+
plaintext in the contract. So if I am a player, what makes sense for me
133+
is to wait for the other player to send their input, and then for me to
134+
decide what I should send. So that's broken.
135+
136+
How do you fix this? There's a simple technique where you make a
137+
commitment. You make a commitment, it is cryptographically hiding, then
138+
in the second part you would open your commitment. That's what you want
139+
to do.
140+
141+
Suppose you do the right thing and use a cryptographic commitment. There
142+
are still ways you can mess up. Imagine that the players have sent their
143+
committed inputs to the contract. In a later phase they would open their
144+
commitment. This function is where they open their commitment. The
145+
detailed code is not too important. What is the problem here? Okay, so
146+
here is another problem. Essentially let's say you and I are playing the
147+
game, you open the commitment and I see that I am losing. At this moment
148+
I have no incentive to open my commitment. It becomes stuck in the
149+
contract. If you are the winner then you wont get the winnings. So
150+
that's pretty bad.
151+
152+
So this brings us to the third class of mistakes which is incentive
153+
compatibility. You want to create contracts that are incentive
154+
compatible. You can introduce a deposit structure to the contract where
155+
you require players to deposit money to play, and then if they don't
156+
open their commitments within a certain amount of time then their
157+
deposit will be sent to the other player.
158+
159+
This was an interesting experience, we went back and forth to get the
160+
students to fix their contracts. What's coming up soon is that we are
161+
going to release some online course material for programming smart
162+
contracts. I have hired my undergrad students back to create a detailed
163+
manual to write the instructions. We will setup a VM where we are
164+
running pyethereum and we will have this step by step lab where we coach
165+
students how to create these smart contracts and what kind of mistakes
166+
to avoid. So if you are a professor and you want to do a lab like this,
167+
then check our online course material and use the virtual machine we
168+
have setup.
169+
170+
In this course material we will have some other more.. which I am not
171+
going to cover here.. they are related to the specifics to the ethereum
172+
or serpent language.
173+
174+
Andrew will now give a quick announcement. Hi everyone, thanks. I have
175+
no particular, where are my other slides. Thank you. I want to give you,
176+
I have no transition for this, I want to give a short update on another
177+
project. This is one of my pet research projects. Kicking around
178+
since 2013.
179+
180+
This is just a short announcement. Non-outsourceable mining puzzles. The
181+
motivation here is that everyone knows that Bitcoin's value is
182+
decentralization. And we aren't quite getting the decentralization we
183+
want. There are extremely influential mining pools. There are some large
184+
industrial miners. They sell shares of mining power to other people that
185+
may have been Bitcoin mining on their own but instead they are hiring
186+
some central organization to do their mining for them. So I wanted to
187+
investigate if it was possible to have a technical disincentive against
188+
this, so a technical measure to prevent this and restore Bitcoin to a
189+
more decentralized ideal.
190+
191+
The observation that makes this work is that the reason why pools are
192+
able to exist in the first place is that the members don't have to trust
193+
each other. There's a protocol where you send shares. The goal of this
194+
research is to propose a new puzzle that prevents that protocol to work.
195+
Whoever does the block and finds the solution, they have to have a
196+
private key to take the reward for them. To do the work you have to have
197+
a private key and you can take that reward if you have it. We have a
198+
stronger version where you can take the reward and you can avoid getting
199+
caught or punished. How does that work? Uses magic cryptography using
200+
zero knowledge snarks. Someone else will give an intro to zkSnarks
201+
later. There's this technical way to steal the puzzle solution for
202+
yourself if you find it. This is an implementation of this, it's new, it
203+
takes only 14 seconds to create one of these puzzle stealing proofs
204+
using the libsnarks library. It would take about $40 of ec2 time.
205+
206+
I got a lot of great feedback. There are some conflicting challenges to
207+
integrate this. Mining pools going away, mining solo is hard unless you
208+
have lots of hashpower or hashrate. There has been some work recently on
209+
the GHOST protocol and other proposals for getting the time between
210+
blocks down really fast, so maybe we can include that. Hosted mining has
211+
other things they can do, like getting you this much money every week so
212+
that there's no way to hide it, and they could use the same shares
213+
protocol to prove how well they are doing. You want to have fast low
214+
value blocks to prevent hosted mining from absorbing the risk
215+
themselves. So we have put together a different incentive scheme like
216+
State lotteries. Every time you make an attempt at a puzzle, you have a
217+
chance at a low value prize or a high value prize. The low value prize
218+
is for variance, and high value is so that big centralization wont be
219+
able to take money, and to prevent someone from skimming from the top.
220+
221+
This is compatible with existing Bitcoin mining equipment. We give a
222+
transformation for the non-outsourceable puzzle variant. You can make a
223+
non-outsourceable version of an ASIC resistant puzzle. This is all in
224+
the new version of the paper if you just search for the word
225+
non-outsourceable you will find it, that's all, thank you.
226+
227+
Q: Can we use automated techniques for testing to detect these bugs?
228+
229+
A: You asked the right question. That's our new research program. I
230+
would be happy to talk more about that offline.
231+
232+
Q: Hi, so, when I looked at the initial presentation, I was reminded in
233+
the legal system, if you don't commit, if you don't answer a claim you
234+
default and you also lose. It looked a little static. If people noticed
235+
the flaw, they could play along for low stakes, and then wait until the
236+
stakes get big. Have you done dynamic iterations of these experiments?
237+
238+
A: So far we have run this lab once. We definitely want to repeat it.
239+
That's why we are also creating this online course material.
240+
241+
Q: So if you noticed a flaw and it was in a dynamic situation, you might
242+
withhold the fact that you noticed the flaw and then play along for a
243+
while. And then ponzi schemers put up small returns, but when the money
244+
gets big they walk away. There seems to be a game play element.
245+
246+
A: We did not see concrete instances of this. Cases of this like would
247+
be very interesting to us. I think this proves that programming smart
248+
contracts is very tricky. There are all of these things you have to get
249+
right, these things don't exist in traditional programming. This can be
250+
an interesting place where disciplines cross each other. You can have
251+
game theory, incentives, mechanism design meets programming language
252+
research. It would be very interesting to try to design tools to get
253+
programmers to do this right.

0 commit comments

Comments
 (0)