SlideShare a Scribd company logo
1 of 16
Who am I?
● Sean Young
● Maintainer of Burrow at Monax
● Maintainer of consumer IR and DVB in linux kernel
● Interested in compilers and reverse engineering
Compiling Solidity to WASM
using solang
Solidity/EVM today
 EVM is the Virtual Machine, Solidity the source language
 Simple high-level language inspired by JavaScript
 All arithmetic and memory operations are 256 bit
 Only Solidity supports EVM, no other languages
 string/per-byte processing difficult
 More accurate gas cost
 Not amenable to JIT function foo(string owner) {
if (owner == "root") {
// does not compile
}
if (sha256(owner) == sha256("root")) {
// recommended solution
}
}
WASM
 WASM is a general, low-level virtual machine
 Ability to JIT and great implementations exist
 Arithmetic is 32 and 64 bit
 Memory can be accessed in all the usual ways
 32 bit and 64 floats do exist – not deterministic
 Has fantastic tooling available
Why have Smart Contracts in WASM?
 Support for languages other than Solidity
 Linking Solidity with other languages:
 Cryptography in Smart Contracts
 Re-use existing libraries (e.g. BPM)
 Efficient data structures
 Improving the Solidity Language
 Re-use existing tooling (llvm compiler kit)
 How to do 256 integer arithmetic on 64 bit VM?
Existing Solidity compiler
 Huge C++ project
 Handwritten lexer/parser
 Handwritten optimiser (YUL)
 EVM output is not optimal
What is solang?
 Small, clean implementation of Solidity
 Written in rust
 Generated lexer and parser
 Use llvm:
 Wonderful optimiser
 Writes wasm binary format
 Solves 256 bit integer problem
 Includes linker (e.g. C or rust modules)
 Fraction of the code base
 Proper string processing and string formatting possible
Where is solang today?
 $ cargo install solang
 Hyperledger Labs project
 Incomplete Solidity language support
 Supports intN, uintN, bool, enum types
 Supports if/else, for, while
 Supports contract storage
 ABI compatible with Solidity/EVM
 Supported in Hyperledger Burrow 0.27.0
Running solang with Burrow today
 Install burrow 0.27.0
 Install solang (cargo install solang)
 When deploying contracts, specify –wasm
 Entirely transparent: solang will be used instead solc and
WASM VM rather EVM
burrow deploy –wasm -v Root_0 deploy.yaml
Solang implementation
Traditional compiler construction. The stages are:
1)Lexer and parser produces Abstract Syntax Tree (AST)
2)AST is decorated (resolved) and transformed into Control
Flow Graph (CFG)
3)CFG is mapped to LLVM IR
4)Call LLVM optimiser and generate and link
1) Lexer and parse stage
 Parser is generated from Solidity grammar using lalrpop
 Outputs AST tree, with symbols locations so we can
provide locations on error and warning messages
 Mostly generated
2) Resolve and Control Flow Graph
 Walks the contracts in the AST
 Generates CFG for statements
 Resolves variables, functions
and types (e.g. enums)
# solang –emit-cfg
foo:
x = 100
y = bar * 100
C = y > 100
brcond c, bar1, bar2
bar1:
a = y + 200
return a
bar2:
b = y << 4
return b
3) Translate to LLVM IR
 Intermediate Representation of
code used LLVM
 Mapping from CFG to LLVM IR
should be mostly 1-to-1
 Also generates ABI
encoder/decoder
 solang –emit-llvm
solang –-emit-llvm foo.sol
; ModuleID = 'bar'
target triple = "wasm32-unknown-unknown-wasm"
define i32 @foo(i32, i32) {
entry:
%2= add i32 %0, 100
%3= icmp sgt i32 %1, 0
br i1 %3, label %then, label %else
then: ; preds = %entry
%4= mul i32 %1, 100
%5= add i32 %2, %4
br label %endif
else: ; preds= %entry
%6= add i32 %1, 10
br label %endif
endif: ; preds= %else, %then
%x= phi i32 [ %5, %then ], [ %6, %else ]
reti32 %x
}
4) LLVM generate and link
 Call LLVM optimizating passes
 Call LLVM code generate
 Result: WASM object file
 Need to link into final contract
 Currently done in rust, can be done by LLVM linker too
 solang --no-link
