StarkNet is a permissionless decentralized ZK-Rollup operating as an L2 network over Ethereum, where any dApp can achieve unlimited scale for its computation, without compromising Ethereum’s composability and security.
Cairo is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly. Cairo and similar proof systems can be used to provide scalability to blockchains.
I'm using Ubuntu and Python3.7 installed in my machine
Install needed dependencies
# sudo apt install -y libgmp3-dev python3-dev
I had to install Python3.9
# sudo apt update
# sudo apt install software-properties-common
# sudo add-apt-repository ppa:deadsnakes/ppa
# sudo apt install python3.9
# sudo apt install python3.9-venv python3.9-dev
# python3.9 --version
It is recommened to work inside a Virtual Env.
# mkdir starknet_nfts
# cd starknet_nfts
# python3.9 -m venv env
# source env/bin/activate
Install dependencies and https://starknet.io/docs/quickstart.html
# sudo apt install -y libgmp3-dev
# pip3 install ecdsa fastecdsa sympy wheel
# wget https://github.com/starkware-libs/cairo-lang/releases/download/v0.10.0/cairo-lang-0.10.0.zip
# pip3 install cairo-lang-0.10.0.zip
# cairo-compile --version
More Info : Quickstart
Create test.cairo
# mkdir contracts
# mkdir build
# vi contracts/test.cairo
Edit Test:
func main():
[ap] = 1000; ap++
[ap] = 2000; ap++
[ap] = [ap - 2] + [ap - 1]; ap++
ret
end
ap is the allocation pointer and points to the next unused memory cell.
- We write 1000 to the first free cell and then we move to the next cell (app++).
- We write 2000 to the second free cell and then we move to the next cell (app++).
- We write 3000 (value at allocation pointer - 2 = 1000, value at allocation pointer -1 = 2000) to the third cell and then we move to the next cell (app++).
Compile it.
# cairo-compile contracts/test.cairo --output build/test_compiled.json
Now run.
# cairo-run --program=build/test_compiled.json --print_output --print_info --relocate_prints
⋮ 1 5189976364521848832 2 1000 3 5189976364521848832 4 2000 5 5201798304953696256 6 2345108766317314046 7 12 8 12 9 1000 10 2000 11 3000
Number of steps: 4 (originally, 4) Used memory cells: 11 Register values after execution: pc = 12 ap = 12 fp = 12
The first cells corresponid to the code, and then we are writing to ap 9,10 and 11.
To keep in mind:
- **ap** is the allocation pointer
- **fp** is the frame pointer (value of ap at the beginning of the function.
- **pc** is the program counter.
Important notes