Universal-Sierra-Compiler
August 20, 2026 ยท View on GitHub
Universal-Sierra-Compiler is the tool/crate for Sierra compilation. It compiles any ever-existing Sierra version to CASM.
| Supported Sierra Versions |
|---|
| 1.9.2 |
| 1.9.1 |
| 1.9.0 |
| 1.8.0 |
| 1.7.0 |
| 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.9.1"
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-contractcompile-raw
The first one compiles Sierra of the Starknet contract, while the second one compiles Sierra of the plain Cairo code.
CASM cache
Both subcommands accept an optional --cache-dir argument. When it is passed, USC stores compiled
CASM in that directory and reuses it on later runs if the Sierra input did not change.
$ universal-sierra-compiler \
compile-contract \
--sierra-path ./path/to/sierra.json \
--cache-dir ./path/to/cache
The cache is best-effort. If it cannot be read or written, USC falls back to normal compilation.
Note
Caching is currently supported only by the CLI through the --cache-dir argument.
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": ...,
"debug_info": ...,
"function_costs": {
"0": {"const": 10000, "pedersen": 1}
}
}
function_costs maps each raw Sierra function's entry-point statement index to its
compiler-inferred cost-token counts. Consumers should price builtin tokens using the same
builtin-cost table that is supplied to the compiled program at execution time.
๐ 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>.