diff --git a/cpwro2023/.gitignore b/cpwro2023/.gitignore new file mode 100644 index 0000000..155156a --- /dev/null +++ b/cpwro2023/.gitignore @@ -0,0 +1,10 @@ +# Draw.io temporary files +.$*.drawio.bkp +.$*.drawio.dtmp + +# Auto-generated word clouds +/zk-languages-wordcloud.png +/other-blockchain-languages-wordcloud.png + +# Build directory +/build/ diff --git a/cpwro2023/README.md b/cpwro2023/README.md new file mode 100644 index 0000000..a756a7a --- /dev/null +++ b/cpwro2023/README.md @@ -0,0 +1,28 @@ +# Code Poets Blockchain Meetup, Wrocław 2023 +[Event at meetup.com](https://www.meetup.com/wroclaw-blockchain-meetup/events/292148616/). + +Topic: **Smart Contract languages of the EVM: What else is there besides Solidity?** + +Description: Solidity is the most popular smart contract language today, but is it your only choice? +What else is there? +Are you missing out on important features? +The talk walks you through the evolution of smart contract languages built on top of the EVM, +showing off their strengths and weaknesses, contrasting them with Solidity as we know it today. +From the early implementations, through esoteric experiments to the select few languages that +eventually came out on top. Which one should you use for your next project? + +## Content +- [Presentation slides](slides.md) +- [Presentation notes](notes.md) + +## Building the presentation +```bash +./build.sh --static build/ +``` + +## Viewing the presentation +```bash +./build.sh --watch +``` + +Go to http://localhost:1948 diff --git a/cpwro2023/build.sh b/cpwro2023/build.sh new file mode 100755 index 0000000..eaceaf9 --- /dev/null +++ b/cpwro2023/build.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Generate wordcloud images. +# This requires python-wordcloud. +wordcloud_cli \ + --width 800 \ + --height 500 \ + --background white \ + --random_state 42 \ + --text other-blockchain-languages.txt \ + --imagefile other-blockchain-languages-wordcloud.png +wordcloud_cli \ + --width 800 \ + --height 500 \ + --background white \ + --random_state 42 \ + --text zk-languages.txt \ + --imagefile zk-languages-wordcloud.png + +# This assumes https://github.com/webpro/reveal-md is installed globally. +reveal-md \ + slides.md \ + --title "Smart Contract languages of the EVM: What else is there besides Solidity?" \ + --css style.css \ + --theme white \ + "$@" diff --git a/cpwro2023/experimental-timeline.drawio b/cpwro2023/experimental-timeline.drawio new file mode 100644 index 0000000..2fe5412 --- /dev/null +++ b/cpwro2023/experimental-timeline.drawio @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpwro2023/experimental-timeline.svg b/cpwro2023/experimental-timeline.svg new file mode 100644 index 0000000..9696747 --- /dev/null +++ b/cpwro2023/experimental-timeline.svg @@ -0,0 +1,3 @@ + + +
Flint 2
Flint 2
Pyramid Scheme
Pyramid Scheme
HAssembly
evm
HAssembly...
2014
2014
2015
2015
2016
2016
2017
2017
2018
2018
2019
2019
2020
2020
2021
2021
2022
2022
2023
2023
Mutan
Mutan
Bamboo
Bamboo
Flint
Flint
Logikon
Lo...
Lira
Lira
Text is not SVG - cannot display
\ No newline at end of file diff --git a/cpwro2023/ir-assembly-timeline.drawio b/cpwro2023/ir-assembly-timeline.drawio new file mode 100644 index 0000000..a7c5e92 --- /dev/null +++ b/cpwro2023/ir-assembly-timeline.drawio @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpwro2023/ir-assembly-timeline.svg b/cpwro2023/ir-assembly-timeline.svg new file mode 100644 index 0000000..7c75c3c --- /dev/null +++ b/cpwro2023/ir-assembly-timeline.svg @@ -0,0 +1,3 @@ + + +
Yul
Yul
ETK assembly
ETK assembly
Huff
(JS)
Huff...
2014
2014
2015
2015
2016
2016
2017
2017
2018
2018
2019
2019
2020
2020
2021
2021
2022
2022
2023
2023
Solidity/LLL
Solidity/LLL
Vyper/LLL
Vyper/LLL
Vyper IR
Vyper IR
JULIA
JULIA
Yul+
Yul+
Sonatina
Sonatina
Huff (Rust)
Huff (Rust)
Text is not SVG - cannot display
\ No newline at end of file diff --git a/cpwro2023/mainstream-timeline.drawio b/cpwro2023/mainstream-timeline.drawio new file mode 100644 index 0000000..e60b629 --- /dev/null +++ b/cpwro2023/mainstream-timeline.drawio @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cpwro2023/mainstream-timeline.svg b/cpwro2023/mainstream-timeline.svg new file mode 100644 index 0000000..f33bd0a --- /dev/null +++ b/cpwro2023/mainstream-timeline.svg @@ -0,0 +1,3 @@ + + +
Vyper
Vyper
Fe
Fe
Sway
Sway
2014
2014
2015
2015
2016
2016
2017
2017
2018
2018
2019
2019
2020
2020
2021
2021
2022
2022
2023
2023
Sway
 on EVM?
