Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Programming Languages x Blockchains
Search
Volodymyr Kyrylov
April 25, 2018
Technology
1
220
Programming Languages x Blockchains
Are you sure you still want smart contracts? Presented on iForum 2018
Volodymyr Kyrylov
April 25, 2018
Tweet
Share
More Decks by Volodymyr Kyrylov
See All by Volodymyr Kyrylov
Ur/Web: lightning fast prototyping for the web
proger
0
240
Swift to Haskell: Overloading Semicolons
proger
2
200
The Programming Language of Mathematics
proger
3
650
Stochastic Relaxation, Gibbs Distributions, and the Bayesian Restoration of Images
proger
0
900
Monosyn - monocular navigation for robots
proger
0
110
Lambda the Ultimate Devops v2
proger
1
450
Lambda the Ultimate Devops
proger
0
260
Haskell >>= DevOps
proger
0
820
The Zalora Platform
proger
2
830
Other Decks in Technology
See All in Technology
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
850
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
490
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
190
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
570
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
190
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
290
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
110
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
270
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
140
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Bash Introduction
62gerente
608
210k
Making the Leap to Tech Lead
cromwellryan
133
9k
A designer walks into a library…
pauljervisheath
204
24k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
A Tale of Four Properties
chriscoyier
157
23k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Designing Experiences People Love
moore
138
23k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Transcript
Programming Languages × Blockchains Vlad Ki ESM.one
Mainstream PLs won't work
None
DApps in 2013
None
None
None
None
None
DApps in 2018
None
function createGen0Auction(uint256 _genes) public onlyCOO { require(gen0CreatedCount < gen0CreationLimit); uint256
kittyId = _createKitty(0, 0, 0, _genes, address(this)); _approve(kittyId, saleAuction); saleAuction.createAuction(kittyId, _computeNextGen0Price(), 0, gen0AuctionDuration, address(this)); gen0CreatedCount++; } function _computeNextGen0Price() internal view returns (uint256) { uint256 avePrice = saleAuction.averageGen0SalePrice(); require(avePrice < 340282366920938463463374607431768211455); uint256 nextPrice = avePrice + (avePrice / 2); if (nextPrice < gen0StartingPrice) { nextPrice = gen0StartingPrice; } return nextPrice; }
#!/bin/bash while { echo -ne "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n<html>lol</ html>\r\n";
} \ | nc -l 80 do : done
WTF?!
Developers are losing abstractions!
ACID Atomic Consistent Isolated Durable
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; UPDATE accounts SET balance =
balance + 100 WHERE addr = 0x4206f95fc533483; UPDATE accounts SET balance = balance - 100 WHERE addr = 0x083c41ea13af6c2; COMMIT;
SELECT address FROM accounts ORDER BY random() LIMIT 1;
CREATE SEQUENCE txn; BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE; INSERT INTO
tx VALUES (nextval('txn'), current_timestamp); INSERT INTO tx VALUES (nextval('txn'), current_timestamp); COMMIT;
BASE Basically Available Soft State Eventually Consistent
http:/ /docs.basho.com/riak/kv/2.2.3/learn/concepts/clusters/
$ curl http://riak/buckets/chain/keys/0x4206f95fc533483 < HTTP/1.1 300 Multiple Choices < X-Riak-Vclock:
a85hYGDgyGDKBVIszMk55zKYEhnzWBlKIniO8kGF2TyvHYIKf0cIszUnMTBz HYVKbIhEUl+VK4spDFTPxhHzFyqhEoVQz7wkSAGLMGuz6FSocFIUijE3pt5H lsgCAA== < Content-Type: multipart/mixed; boundary=lol --lol Content-Type: application/json Link: </buckets/chain>; rel="up" Etag: 16vic4eU9ny46o4KPiDz1f Last-Modified: Wed, 10 Mar 2010 18:01:06 GMT 100 --lol Content-Type: application/json Link: </buckets/chain>; rel="up" Etag: 4v5xOg4bVwUYZdMkqf0d6I Last-Modified: Wed, 10 Mar 2010 18:00:04 GMT 200
Logical Clocks https:/ /cacm.acm.org/magazines/2016/4/200168-why-logical-clocks-are-easy/abstract
https:/ /hal.inria.fr/file/index/docid/555588/filename/techreport.pdf
Definition counter : Type := nat * nat. Definition zero
:= (O, O). Definition succ (c : counter) := match c with (p, n) => (p + 1, n) end. Definition pred (c : counter) := match c with (p, n) => (p, n + 1) end.
$ curl -XPOST http://riak/types/counters/buckets/ chain/datatypes/0x4206f95fc533483 \ -d '{"increment": 100}' $
curl -XPOST http://riak/types/counters/buckets/ chain/datatypes/0x4206f95fc533483 \ -d '{"decrement": 50}' $ curl http://riak/types/counters/buckets/chain/ datatypes/0x4206f95fc533483 {"type":"counter", "value": 100}
В риаке конфликты на чтение Пиши в блокчейн! А зачем?
Глобальный консенсус! Так языка запросов даже нет! Ты чё, пёс, это же крипта!
UTXO Unconvincing Transaction Outcome
Smart Contracts Smart contracts help you exchange money, property, shares,
or anything of value in a transparent, conflict-free way while avoiding the services of a middleman.
european :: Date -> Contract -> Contract european t u
= at t (u `or` zero)
None
Smart Contracts Smart contracts are executable programs run on top
of an immutable distributed database whose inputs and outputs are maintained globally consistent by a distributed consensus protocol.
pragma solidity ^0.4.0; contract SimpleStorage { uint storedData; function set(uint
x) public { storedData = x; } function get() public constant returns (uint) { return storedData; } }
function createGen0Auction(uint256 _genes) public onlyCOO { require(gen0CreatedCount < gen0CreationLimit); uint256
kittyId = _createKitty(0, 0, 0, _genes, address(this)); _approve(kittyId, saleAuction); saleAuction.createAuction(kittyId, _computeNextGen0Price(), 0, gen0AuctionDuration, address(this)); gen0CreatedCount++; } function _computeNextGen0Price() internal view returns (uint256) { uint256 avePrice = saleAuction.averageGen0SalePrice(); require(avePrice < 340282366920938463463374607431768211455); uint256 nextPrice = avePrice + (avePrice / 2); if (nextPrice < gen0StartingPrice) { nextPrice = gen0StartingPrice; } return nextPrice; }
None
web3.eth.getTransaction('0x9fc76417374aa880d4449a1f7f31ec5 97f00b1f6f3dd2d66f4c9c6c445836d8b§234') .then(console.log); > { "hash": "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c 445836d8b", "nonce": 2,
"blockHash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e 133e34b46", "blockNumber": 3, "transactionIndex": 0, "from": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", "value": '123450000000000000', "gas": 314159, "gasPrice": '2000000000000', "input": "0x57cb2fc4" }
Why?
None
None
ERC20 allowance contract ERC20 is ERC20Basic { function transferFrom(address from,
address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); } https:/ /docs.google.com/document/d/ 1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit https:/ /github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
None
None
Ensure Properties!
None
Coq Dependent Type Theory Tactics Extraction to OCaml and Haskell
Formalization of mathematics
Theorem pred_and_succ_covariant: forall c: counter, pred (succ c) = succ
(pred c). intros c. induction c. compute. reflexivity. Qed.
None
None
pragma solidity ^0.4.0; contract Fund { mapping(address => uint) shares;
function withdraw() public { if (msg.sender.call.value(shares[msg.sender])()) shares[msg.sender] = 0; } }
The DAO https:/ /abhiroop.github.io/Exceptions-and-Transactions/
Interface State Machine Plutus Plutus Core Solidity EVM (stack) IELE
(register) Chain Bitcoin Script Ivy Vyper
None
None
Hardening Strategies Interfaces (*.h, *.mli) Interfaces + property claims (f
. g = g . f) Interfaces + property proofs Implementation property claims Implementation property proofs
Hardening Strategies End-to-end compilation Verify interfaces in Coq Use plutus
core/iele as compilation targets
Contracts as State Machines
None
Denotate to simple languages!
None
System F
Turing vs Church
Interface State Machine Plutus Plutus Core Solidity EVM (stack) IELE
(register) Chain Bitcoin Script Ivy Vyper
Interface State Machine Plutus Plutus Core Solidity EVM (stack) IELE
(register) Chain Bitcoin Script Ivy Vyper run . compile = meaning
Gotcha
gcd :: (Integral a) => a -> a -> a
gcd x y = gcd' (abs x) (abs y) where gcd' a 0 = a gcd' a b = gcd' b (a `rem` b)
Lemma euclid_rec : forall v3 : Z, (0 <= v3)%Z
-> forall u1 u2 u3 v1 v2 : Z, (u1 * a + u2 * b)%Z = u3 -> (v1 * a + v2 * b)%Z = v3 -> (forall d : Z, gcd u3 v3 d -> gcd a b d) -> Euclid. Proof. intros v3 Hv3; generalize Hv3; pattern v3 in |- *. apply Z_lt_rec. clear v3 Hv3; intros. elim (Z_zerop x); intro. apply Euclid_intro with (u := u1) (v := u2) (d := u3). assumption. apply H2. rewrite a0; auto. set (q := (u3 / x)%Z) in *. assert (Hq : (0 <= u3 - q * x < x)%Z). replace (u3 - q * x)%Z with (u3 mod x)%Z. apply Z_mod_lt; omega. assert (xpos : (x > 0)%Z). omega. generalize (Z_div_mod_eq u3 x xpos). unfold q in |- *. intro eq; pattern u3 at 2 in |- *; rewrite eq; ring. apply (H (u3 - q * x)%Z Hq (proj1 Hq) v1 v2 x (u1 - q * v1)%Z (u2 - q * v2)%Z). tauto. replace ((u1 - q * v1) * a + (u2 - q * v2) * b)%Z with (u1 * a + u2 * b - q * (v1 * a + v2 * b))%Z. rewrite H0; rewrite H1; trivial. ring. intros; apply H2. apply gcd_for_euclid with q; assumption. assumption. Qed.
twitter.com/kievfprog kievfprog.net
Haskell Rust Scala F# F* Ur Agda Idris Coq SML
OCaml QuickCheck SMT
None
Yay Formal Methods!
[email protected]