## Smart Contracts
<br>
###### [Orange County ACM Chapter](https://www.meetup.com/acm-oc/events/287648578/), Sep 21, 2022
<br>
###### Alexander Kurz
###### Chapman University
<br>
<center><font size="+0">view online at </font></font><font size="+1" color=blue>http://tiny.cc/qibzuz</font></center>
<center><font size="+0" color=grey>(layout optimized for Brave browser)</font></center>
---
<style type="text/css">
.reveal p {
text-align: left;
}
.reveal ul {
display: block;
}
.reveal ol {
display: block;
}
.reveal {
font-size: 36px;
}
</style>
## Overview
<br>
***Why*** are smart contracts interesting?
***How*** to write and use smart contracts?
***What*** is a smart contract?
***Where*** do we go with this technology?
Note:
My background is in applications of logic and category theory to software engineering. This has some relevance on question 2. But what actually interest me most is question 4.
---
## ***Why*** are Smart Contracts Interesting?
---
*New Technologies:*
Cryptocurruencies
Smart Contracts
<br>
*Media Attention:*
New Applications
Scams, Heists, Fraud and Crime
SciFi Becoming Real
Note:
There are many new and exciting technologies that do not get much media attention (precision fermentation, graphene, radiative cooling, ...). But "Crypto" is different and for the remainder of the intro I want to explore a little why.
First, of course, the range of potentially disruptive new application. (But other technology has this to.)
Second, even if you are in only for entertainment, there are some real gems waiting for you, in particular in the area of true crime.
Third, scifi ...
(Btw, the attention media pays to "crypto" is only rivalled by AI/machine learning and we can see the similarities. Note that while media always like scare stories, they are interestingly different (AI: Robots taking over, Crypto: True Crime))
---
### New Technologies
<br>
Cryptocurrencies: [prehistory](https://www.youtube.com/watch?v=wokvO1ptE1k), [Bitcoin](https://nakamotoinstitute.org), [2011](https://www.gwern.net/Bitcoin-is-Worse-is-Better), [academic](https://dl.acm.org/doi/pdf/10.1145/3132259?download=true), [critical](https://blog.dshr.org/2022/02/ee380-talk.html), [satire](https://vitalik.ca/general/2022/04/01/maximalist.html) ... [Silk Road](http://www.americankingpin.com/) ...
<br>
Smart contracts: [Szabo](https://firstmonday.org/ojs/index.php/fm/article/view/548/469), [Ethereum](https://ethereum.org/en/whitepaper/), [Ethereum Virtual Machine (EVM)](https://github.com/ethereum/yellowpaper) ... [law as code](https://lessig.org/product/code/) ...
Note:
the history of bitcoin is more interesting than the history of ethereum but the technology of smart contracts is more interesting than the technology of cryptocurrencies ... but Lessig's book is a very interesting history of the early internet as well as of the interplay between law and code
---
#### Media Attention
<br>
I link below examples from the media.
How to separate the hype from the serious?
We can come back to this after the *How* and the *What*.
---
#### New Applications
<br>
[Distributed Autonomous Organisations (DAOs)](https://www.forbes.com/sites/laurashin/2022/02/22/exclusive-austrian-programmer-and-ex-crypto-ceo-likely-stole-11-billion-of-ether/?sh=4983aca7f589) ... [NFTs](https://www.youtube.com/watch?v=YQ_xWvX1n9g) ... [Metaverse](https://www.nytimes.com/2021/07/10/style/metaverse-virtual-worlds.html) ... [Facebook is Meta](https://www.nytimes.com/2021/10/29/technology/meta-facebook-zuckerberg.html) ... [Computer Games](https://medium.com/@jradoff) ... [Web3](https://www.nytimes.com/2021/12/05/business/dealbook/what-is-web3.html) ... [Fintech](https://www.nytimes.com/2022/01/20/nyregion/eric-adams-bitcoin-cryptocurrency.html) ... [DeFi](https://www.coinbase.com/learn/crypto-basics/what-is-defi) ... [Transparent Supply Chains](https://www.forbes.com/sites/leannekemp/2022/02/27/how-smart-contracts-trigger-swift-action-to-take-russian-goods-off-the-market/) ...
<br>
---
#### Scams, Heists, Fraud and Crime
[Beanstalk cryptocurrency robbed after hacker votes to send themself $182 million](https://www.theverge.com/2022/4/18/23030754/beanstalk-cryptocurrency-hack-182-million-dao-voting), 2022. Exploiting flashloans.
[Poly Network Hack Analysis](https://mudit.blog/poly-network-largest-crypto-hack/), 2021. Exploiting bridges.
[Escaping the Dark Forest](https://samczsun.com/escaping-the-dark-forest/) ... [Ethereum is a Dark Forest](https://www.paradigm.xyz/2020/08/ethereum-is-a-dark-forest), 2020. Can involuntary transactions be rescued?
More at the [Molly White List](https://web3isgoinggreat.com/?theme=hack)
<br>
[Sex, Drugs, and Bitcoin: How Much Illegal Activity is Financed through Cryptocurrencies?](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3102645) "around $76 billion of illegal activity per year involves bitcoin (46% of bitcoin transactions)"
---
#### SciFi Becoming Real
<br>
<font color=grey> I planned this slide, but then realized that I know too little about the history of either crypto or scifi. There is an interesting story hidden. A starting point would be the [mailing list of the Cypherpunk movement](https://mailing-list-archive.cryptoanarchy.wiki/) of the 90s (which named itself with reference to cyberpunk scifi).
</font>
Note:
Similary to Ai, crypto and scifi share a history. But even more than with AI, one gets a sense that scifi was a driving force. We all remember the optimism generated by the early internet in the 1990s (free and open knowledge, democratization of society, etc).
---
## ***How*** to write and use smart contracts?
---
Example: Players guess a number and bet. Winner gets all.
<br>
```solidity
contract PayAndGuess {
address payable[] public betters; //list of players
mapping(address => uint) public bets; //bet of player
mapping(address => uint) public guesses; //guess of player
function bet(uint guess) public payable {
betters.push(payable(msg.sender)); //add new player
bets[msg.sender] = msg.value; //record their bet
guesses[msg.sender] = guess; //record their guess
}
function disburse() public {
address payable winner;
uint winAmount;
... //calculate winner
winner.transfer(winAmount); //pay winner
}
}
```
<br>
[The full contract on Etherscan](https://ropsten.etherscan.io/address/0xd0a09debec0ff0a0d259402a819c48a7e8d19acc#code) (credit: Christopher Chang).
---
**Example Scenario:** Crowdfunding Software Development
<br>
Developers set rules of funding scheme in a smart contract.
If enough funds come in, project starts.
Pays a salary to the developers.
Funders get to vote on rising salaries or ending the project.
<br>
Source: [vbuterin - Explanation of DAICOs](https://ethresear.ch/t/explanation-of-daicos/465)
---
## ***What*** is a smart contract?
---
A smart contract is ...
a program on a "distributed computer" such as the EVM ...
"running on" distributed consensus.
<br>
What is distributed consensus?
---
#### Distributed Consensus
<br>
Remark on Terminology:
distributed vs decentralized (?)
fail-stop vs Byzantine fault tolerance
Note:
terminology varies, examples:
distributed includes client server
decentralized restricts to P2P
sometimes: decentralized = fully distributed
---
#### Distributed Consensus (cont'd)
<br>
I will explain proof-of-work-consensus with the help of the following picture:
![](https://hackmd.io/_uploads/HJHzXGuZj.png)
(image credit [Satoshi Nakamoto Institute](https://nakamotoinstitute.org))
---
## ***Where*** to go?
---
What can be decentralized?
*Example:* social media.
What service do centralized platforms perform?
Are decentralized social media more democratic?
<br>
[Mastodon](https://en.wikipedia.org/wiki/Mastodon_(software)) [[1]](https://www.youtube.com/watch?v=IPSbNdBmWKE&t=1s) [[2]](https://www.youtube.com/watch?v=yZoASOyfvGQ), [Center for Humane Technology](https://www.humanetech.com/technologists), [Buterin on Decentralization](https://www.google.com/search?q=https%3A%2F%2Fvitalik.ca%2F+%22decentralization%22), ...
---
Reliable and maintainable smart contracts?
Smart contracts and democracy?
How to account for renegotiation of contracts?
Robustness? Bankruptcy?
Governance?
<br>
[Metagov](https://metagov.org/), [Bell on Digital Autonomous Authoritarians](https://www.elgaronline.com/view/edcoll/9781839100789/9781839100789.00011.xml), [Buterin on Governance](https://www.google.com/search?q=https%3A%2F%2Fvitalik.ca%2F+%22governance%22), ...
---
Is P2P software inherently open source?
How to finance and maintain open source software?
How to finance public goods?
<br>
[Tabarrok](https://mason.gmu.edu/~atabarro/PrivateProvision.pdf) [[1]](https://foresight.org/summary/dominant-assurance-contracts-alex-tabarrok-george-mason-university/) [[2]](https://programtheblockchain.com/posts/2018/05/01/writing-a-dominant-assurance-contract/), [Buterin on Public Goods](https://www.google.com/search?q=https%3A%2F%2Fvitalik.ca%2F+%22public+goods%22&)
---
How to make off-chain events available on-chain?
How to build and quantify reputation and trust?
Principles of distributed organizations?
Which laws should govern the web3?
Cryptocurrencies and money laundering?
Anonymity and data privacy vs openness and trust?
Smart contracts and constraints vs incentives?
---
## References
---
#### Smart Contracts
<br>
[Search the book](https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fcypherpunks-core.github.io%2Fethereumbook%2F+%22smart+contract%22&sxsrf=ALiCzsae8SMs5nL3MeBKzPJxwLl-XDy6xA%3A1663772802254&ei=gigrY8yWD-vekPIPvoWUqAE&ved=0ahUKEwjM3_XWlKb6AhVrL0QIHb4CBRUQ4dUDCA4&uact=5&oq=site%3Ahttps%3A%2F%2Fcypherpunks-core.github.io%2Fethereumbook%2F+%22smart+contract%22&gs_lcp=Cgdnd3Mtd2l6EANKBAhBGAFKBAhGGABQyhFYsCRguitoAnAAeACAAdYBiAGdCpIBBjEzLjAuMZgBAKABAcABAQ&sclient=gws-wiz) *Mastering Ethereum*.
---
#### Authorities vs the Public, Hierarchies vs Networks
<br>
Martin Gurri. The Revolt of The Public and the Crisis of Authority in the New Millennium (2014/2018)
Wael Ghonim. The Revolution 2.0: The Power of the People Is Greater Than the People in Power (2012)
---
#### Psychology and Evolution of Human Cooperation
<br>
Joseph Henrich. The WEIRDest People in the World (2020)
Bart Wilson. The Property Species (2020)
Michael Tomasello. Becoming Human (2019)
Mercier and Sperber. The Enigma of Reason (2019)
Richard Wrangham. The Goodness Paradox (2019)
Kim Sterelny. The Evolved Apprentice (2012)
Jonathan Haidt. The Righteous Mind (2012)
---
## Acknowledgements
<br>
*Students:* Luke Burns, Christopher Chang, Kevin Jeon, Ronan Kearns, Tyler Lewis, Sri Pranav, Subhash Prasad, Jun Yoon
<br>
*Colleagues:* Andrea Bracciali, Mohammad Hammoudeh, Gabriele Camera, David Rojo Arjona, Tom Bell, Seth Benzell
---
## Concluding Quote
<br>
"In the end, computers plus networks plus people add up to something significantly greater than the parts. The ensemble eventually grows beyond human creativity. To become what? We can't know until we get there."
<br>
Vernor Vinge, [The creativity machine](https://rdcu.be/cV2YK), 2006.
<!--
## Random Links
![](https://hackmd.io/_uploads/Hy14gILbi.png)
(image from [Proof of Work based blockchain consensus](https://medium.com/@drstone/an-overview-of-proof-of-work-based-blockchain-consensus-protocols-part-1-e04102885093))
-->
{"metaMigratedAt":"2023-06-17T06:15:32.756Z","metaMigratedFrom":"YAML","title":"Smart Contracts (Slides)","breaks":true,"slideOptions":"{\"theme\":\"white\",\"transition\":\"fade\",\"transitionSpeed\":\"slow\",\"spotlight\":{\"enabled\":false},\"allottedMinutes\":2,\"controls\":false}","contributors":"[{\"id\":\"d215bc36-9464-43c8-81b4-4d58ae2c492a\",\"add\":21802,\"del\":20499}]"}