SlideShare a Scribd company logo
SCaml compiler
DaiLambda, Inc.
Jun FURUSE/古瀬淳
, Université de Paris, 2019-11-22Tezos Smart Contracts
What is SCaml
Yet another compiler from OCaml to Michelson.
For Smart contracts
Strict Subset of OCaml
Small (< 3000 loc.).
and Serious
Strict Subset of OCaml
No fancy features for smart contracts
Many OCaml features are disabled:
No recursion
No polymoprhism
No modules
No objects
No mutability
No user defined types
Small
Built over OCaml’s compiler­libs.
Reusing OCaml’s parser and type-checker,
which are well tested for long time.
SCaml code only compiles OCaml’s typed AST to Michelson.
Less than 3000 lines of *.ml, written in 5 days.
and Serious
Serious compiler. Not a toy.
All the Michelson opcodes are supported, except
CREATE_CONTRACT.
Some optimizations in the pure ML level.
Babylon ready (i.e. entry points, closures)
Benefit of being Strict Subset
OCaml programmers can use SCaml without any surprise.
Newbies can learn SCaml via OCaml tutorial.
Many OCaml eco-system tools can be used for free:
Menhir, Tuareg, indender, reformatter
PPX, P4, ReasonML
etc.
Possibilities of being Strict Subset
Contracts can be compiled to native code with a
proper OCaml library:
Fast Monte Carlo simulations of contracts.
Contract, UI and server together in OCaml.
“Ocsigen” for Tezos:
Contracts: to Michelson by SCaml
UI: to JS by JSOO
Server: to native by OCaml
Compilation path
Parsing by OCaml parser
Typing by OCaml type checker
Unifying types for entry points and storage
Translation to an IL, pure monomorhpic core ML
Some inlining and partial evaluation
Compilation to Michelson
SCaml Features
Numeric types: int, nat, tz
Int (­12),   Nat 42,   Tz 1.23
with monomorphic operators: (+), (+^),(+$)
Options, Lists, Sets, Maps:
Some 1,   [ 1; 2; 3 ]
Set [ 1; 2; 3 ],  Map [ (1, "one"), (2, "two") ]
Blockchain related constants with strings:
Key_hash "tz1..."
Pairs, Sums:
int * int,  (int, int) sum
No user defined data types… yet
Aliases are OK: type 'a t = (int * ('a, nat) sum)
Future Work
Pattern match (almost done)
User defined types
Nothing more. We keep things small.
Vague Idea of Collaboration
SCaml + ReFX = SCaml + refinement type
Refinement specification as SCaml annotations.
Compiles down them to annotations in Michelson.
SCam Language
A scam never calls it a scam.
https://gitlab.com/dailambda/scaml

More Related Content

PPTX
GDC2014: Boosting your ARM mobile 3D rendering performance with Umbra
PPTX
Leakage power optimization for ripple carry adder
PDF
Flow Control
ODP
OpenHistoricalMap tim waters - Topomancy / NYPL Lightning Talk
ODP
Clojure 12 Minute Talk
PDF
Toy Model Overview
PDF
Tezos 008 Edo protocol
PDF
Plebeia, a new storage for Tezos blockchain state
GDC2014: Boosting your ARM mobile 3D rendering performance with Umbra
Leakage power optimization for ripple carry adder
Flow Control
OpenHistoricalMap tim waters - Topomancy / NYPL Lightning Talk
Clojure 12 Minute Talk
Toy Model Overview
Tezos 008 Edo protocol
Plebeia, a new storage for Tezos blockchain state

More from Jun Furuse (18)

