Expired
Milestone Apr 3, 2023–Jun 30, 2023

Support semantic interpretation of instructions set of a simple contract

Motivation

Objective: Key Result:

Scope

The goal of this milestone is to demonstrate Polyrun on a small Michelson script. More precisely, we want to develop Polyrun to the point where it can generate all the aspects of a Michelson runtime but on a small subset of Michelson.

The contract

parameter string;
storage (map string int);
code
  {
    AMOUNT ;
    PUSH mutez 5000000;
    COMPARE; GT;
    IF { FAIL } {};
    DUP; DIP { CDR; DUP }; CAR; DUP ;
    DIP
      {
        GET; ASSERT_SOME;
        PUSH int 1; ADD; SOME
      };
    UPDATE;
    NIL operation; PAIR
  }

The initial storage could be something like {Elt "Loana" 0; Elt "Steevy" 0}

ASSERT_SOME is a macro for IF_NONE{UNIT;FAILWITH}

So we need to support the following instructions

ADD AMOUNT CAR CDR COMPARE DUP DIP FAILWITH GT GET IF IF_NONE NIL PAIR PUSH SOME UPDATE UNIT

Work breakdown

  • (hours) check if the instructions are available in the rust interpreter
  • Allows to build a runtime restricted to an instruction subset
    • (days) OCaml (Instructions are used at many points)
      a possible path to do that is to progress in %Support for Michelson unit tests in TZT format in tezos/tezos to have an RPC to execute just the step function
    • (hours) Rust (scoped interpreter.rs) !41 (merged) !42 (merged)
  • Allows to build a runtime restricted to a type subset
    • (days) OCaml (many many pattern matching on types)
    • (days/weeks) Rust (t-o-t imports type defs from tezos-sdk)
  • move custom enrichment that should be pushed in the front-end into a separate file to ease readability !36 (merged)
  • (weeks) describe basic semantics rule in the data-model !35 (merged)
    • explore and understand t-o-t architecture
    • find a suitable data-model of interpreter semantics
    • write a rule for a chosen instruction
    • write a translation of these rule into rust code

For each instruction we need to support the generation of

  • the instruction definition (OCaml GADT)
  • the instruction typing (Ocaml parse_instr, Rust pop_cast)
  • the instruction interpretation (Ocaml step function, Rust ?)

For instruction definitions, ToT relies on tezos-rust-sdk crate. So adding/modifying instructions will require either to remove the dependency or to modify concurrently the two projects. We delay that in a future milestone and will rely on existing crate for now.

for each of this component,

  • first provide a data-model that holds the needed information
  • write/adapt the backend transformer that produces the relevant part in OCaml and Rust
  • bridge the data-model with the available description or modify the input structure

Per instruction:

simple operator

GT

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • the instruction interpretation
    • Ocaml
    • Rust

Algebraic destructors

CAR

  • instruction definition tezos/tezos!8720 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust !27 (merged)
  • the instruction interpretation
    • (days) semantic rule definition in data-model !35 (merged)
    • (hours) Ocaml generation
    • (hours) Rust generation !35 (merged)
    • (days) from description to semantic rule !43 (closed)

CDR

  • instruction definition tezos/tezos!8720 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust !27 (merged)
  • (hour once CAR is done) the instruction interpretation
    • (hour) semantic rule definition in data-model
    • (free ?) Ocaml generation
    • (free) Rust generation
    • (free) from description to semantic rule

Constructor

UNIT

  • instruction definition
    • make UNIT a Michelson instr tezos/tezos!8579 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours once !35 (merged) is done) the instruction interpretation
    • (hours) semantic rule definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

Polymorph constructor

SOME

  • instruction definition !2 (merged), !14 (merged), !21 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust !27 (merged)
  • (hours) the instruction interpretation
    • (hours) semantic rule definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation !39 (closed)
    • (hours) from description to semantic rule

NIL

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours) the instruction interpretation
    • (hour) semantic rule definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (free ?) from description to semantic rule

Polymorph with optional n parameter

DUP

  • instruction definition !2 (merged), !14 (merged), !21 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (days) the instruction interpretation
    • (hours) semantic rule definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

PAIR

  • instruction definition tezos/tezos!8720 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust !27 (merged)
  • the instruction interpretation
    • Ocaml
    • Rust
  • (hours once dup is done) the instruction interpretation
    • (hour) semantic rule definition in data-model
    • (hour) Ocaml generation
    • (hour) Rust generation
    • (hour) from description to semantic rule

with data parameter

PUSH

  • instruction definition !2 (merged), !14 (merged), !21 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours) the instruction interpretation (not counting data-parsing)
    • (hour) semantic rule definition in data-model
    • (hour) Ocaml generation
    • (hour) Rust generation
    • (hour) from description to semantic rule

Overloading

ADD

  • (weeks) instruction definition !2 (merged), !14 (merged), !21 (merged)
    • => overloading support
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (days) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

GET (at least on map)

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

UPDATE (on map)

  • instruction definition !2 (merged), !14 (merged), !21 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

COMPARE (at least on mutez)

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (hours) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

Chain's context dependent

AMOUNT

  • instruction definition !2 (merged), !14 (merged), !21 (merged)
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (days) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

Control flow

IF

  • instruction definition

    • Ocaml
  • the instruction typing

    • Ocaml
    • Rust
  • (days) the instruction interpretation

    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

DIP

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (days) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule

FAILWITH

  • instruction definition
    • Ocaml
  • the instruction typing
    • Ocaml
    • Rust
  • (days) the instruction interpretation
    • (hours) semantic rules definition in data-model
    • (hours) Ocaml generation
    • (hours) Rust generation
    • (hours) from description to semantic rule
  • Work items 1
  • Merge requests 7
  • Participants 0
  • Labels 0
Loading
Loading
Loading
Loading
0% complete
0%
Start date
Apr 3, 2023
Apr 3
-
Jun 30 2023
Due date
Jun 30, 2023 (Past due)
1
Work items 1 New issue
Open: 1 Closed: 0
None
Total weight
None
7
Merge requests 7
Open: 0 Closed: 2 Merged: 5
0
Releases
None
Reference: nomadic-labs/michelson-polyrun%"Support semantic interpretation of instructions set of a simple contract"