Future: solang linking against C, etc
LLVM LTO linker can link against wasm objects:
C:
clang --target=wasm32 -c -O3 -Wall foo.c
solang contract.sol –link foo.o
Next steps for solang
 Make compatible with eWASM
 More data types: string, bytes, struct, mapping, arrays
 Other language features: modifiers, external calls, imports,
interfaces
 Testcases
 Get involved!
Thanks!
sean.young@monax.io
https://github.com/hyperledger-labs/solang/
https://monax.io/

More Related Content

Similar to Compiling Solidity to WASM using solang

07 140430-ipp-languages used in llvm during compilation
07 140430-ipp-languages used in llvm during compilation07 140430-ipp-languages used in llvm during compilation
07 140430-ipp-languages used in llvm during compilationAdam Husár
 
Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assemblyShakacon
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityThomas Moulard
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptxAnaLoreto13
 
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...Masashi Yoshimura
 
Porting To Symbian
Porting To SymbianPorting To Symbian
Porting To SymbianMark Wilcox
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXLLinaro
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bitsChiou-Nan Chen
 
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...Masashi Yoshimura
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyMatthew Gaudet
 
A world to win: WebAssembly for the rest of us
A world to win: WebAssembly for the rest of usA world to win: WebAssembly for the rest of us
A world to win: WebAssembly for the rest of usIgalia
 
Mitigating overflows using defense in-depth. What can your compiler do for you?
Mitigating overflows using defense in-depth. What can your compiler do for you?Mitigating overflows using defense in-depth. What can your compiler do for you?
Mitigating overflows using defense in-depth. What can your compiler do for you?Javier Tallón
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits BVBA (freelancer)
 
compressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfcompressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfGinaMartinezTacuchi
 
compressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfcompressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfMaherEmad1
 
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...ryancox
 

Similar to Compiling Solidity to WASM using solang (20)

07 140430-ipp-languages used in llvm during compilation
07 140430-ipp-languages used in llvm during compilation07 140430-ipp-languages used in llvm during compilation
07 140430-ipp-languages used in llvm during compilation
 
Wasm intro
Wasm introWasm intro
Wasm intro
 
Web (dis)assembly
Web (dis)assemblyWeb (dis)assembly
Web (dis)assembly
 
Raising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code QualityRaising the Bar on Robotics Code Quality
Raising the Bar on Robotics Code Quality
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
cs262_intro_slides.pptx
cs262_intro_slides.pptxcs262_intro_slides.pptx
cs262_intro_slides.pptx
 
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to LLVM bitcod...
 
Porting To Symbian
Porting To SymbianPorting To Symbian
Porting To Symbian
 
SFO15-500: VIXL
SFO15-500: VIXLSFO15-500: VIXL
SFO15-500: VIXL
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bits
 
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...
elfconv: AOT compiler that translates Linux/AArch64 ELF binary to WebAssembly...
 
Experiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRubyExperiments in Sharing Java VM Technology with CRuby
Experiments in Sharing Java VM Technology with CRuby
 
A world to win: WebAssembly for the rest of us
A world to win: WebAssembly for the rest of usA world to win: WebAssembly for the rest of us
A world to win: WebAssembly for the rest of us
 
Mitigating overflows using defense in-depth. What can your compiler do for you?
Mitigating overflows using defense in-depth. What can your compiler do for you?Mitigating overflows using defense in-depth. What can your compiler do for you?
Mitigating overflows using defense in-depth. What can your compiler do for you?
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
AllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW SecurityAllBits presentation - Lower Level SW Security
AllBits presentation - Lower Level SW Security
 
compressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfcompressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdf
 
compressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdfcompressed.tracemonkey-pldi-09.pdf
compressed.tracemonkey-pldi-09.pdf
 
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
Developing Applications for Beagle Bone Black, Raspberry Pi and SoC Single Bo...
 

Recently uploaded

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

