#sierra #version #compilation #casm #tool #compile-contract #ever-existing

bin+lib universal-sierra-compiler

Universal-Sierra-Compiler is the tool for Sierra compilation. It compiles any ever-existing Sierra version to CASM.

4 releases (2 stable)

2.2.0 Aug 2, 2024
2.2.0-rc.1 Jul 10, 2024
2.2.0-rc.0 Jul 2, 2024
2.1.0 Mar 22, 2024

#2 in #casm

Download history 178/week @ 2024-07-21 338/week @ 2024-07-28 322/week @ 2024-08-04 111/week @ 2024-08-11 78/week @ 2024-08-18 94/week @ 2024-08-25 84/week @ 2024-09-01 26/week @ 2024-09-08 108/week @ 2024-09-15 169/week @ 2024-09-22 75/week @ 2024-09-29 30/week @ 2024-10-06 44/week @ 2024-10-13 89/week @ 2024-10-20 150/week @ 2024-10-27 104/week @ 2024-11-03

390 downloads per month
Used in 4 crates (3 directly)

MIT license

1MB
289 lines

Universal-Sierra-Compiler

Crates.io Version

Universal-Sierra-Compiler is the tool/crate for Sierra compilation. It compiles any ever-existing Sierra version to CASM.

Supported Sierra Versions
1.6.0
1.5.0
~1.4.0
~1.3.0
~1.2.0
1.1.0
1.0.0
0.1.0

Installation

To install the latest stable version of universal-sierra-binary run:

curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh

Alternatively, to use USC as a Rust dependency, just put it in your Cargo.toml like so:

universal-sierra-compiler = "2.1.0"

You almost always want to install the latest stable version. In rare cases where a prerelease with a new unstable sierra version exists, and you want to use it, run the following command with the requested prerelease version:

curl -L https://raw.githubusercontent.com/software-mansion/universal-sierra-compiler/master/scripts/install.sh | sh -s -- v2.0.0-rc.0

📝 Note

If the script can't add installed binary to the PATH, it will print the instructions about adding it manually.

Using as a binary

Command line tool

Tool consist of two subcommands:

  • compile-contract
  • compile-raw

The first one compiles Sierra of the Starknet contract, while the second one compiles Sierra of the plain Cairo code.

compile-contract subcommand

The input of this subcommand is a path to a file with Sierra of the contract (cairo_lang_starknet_classes::contract_class::ContractClass) in json format:

$ universal-sierra-compiler \
  compile-contract \
  --sierra-path ./path/to/sierra.json
  
{"bytecode": ...}

📝 Note

Please, note that the output is in the JSON format.

To automatically save CASM, pass --output-path argument:

$ universal-sierra-compiler \
    compile-contract \
      --sierra-path ./path/to/sierra.json
      --output-path ./path/to/casm.json

compile-raw subcommand

The input of this subcommand is a path to a file with Sierra program (cairo_lang_sierra::program::Program) in json format:

$ universal-sierra-compiler \
    compile-raw \
      --sierra-path ./path/to/sierra.json
  
{"assembled_cairo_program": ...}

📝 Note

Please, note that the output is in the JSON format.

To automatically save assebled cairo program, pass --output-path argument:

$ universal-sierra-compiler \
    compile-raw \
      --sierra-path ./path/to/sierra.json
      --output-path ./path/to/casm.json

Using as a library

Library crate exports two functions:

  • compile_contract(serde_json::Value) -> Result<serde_json::Value>
  • compile_raw(serde_json::Value) -> Result<serde_json::Value>

They do the same as their CLI counterparts. However, they accept the whole program in json format as a parameter, precisely a json_serde::Value. Return value is the compiled program inside Result<serde_json::Value>.

Dependencies

~26–37MB
~527K SLoC