Sway...
Rust
Vyper
Rust...
Viper
Viper
Solidity
Solidity
Serpent
Serpent
0.1
0.1
0.2
0.2
0.3
0.3
0.4
0.4
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.3
0.3
0.2
0.2
0.1
0.1
CLL
CLL
Text is not SVG - cannot display
\ No newline at end of file diff --git a/cpwro2023/notes.md b/cpwro2023/notes.md new file mode 100644 index 0000000..e7a7632 --- /dev/null +++ b/cpwro2023/notes.md @@ -0,0 +1,163 @@ +### Serpent +#### History +- Serpent or LLL first? + - First mention of CLL in January 2014 on EF blog. + - First LLL commits in Aleth in January 2014. +- Written in C++. + +#### Characteristics +- Low level compared to newer languages but has high-level features. + - I'd draw the line at EVM opcodes as a first-class language primitive. +- Ironically, the C-Like Language was actually Python-like. + +#### Highlights +- Hides stack manipulation. +- External functions means ABI. +- Its storage arrays are effectively mappings. +- Already a primitive memory allocation scheme. + +#### Drawbacks +- No types associated with variables. + - Has literals, e.g. strings, but size limited and in the end stored as 256-bit numbers. + - Any operation can be performed on any variable. +- No dynamic structures in memory means also no unlimited size strings. +- Without external functions calls are expensive. + - But gas used to be much less of an issue. +- No internal functions and no imports means lots of code in a single function. +- Security: + - OpenZeppelin audit in July 2017. + - Findings: low quality code, untested, little documentation, flawed design. + +### Solidity +#### History +- Started in October 2014. +- Originally part of Aleth, later extracted. +- Two alternative compilers exist: Solang and SOLL. +- Written in C++. + +#### Influences +- C++: declarations, loop/if syntax, overloading, conversions. +- JavaScript (initially): scoping and `var` keyword. + - Now just a few leftovers: `function` keyword, import syntax. +- Python: modifiers (decorators), inheritance, assignment semantics. + +#### Highlights +- More effective abstractions over low level concepts: + - OOP features: inheritance, enscapsulation, contracts are objects. + - Events: abstraction over logs. + - Syntax sugar: modifiers +- Inline assembly: escape hatch from abstractions for more control +- Dynamic memory allocation scheme addressing the need for dynamic types. +- Dynamic types also in storage. + +#### Drawbacks +- More features means more complexity. +- Complex abstractions require a good optimizer. + - Introduction of Yul to allow for more high-level optimizations. +- "Stack too deep" is a natural consequence of storing variables on the limited stack of the EVM. + +### Vyper +#### History +- Started in November 2016, renamed from Viper in December 2017. +- Written in Python. + +#### Highlights +- Inline assembly can be a hindrance to optimization and requires making assumptions. +- Despite limitations, the language is modern and comparable with Solidity. +- Lack of recursive calls helps keep static locations for variables. + - Lower cost of loading them on the stack. +- Vyper used to have only external calls to ensure static variable locations. +- Vyper added checked arithmetic in 2018. +- Some people just **really** like Python. + +#### Drawbacks +- In Solidity you can work around of lots of limitations with inline assembly. +- More memory waste in certain scenarios compared to Solidity due having to allocate the maximum size. + - Less memory waste in certain scenarios compared to Solidity due to no repeated allocations. + +### Fe +#### History +- Started in August 2019, renamed in September 2020. +- Current Fe team is a part of EF, replaced Vyper. +- Still at the alpha stage. +- Written in Rust. + +#### Highlights +- May get inline assembly in the form of `unsafe` blocks. +- Aims to have a rich standard library. +- Already has some limited generics. + +#### Drawbacks +- Due to compiling to Yul, is closer to Solidity's memory model than to Vyper's. + - May be seen as a downside when it comes to "Stack too deep" errors. + - But these problems are also being addressed at Yul level. + +### Sway +#### History +- Started in January 2021 at Fuel Labs. +- EVM backend is supposedly already under development as of March 2023. Not much is known about it. +- Writen in Rust. + +#### Highlights +- Scripts allow users to atomically call multiple contracts without deploying a contract. + +#### Drawbacks +- Rust was not designed from the ground up for environment as limited as EVM, which may and up being a hindrance. + +### LLL +#### History +- Probably the first language on the EVM. +- Started in January 2014. + - Written in C++. +- Vyper implementation in November 2016 by Vitalik Buterin. + - Written in Python. + - Used as IR for the Vyper compiler. +- Solidity/LLL removed from the Solidity repository in Solidity 0.6.2 (January 2020). + +### Yul +#### History +- First code appeared in Solidity 0.4.11. +- Renamed Yul in March 2018. +- JULIA = Joyfully Universal Language for (Inline) Assembly. +- Written in C++. +- Used as IR for the Solidity compiler. + +#### Drawbacks +- Extensive use of `switch` is due to`if`s not having `else` clauses. + +### Yul+ +#### History +- Started in January 2020 by Nick Dodson at Fuel Labs. +- Development stopped in February 2022. +- Written in Rust. + +## ETK assembly +#### History +- Started in February 2021. +- Written in Rust. + +### Huff +#### History +- Started in December 2019 at AZTEC Protocol. + +### Sonatina +#### History +- Started in September 2021. +- Written in Rust. + +# Experimental languages +- Many alternative approaches, ultimately abandoned. +- A lot of variety compared to mainstream languages. Diverse influences and paradigms. +- Mutan was an early language from the era of Serpent and LLL. + - Quickly deprecated (March 2015). +- Flint is one of the more developed experimental languages, addressing weaknesses in Solidity. + - Ultimately it's still an academic language with no production use, interesting mostly for its ideas. + - Targeting also Libra. + - Docker image with the compiler: + ```bash + docker pull cameel/flint-bionic + ``` +- Logikon was a short-lived experiment by Solidity developers in creating a Prolog-like language. +- Lira is substantially different that other languages here. + - DSL for expressing financial contracts. + - Aimed at users with a financial background rather than programmers. diff --git a/cpwro2023/other-blockchain-languages.txt b/cpwro2023/other-blockchain-languages.txt new file mode 100644 index 0000000..79a4548 --- /dev/null +++ b/cpwro2023/other-blockchain-languages.txt @@ -0,0 +1,13 @@ +Move +Plutus +Michelson +Cadence +Hoon +Obsidian +Move +Scrypto +Rholang +Sophia +Contractum +Juvix +Reach diff --git a/cpwro2023/pool-meme-evm-languages.webp b/cpwro2023/pool-meme-evm-languages.webp new file mode 100644 index 0000000..c8f417b Binary files /dev/null and b/cpwro2023/pool-meme-evm-languages.webp differ diff --git a/cpwro2023/programming-language-iceberg.jpg b/cpwro2023/programming-language-iceberg.jpg new file mode 100644 index 0000000..5f79d3b Binary files /dev/null and b/cpwro2023/programming-language-iceberg.jpg differ diff --git a/cpwro2023/reveal.json b/cpwro2023/reveal.json new file mode 100644 index 0000000..1fbb743 --- /dev/null +++ b/cpwro2023/reveal.json @@ -0,0 +1,9 @@ +{ + "controls": false, + "slideNumber": "c/t", + "transition": "slide", + "transitionSpeed": "fast", + "center": true, + "width": 1920, + "height": 1080 +} diff --git a/cpwro2023/slides.md b/cpwro2023/slides.md new file mode 100644 index 0000000..1708c94 --- /dev/null +++ b/cpwro2023/slides.md @@ -0,0 +1,1181 @@ +## Smart Contract languages of the EVM +### What else is there besides Solidity? +
+
+
+
+
+
+ +
+ +**Kamil Śliwak**
+Code Poets / co-founder
+Ethereum Foundation / Solidity compiler team + +
+ +---- + +#### EVM languages + +
+
+
+ +##### Expectation + +![programming-language-iceberg](programming-language-iceberg.jpg) + +
+
+ +
+
+ +#### Reality + +![pool-meme-evm-languages](pool-meme-evm-languages.webp) + +
+
+
+ +---- + +## EVM languages +- Mainstream languages +- IR/assembly languages +- Experimental languages + +--- + +## Mainstream languages +- Serpent +- Solidity +- Vyper +- Fe +- Sway + +---- + +
+
+ +# Serpent + +
+ +# Serpent +#### History +- 2014-2017 +- by Vitalik Buterin +- used in Ethereum whitepaper +- originally called CLL (C-Like Language) + +
+ +
+ +# Serpent +#### Characteristics +- relatively high-level +- procedural +- untyped +- pythonic + +
+
+ +# Serpent +#### Highlights +- variables, expressions, control structures +- external functions +- constructors +- dynamic structures in storage +- static memory arrays + +
+
+ +# Serpent +#### Drawbacks +- untyped variables +- no dynamic structures in memory +- no internal functions +- no imports +- unchecked arithmetic +- not much focus on security +- almost no documentation + +
+
+
+ +```python +def deposit(): + if not self.storage[msg.sender]: + self.storage[msg.sender] = 0 + self.storage[msg.sender] += msg.value + return(1) + +def withdraw(amount): + if self.storage[msg.sender] < amount: + return(-1) + else: + self.storage[msg.sender] -= amount + send(0, msg.sender, amount) + return(1) + +def transfer(amount, destination): + if self.storage[msg.sender] < amount: + return(-1) + else: + if not self.storage[destination]: + self.storage[destination] = 0 + self.storage[msg.sender] -= amount + self.storage[destination] += amount + return(1) + +def balance(): + if not self.storage[msg.sender]: + return(-1) + else: + return(self.storage[msg.sender]) +``` + +
+
+ +---- + +
+
+ +# Solidity + +
+ +# Solidity +#### History +- 2014-now +- by Christian Reitwießner +- alternative compilers: Solang, SOLL + +
+
+ +# Solidity +#### Characteristics +- high-level +- procedural +- strongly-typed +- curly-braced + +
+
+ +# Solidity +#### Influences +- C++ +- Python +- JavaScript + +
+
+ +# Solidity +#### Highlights +- type safety +- object-oriented abstractions +- modifiers, events, errors +- inline assembly +- dynamic types +- versatility and flexibility +- very active development + +
+
+ +# Solidity +#### Future +- generics and type system redesign +- compile-time evaluation +- debug data format + +
+
+ +# Solidity +#### Drawbacks +- complexity + - bad for auditability + - bad for security + - bad for formal analysis +- cost of abstractions +- stack pressure + +
+
+
+ +```solidity +// SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.4; + +contract Token { + address public minter; + mapping(address => uint) public balances; + + event Sent(address from, address to, uint amount); + error Insufficient(uint requested, uint available); + + constructor() { + minter = msg.sender; + } + + function mint(address receiver, uint amount) public { + require(msg.sender == minter); + balances[receiver] += amount; + } + + function send(address receiver, uint amount) public { + if (amount > balances[msg.sender]) + revert Insufficient({ + requested: amount, + available: balances[msg.sender] + }); + + balances[msg.sender] -= amount; + balances[receiver] += amount; + emit Sent(msg.sender, receiver, amount); + } +} +``` + +
+
+ +---- + +
+
+ +# Vyper + +
+ +# Vyper +#### History +- 2016-now +- by Vitalik Buterin +- successor to Serpent +- originally called Viper + +
+
+ +# Vyper +#### Characteristics +- high-level +- procedural +- strongly-typed +- pythonic + +
+
+ +# Vyper +#### Highlights +- sneks on the EVM +- addressing complexity by limiting features + - no inheritance + - no overloading + - no modifiers + - no imports + - no inline assembly +- no unbounded computation and data structures + - bounded dynamic arrays + - no infinite loops + - no recursive internal calls +- checked arithmetic early on +- static memory management + - no "Stack too deep" errors + +
+
+ +# Vyper +#### Memory expansion cost +- on the EVM you pay for memory space + - based on highest address accessed (`MSIZE`) + - cost quadratic over 704 bytes + - see Yellow Paper for exact formula +- Solidity allocates but never frees memory +- Vyper allocates on internal call and frees afterwards + +
+
+ +# Vyper +#### Drawbacks +- limiting, less flexibility +- static allocation can be wasteful + - but often better than no deallocation +- cost of storing all variables in memory +- still had security issues despite limitations + +
+
+
+ +```vyper +beneficiary: public(address) +auctionStart: public(uint256) +auctionEnd: public(uint256) +highestBidder: public(address) +highestBid: public(uint256) +ended: public(bool) + +@external +def __init__( + _beneficiary: address, + _auction_start: uint256, + _bidding_time: uint256 +): + self.beneficiary = _beneficiary + self.auctionStart = _auction_start + self.auctionEnd = self.auctionStart + _bidding_time + assert block.timestamp < self.auctionEnd + +@external +@payable +def bid(): + assert block.timestamp >= self.auctionStart + assert block.timestamp < self.auctionEnd + assert msg.value > self.highestBid + self.highestBidder = msg.sender + self.highestBid = msg.value + +@external +def endAuction(): + assert block.timestamp >= self.auctionEnd + assert not self.ended + self.ended = True + send(self.beneficiary, self.highestBid) +``` + +
+
+ +---- + +
+
+ +# Fe + +
+ +# Fe +#### History +- 2019-now +- by David Sanders +- originally called Rust Vyper +- started out as a Vyper compiler +- diverged into a separate language + +
+
+ +# Fe +#### Characteristics +- high-level +- procedural +- strongly-typed +- Rust-like + +
+
+ +# Fe +#### Influences +- Python +- Rust + +
+
+ +# Fe +#### Highlights +- inherited from Vyper + - no unbounded computation and data structures + - no modifiers + - no overloading +- moving towards Rust + - `{` no more snek `}` + - traits over inheritance + - generics + - module imports + - lots of other good elements of the design +- influence from Solidity via Yul + - dynamic memory management + - variables on stack + +
+
+ +# Fe +#### Drawbacks +- still in the alpha stage +- design in flux, pivoting from Python to Rust +- affected by stack pressure like Solidity + +
+
+
+ +```rust +struct Transfer { + #indexed + pub from: address + pub value: u256 +} +contract Token { + _balances: Map + + pub fn __init__(mut self, mut ctx: Context) { + self._balances[ctx.msg_sender()] = 1000_000_000 + } + + pub fn balanceOf(self, _ account: address) -> u256 { + return self._balances[account] + } + + pub fn transfer( + mut self, mut ctx: Context, + to: address, v: u256 + ) { + self._transfer(ctx, from: ctx.msg_sender(), to, v) + } + + fn _transfer( + mut self, mut ctx: Context, + from: address, to: address, v: u256 + ) { + assert from != address(0) and to != address(0) + self._balances[from] = self._balances[from] - v + self._balances[to] = self._balances[to] + v + ctx.emit(Transfer(from: from, v)) + } +} +``` + +
+
+ +---- + +
+
+ +# Sway + +
+ +# Sway +#### History +- 2021-now +- by John Adler and Alex Hansen +- targets FuelVM +- EVM backend in development + +
+
+ +# Sway +#### Characteristics +- high-level +- procedural +- strongly-typed +- Rust-like + +
+
+ +# Sway +#### FuelVM vs EVM +- register-based +- very cheap memory +- memory shared between contract calls +- UTXO paradigm +- native assets +- scripts + +
+
+ +# Sway +#### Highlights +- heap-based memory management +- language design closely following Rust + - borrow-checker + - generics +- inline assembly +- standard library +- no reentrancy issues +
+
+ +# Sway +#### Drawbacks +- on EVM may lose features that depend on FuelVM + - reentrancy protection + - no stack pressure + - memory management + - account abstraction +- more features = more complexity + +
+
+
+ +```rust +contract; + +abi TestContract { + #[storage(write)] + fn initialize_counter(value: u64) -> u64; + + #[storage(read, write)] + fn increment_counter(amount: u64) -> u64; +} + +storage { + counter: u64 = 0, +} + +impl TestContract for Contract { + #[storage(write)] + fn initialize_counter(value: u64) -> u64 { + storage.counter = value; + value + } + + #[storage(read, write)] + fn increment_counter(amount: u64) -> u64 { + let incremented = storage.counter + amount; + storage.counter = incremented; + incremented + } +} +``` + +
+
+ +---- + +#### Mainstream languages: timeline + +![mainstream-timeline](mainstream-timeline.svg) + +--- + +## IR/assembly languages +- LLL +- Yul +- Yul+ +- ETK assembly +- Huff +- Sonatina + +---- + +
+
+ +# LLL + +
+ +# LLL +#### History +- 2014-now +- by Gavin Wood +- LLL = Lisp-Like Language +- LLL/Solidity deprecated +- LLL/Vyper lives on as Vyper IR + +
+
+ +# LLL +#### Characteristics +- low-level +- imperative (not functional) +- untyped +- Lisp-inspired syntax + +
+
+ +# LLL +#### Highlights +- S-expressions are extremely easy to parse +- variables, expressions, control structures +- direct stack manipulation possible +- imports +- inline assembly +- macros + +
+
+ +# LLL +#### Drawbacks +- (to (is syntax weird) (is people (not (used-to Lisp)))) +- not actually functional despite appearances +- not a perfect IR + +
+
+
+ +```lisp +(seq + (def 'scratch 0x00) + + (def 'identity 0xac37eebb) + + (def 'function (function-hash code-body) + (when + (= + (div + (calldataload 0x00) + (exp 2 224)) + function-hash) + code-body)) + + (returnlll + (function identity + (seq + (mstore scratch (calldataload 0x04)) + (return scratch 32))))) +``` + +
+
+ +---- + +
+
+ +# Yul + +
+ +# Yul +#### History +- 2017-now +- by Christian Reitwießner and Alex Beregszaszi +- JULIA -> IULIA -> Yul +- Solidity's inline assembly +- IR for Solidity, Fe, Flint, Logikon + +
+
+ +# Yul +#### Characteristics +- low-level +- procedural +- untyped +- curly-braced +- designed primarily as IR + +
+
+ +# Yul +#### Highlights +- very simple syntax +- human-readable by design +- control structures resembling those from Solidity + - loops, conditions + - variables + - functions +- literals +- retains more high-level context for the optimizer + +
+
+ +# Yul +#### Drawbacks +- no direct stack access +- no jumps +- no inline assembly +- no operators +- no imports +- no convenience features +- Yul->EVM transform is non-trivial and hides complexity + +
+
+
+ +```yul +object "C" { + code { + let size := datasize("C") + datacopy(0, dataoffset("C_deployed"), size) + return(0, size) + } + + object "C_deployed" { + code { + function power(base, exponent) -> result { + switch exponent + case 0 { result := 1 } + case 1 { result := base } + default { + result := power( + mul(base, base), + div(exponent, 2) + ) + + switch mod(exponent, 2) + case 1 { + result := mul(base, result) + } + } + } + + mstore(0, power(2, 10)) + return(0, 0x20) + } + + data ".metadata" "11223344" + } +} +``` + +
+
+ +---- + +
+
+ +# Yul+ + +
+ +# Yul+ +#### History +- 2020-2022 +- by Nick Dodson + +
+
+ +# Yul+ +#### Characteristics +- low-level +- procedural +- untyped +- curly-braced + +
+
+ +# Yul+ +#### Highlights +- superset of Yul +- convenience features for humans + - safe math + - enums + - constants + - selector generation + - memory structures + +
+
+ +# Yul+ +#### Drawbacks +- more complexity + - not needed in an IR + - more effort to parse and process +- not produced by the higher-level compilers + +
+
+
+ +```yul +object "SimpleStore" { + code { + let size := datasize("Runtime") + datacopy(0, dataoffset("Runtime"), size) + return(0, size) + } + + object "Runtime" { + code { + calldatacopy(0, 0, 36) + mstruct StoreCalldata(sig: 4, val: 32) + + let topic := topic"event Store(uint256 value)" + + switch StoreCalldata.sig(0) + case sig"function store(uint256 val)" { + sstore(0, StoreCalldata.val(0)) + log2(0, 0, topic, StoreCalldata.val(0)) + } + case sig"function get() returns (uint256)" { + mstore(100, sload(0)) + return (100, 32) + } + } + } +} +``` + +
+
+ +---- + +
+
+ +# ETK assembly + +
+ +# ETK assembly +#### History +- 2021-now +- by Matt Garnett and Sam Wilson +- ETK = EVM ToolKit. +- inspired by NASM and similar assemblers +- still experimental + +
+
+ +# ETK assembly +#### Characteristics +- low-level +- imperative +- untyped +- assembly +- designed primarily for humans + +
+
+ +# ETK assembly +#### Highlights +- designed for creating EVM bytecode by hand + - direct stack access + - jumps + - nothing is hidden from the programmer +- minimal convenience features for humans + - macros + - operators + - selector generation + - imports +- close to EVM assembly output from higher-level compilers + +
+
+ +# ETK assembly +#### Drawbacks +- nothing is hidden from the programmer +- harder to read and analyze than Yul +- not an IR so not produced by the higher-level compilers + +
+
+
+ +``` +%macro foo() + push1 start + jump +%end + +%macro bar() + start: + push1 0x40 + push1 start +%end + +%macro foobar(tag, gat) + push2 $tag + push2 $gat + push1 delayed_expr(7) +%end + +%def delayed_expr(x) + $x + 1 +%end + +start: + jumpdest + pc + %foo() + %bar() + push1 delayed + +delayed: + %foobar(start, 0x42) +``` + +
+
+ +---- + +
+
+ +# Huff + +
+ +# Huff +#### History +- 2019-now +- by Zachary Williamson +- initial implementation in JavaScript +- In 2022 reimplemented in Rust + +
+
+ +# Huff +#### Characteristics +- low-level +- imperative +- untyped +- assembly +- designed primarily for humans + +
+
+ +# Huff +#### Features +- designed for creating EVM bytecode by hand + - direct stack access + - jumps +- extra convenience features over ETK + - constants + - custom errors +- higher level primitives + - jump tables + - functions + +
+
+ +# Huff +#### Drawbacks +- a little more complexity than in ETK +- missing some convenience features from ETK + - operators +- harder to read and analyze than Yul +- not an IR so not produced by the higher-level compilers + +
+
+
+ +``` +#define function addWord(uint256) pure returns (uint256) +#define constant OWNER = FREE_STORAGE_POINTER() + +#define macro ONLY_OWNER() = takes (0) returns (0) { + caller + [OWNER] sload + eq + is_owner jumpi + 0x00 0x00 revert + + is_owner: +} + +#define macro ADD_WORD() = takes (1) returns (1) { + ONLY_OWNER() + 0x20 + add +} + +#define macro MAIN() = takes (0) returns (0) { + 0x00 calldataload + 0xE0 shr + __FUNC_SIG(addWord) + eq + add_word jumpi + 0x00 0x00 revert + + add_word: + 0x04 calldataload + ADD_WORD() + 0x00 mstore + 0x20 0x00 return +} +``` + +
+
+ +---- + +
+
+ +# Sonatina + +
+ +# Sonatina +#### History +- 2021-now +- by Yoshitomo Nakanishi +- meant to replace Yul as Fe's IR +- still very experimental + +
+
+ +# Sonatina +#### Characteristics +- low-level +- imperative +- weakly-typed +- assembly-like +- designed primarily as IR + +
+
+ +# Sonatina +#### Highlights +- simple syntax +- types +- more friendly towards some code generation strategies + - explicit jumps instead of control structures + - no direct stack access + - variables and functions + +
+
+ +# Sonatina +#### Drawbacks +- not as readable as Yul +- design still in flux, not much documentation + +
+
+
+ +``` +target = "evm-ethereum-london" + +func public %nested_loops(v0.i32, v1.i32) -> void: + block0: + jump block1; + + block1: + v2.i32 = phi (0.i32 block0) (v9 block5); + jump block2; + + block2: + v3.i32 = phi (0.i32 block1) (v7 block3); + jump block3; + + block3: + v4.i32 = add v0 v2; + v5.i32 = add v0 v1; + v6.i32 = mul v4 v5; + v7.i32 = sub v6 v3; + v8.i1 = slt v7 10.i32; + br v8 block4 block2; + + block4: + v9.i32 = add v2 1.i32; + v10.i1 = slt v9 100.i32; + br v10 block1 block5; + + block5: + return; +``` + +
+
+ +---- + +#### IR/assembly languages: timeline + +![ir-assembly-timeline](ir-assembly-timeline.svg) + +--- + +## Experimental languages + +| Language | Influences | Style | +|----------------|------------------|--------------------| +| Mutan | Go, C | procedural | +| Bamboo | Obsidian, Erlang | procedural | +| Flint | Swift | procedural | +| Pyramid Scheme | Scheme | functional | +| HAssembly-evm | Haskell | functional | +| Logikon | Prolog, Haskell | logical/functional | +| Lira | | declarative | + +---- + +#### Experimental languages: timeline + +![experimental-timeline](experimental-timeline.svg) + +--- + +# What else is there? + +---- + +### ZK/circuit languages +![zk-languages-wordcloud](zk-languages-wordcloud.png) + +---- + +### Languages on other blockchains +![other-blockchain-languages-wordcloud](other-blockchain-languages-wordcloud.png) + +--- + +# Thank you! + +
+
+
+
+ +
+ +- ✉ kamil.sliwak@codepoets.it
+- **@cameel** +- `#solidity-dev` channel on Matrix + +
diff --git a/cpwro2023/style.css b/cpwro2023/style.css new file mode 100644 index 0000000..263d407 --- /dev/null +++ b/cpwro2023/style.css @@ -0,0 +1,35 @@ +/* Styles that splits the slide into two columns. */ +.column-container { + display: flex; + height: 100%; +} + +.column { + width: 50%; +} + +/* Non-transparent card for use in r-stacks so that the previous content does not show through. + * Assumes a white theme. */ +.card { + height: 100%; + width: 100%; + background: white; +} + +/* Make the code blocks take the full height of the slide. */ +pre.code-wrapper { + margin: 0; + height: 90vh; +} + +/* Fix Python decorators and Rust attributes being highlighted as black text in Monokai. */ +.hljs-meta { + color: #F92672; +} + +.author-info { + font-size: 30px; + text-align: right; + border-right: 2px solid black; + padding: 20px; +} diff --git a/cpwro2023/zk-languages.txt b/cpwro2023/zk-languages.txt new file mode 100644 index 0000000..a123c15 --- /dev/null +++ b/cpwro2023/zk-languages.txt @@ -0,0 +1,7 @@ +Cairo +Zinc +Leo +Circom +Noir +Zokrates +Snarky