Installation
We recommend working inside a python virtual environment, but you can also install the Cairo package directly. To create and enter the virtual environment, type:
python3.7 -m venv
~/cairo_venv
source ~/cairo_venv/bin/activate
Make sure the venv is activated – you should see (cairo_venv)
in the command line prompt.
Make sure you can install the following pip packages: ecdsa
, fastecdsa
, sympy
. On Ubuntu, for example, you will have to first run:
sudo apt install -y libgmp3-dev
To install the Cairo package, run:
pip install cairo-starkware-0.0.1.zip
Cairo was tested with python3.7. To make it work with python3.6, you will have to install contextvars
:
pip install contextvars
Compiling and running a Cairo program
- Create a file, named
test.cairo
, with the following lines:
func main(): [ap] = 1000; ap++ [ap] = 2000; ap++ [ap] = [ap - 2] + [ap - 1]; ap++ ret end
- Compile: (make sure all commands are executed in the virtual environment)
cairo-compile test.cairo \ --debug_info \ --prime=3618502788666131213697322783095070105623107215331596699973092056135872020481 \ --output test_compiled.json
- Run:
cairo-run \ --program=test_compiled.json --print_output \ --print_info --relocate_prints
- You can open the Cairo tracer by providing the
--tracer
flag tocairo-run
. Then open it at http://localhost:8100/.
Visual Studio Code setup
Install the Cairo Visual Studio Code extension:
code --install-extension cairo-0.0.1.vsix
Configure Visual Studio Code settings:
"editor.formatOnSaveTimeout": 1500