Compiling Solidity to WASM using solang

  • 1. Who am I? ● Sean Young ● Maintainer of Burrow at Monax ● Maintainer of consumer IR and DVB in linux kernel ● Interested in compilers and reverse engineering Compiling Solidity to WASM using solang
  • 2. Solidity/EVM today  EVM is the Virtual Machine, Solidity the source language  Simple high-level language inspired by JavaScript  All arithmetic and memory operations are 256 bit  Only Solidity supports EVM, no other languages  string/per-byte processing difficult  More accurate gas cost  Not amenable to JIT function foo(string owner) { if (owner == "root") { // does not compile } if (sha256(owner) == sha256("root")) { // recommended solution } }
  • 3. WASM  WASM is a general, low-level virtual machine  Ability to JIT and great implementations exist  Arithmetic is 32 and 64 bit  Memory can be accessed in all the usual ways  32 bit and 64 floats do exist – not deterministic  Has fantastic tooling available
  • 4. Why have Smart Contracts in WASM?  Support for languages other than Solidity  Linking Solidity with other languages:  Cryptography in Smart Contracts  Re-use existing libraries (e.g. BPM)  Efficient data structures  Improving the Solidity Language  Re-use existing tooling (llvm compiler kit)  How to do 256 integer arithmetic on 64 bit VM?
  • 5. Existing Solidity compiler  Huge C++ project  Handwritten lexer/parser  Handwritten optimiser (YUL)  EVM output is not optimal
  • 6. What is solang?  Small, clean implementation of Solidity  Written in rust  Generated lexer and parser  Use llvm:  Wonderful optimiser  Writes wasm binary format  Solves 256 bit integer problem  Includes linker (e.g. C or rust modules)  Fraction of the code base  Proper string processing and string formatting possible
  • 7. Where is solang today?  $ cargo install solang  Hyperledger Labs project  Incomplete Solidity language support  Supports intN, uintN, bool, enum types  Supports if/else, for, while  Supports contract storage  ABI compatible with Solidity/EVM  Supported in Hyperledger Burrow 0.27.0
  • 8. Running solang with Burrow today  Install burrow 0.27.0  Install solang (cargo install solang)  When deploying contracts, specify –wasm  Entirely transparent: solang will be used instead solc and WASM VM rather EVM burrow deploy –wasm -v Root_0 deploy.yaml
  • 9. Solang implementation Traditional compiler construction. The stages are: 1)Lexer and parser produces Abstract Syntax Tree (AST) 2)AST is decorated (resolved) and transformed into Control Flow Graph (CFG) 3)CFG is mapped to LLVM IR 4)Call LLVM optimiser and generate and link
  • 10. 1) Lexer and parse stage  Parser is generated from Solidity grammar using lalrpop  Outputs AST tree, with symbols locations so we can provide locations on error and warning messages  Mostly generated
  • 11. 2) Resolve and Control Flow Graph  Walks the contracts in the AST  Generates CFG for statements  Resolves variables, functions and types (e.g. enums) # solang –emit-cfg foo: x = 100 y = bar * 100 C = y > 100 brcond c, bar1, bar2 bar1: a = y + 200 return a bar2: b = y << 4 return b
  • 12. 3) Translate to LLVM IR  Intermediate Representation of code used LLVM  Mapping from CFG to LLVM IR should be mostly 1-to-1  Also generates ABI encoder/decoder  solang –emit-llvm solang –-emit-llvm foo.sol ; ModuleID = 'bar' target triple = "wasm32-unknown-unknown-wasm" define i32 @foo(i32, i32) { entry: %2= add i32 %0, 100 %3= icmp sgt i32 %1, 0 br i1 %3, label %then, label %else then: ; preds = %entry %4= mul i32 %1, 100 %5= add i32 %2, %4 br label %endif else: ; preds= %entry %6= add i32 %1, 10 br label %endif endif: ; preds= %else, %then %x= phi i32 [ %5, %then ], [ %6, %else ] reti32 %x }
  • 13. 4) LLVM generate and link  Call LLVM optimizating passes  Call LLVM code generate  Result: WASM object file  Need to link into final contract  Currently done in rust, can be done by LLVM linker too  solang --no-link
  • 14. Future: solang linking against C, etc LLVM LTO linker can link against wasm objects: C: clang --target=wasm32 -c -O3 -Wall foo.c solang contract.sol –link foo.o
  • 15. Next steps for solang  Make compatible with eWASM  More data types: string, bytes, struct, mapping, arrays  Other language features: modifiers, external calls, imports, interfaces  Testcases  Get involved!

Editor's Notes

  1. Straw poll: Solidity, Kafka, elliptic curve diffie helman?
  2. Straw poll: Solidity, Kafka, elliptic curve diffie helman?