PDF
SCaml update 2020-06
PDF
Tezso and on-chain governanace: towards "Kyoto amendment"
PDF
Comparison of Proof of Stakes
PDF
SCaml compiler
PDF
Blockchain and Smart Contract Simulation
PDF
Blockchain and formal verification (Japanese)
PDF
Blockchain and Formal verification (English)
PDF
Tezos Hands on 2019-06-15 Exercise (Japanese)
PDF
Tezos Hands on 2019-06-15 (Japanese)
PDF
Tezos and its formal verification (Japanese)
PDF
Tezos hands-on : Tezos exercise
PDF
Tezos hands-on : Tezos overview
PDF
Tezos: Self-amending crypt ledger (Japanese)
PDF
ブロックチェーンと形式検証
PDF
Recent tezos core developments
PDF
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
PDF
OCamlOScope: a New OCaml API Search
ODP
Um2010
SCaml update 2020-06
Tezso and on-chain governanace: towards "Kyoto amendment"
Comparison of Proof of Stakes
SCaml compiler
Blockchain and Smart Contract Simulation
Blockchain and formal verification (Japanese)
Blockchain and Formal verification (English)
Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 (Japanese)
Tezos and its formal verification (Japanese)
Tezos hands-on : Tezos exercise
Tezos hands-on : Tezos overview
Tezos: Self-amending crypt ledger (Japanese)
ブロックチェーンと形式検証
Recent tezos core developments
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
OCamlOScope: a New OCaml API Search
Um2010
Ad

Recently uploaded (20)

PPTX
Current and future trends in Computer Vision.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
UNIT - 3 Total quality Management .pptx
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPT
Occupational Health and Safety Management System
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
introduction to datamining and warehousing
Current and future trends in Computer Vision.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
R24 SURVEYING LAB MANUAL for civil enggi
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
UNIT - 3 Total quality Management .pptx
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Visual Aids for Exploratory Data Analysis.pdf
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Occupational Health and Safety Management System
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Abrasive, erosive and cavitation wear.pdf
introduction to datamining and warehousing
Ad

SCaml compiler

  • 1. SCaml compiler DaiLambda, Inc. Jun FURUSE/古瀬淳 , Université de Paris, 2019-11-22Tezos Smart Contracts
  • 2. What is SCaml Yet another compiler from OCaml to Michelson. For Smart contracts Strict Subset of OCaml Small (< 3000 loc.). and Serious
  • 3. Strict Subset of OCaml No fancy features for smart contracts Many OCaml features are disabled: No recursion No polymoprhism No modules No objects No mutability No user defined types
  • 4. Small Built over OCaml’s compiler­libs. Reusing OCaml’s parser and type-checker, which are well tested for long time. SCaml code only compiles OCaml’s typed AST to Michelson. Less than 3000 lines of *.ml, written in 5 days.
  • 5. and Serious Serious compiler. Not a toy. All the Michelson opcodes are supported, except CREATE_CONTRACT. Some optimizations in the pure ML level. Babylon ready (i.e. entry points, closures)
  • 6. Benefit of being Strict Subset OCaml programmers can use SCaml without any surprise. Newbies can learn SCaml via OCaml tutorial. Many OCaml eco-system tools can be used for free: Menhir, Tuareg, indender, reformatter PPX, P4, ReasonML etc.
  • 7. Possibilities of being Strict Subset Contracts can be compiled to native code with a proper OCaml library: Fast Monte Carlo simulations of contracts. Contract, UI and server together in OCaml. “Ocsigen” for Tezos: Contracts: to Michelson by SCaml UI: to JS by JSOO Server: to native by OCaml
  • 8. Compilation path Parsing by OCaml parser Typing by OCaml type checker Unifying types for entry points and storage Translation to an IL, pure monomorhpic core ML Some inlining and partial evaluation Compilation to Michelson
  • 9. SCaml Features Numeric types: int, nat, tz Int (­12),   Nat 42,   Tz 1.23 with monomorphic operators: (+), (+^),(+$) Options, Lists, Sets, Maps: Some 1,   [ 1; 2; 3 ] Set [ 1; 2; 3 ],  Map [ (1, "one"), (2, "two") ] Blockchain related constants with strings: Key_hash "tz1..." Pairs, Sums: int * int,  (int, int) sum No user defined data types… yet Aliases are OK: type 'a t = (int * ('a, nat) sum)
  • 10. Future Work Pattern match (almost done) User defined types Nothing more. We keep things small.
  • 11. Vague Idea of Collaboration SCaml + ReFX = SCaml + refinement type Refinement specification as SCaml annotations. Compiles down them to annotations in Michelson.
  • 12. SCam Language A scam never calls it a scam. https://gitlab.com/dailambda/scaml