So let’s start off with what is Starknet,
StarkNet is a permissionless decentralized Validity-Rollup
(often referred to as ZK-Rollup). It operates as an L2 network over
Ethereum, enabling any dApp to achieve unlimited scale for its computation
– without compromising Ethereum's composability and security.
Or so is what Starkware’s site says. In simpler terms, it’s another chain which gets its computation done by external entities (could be servers hosted on AWS). The reason this still stays permission-less is due to the use of ZK-Proofs to verify that the computation done isn’t tampered with. These ZK-Proof verifiers are essentially Smart contracts on Ethereum Mainnet that are responsible for verifying the proofs submitted by these external entities.
To enable this ZK-Proof validation via STARKS, Cairo was created by Team Starkware.
Setting Up Cairo Environment
Cairo’s compiler has been written in python and the latest cairo version 0.10.3 was tested on python3.9. This is why we’re gonna stick with this and not the latest python version. If you are like me and don’t like importing PPAs on Ubuntu-based distros to install different python versions thenpyenv
is the solution for you. Here is how you setup pyenv:
Install Build Dependencies
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
Use the pyenv installer
curl https://pyenv.run | bash
This installs some other plugins as well like:
pyenv: The actual
pyenv
applicationpyenv-virtulenv: Plugin for
pyenv
and virtual environmentspyenv-update: Plugin for updating
pyenv
pyenv-doctor: Plugin to verify that
pyenv
and build dependencies are installedpyenv-which-ext: Plugin to automatically lookup system commands
At the end of the run, you will see something like this:
WARNING: seems you still have not added 'pyenv' to the load path.
Load pyenv automatically by adding
the following to ~/.bashrc:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
After adding these to your .bashrc
you can restart your shell and pyenv should work.
pyenv install 3.9.13
pyenv install 3.9-dev # this is needed to ensure that Python gets
# imported upon installing packages
Make a Virtual Environment
python3.9 -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate
make sure you can install ecdsa
, fastecdsa
, sympy
using pip3. Also make sure you run:
sudo apt install -y libgmp3-dev
And just install the cairo package.
pip3 install cairo-lang
Checking if it all works
- Create a file named,
test.cairo
with this:
func main(){
[ap] = 1000, ap++;
[ap] = 2000, ap++;
[ap] = [ap - 2] + [ap - 1], ap++;
ret;
}
- Compile it:
cairo-compile test.cairo --output test_compiled.json
- Run:
cairo-run \
--program=test_compiled.json --print_output \
--print_info --relocate_prints
And voila! You now have Cairo set up on your system. The following blogs will be about getting started with coding with Cairo and Starknet concepts.