Skip to content

Latest commit

 

History

History
81 lines (67 loc) · 2.31 KB

1.environment-setup.md

File metadata and controls

81 lines (67 loc) · 2.31 KB

Setting Up the environment

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

Step 1 : Install

It is recommened to work inside a Virtual Env.

python3.7 -m venv ~/cairo_venv
source ~/cairo_venv/bin/activate

Install dependencies and Cairo

# sudo apt install -y libgmp3-dev
# pip3 install ecdsa fastecdsa sympy
# wget https://github.com/starkware-libs/cairo-lang/releases/download/v0.7.0/cairo-lang-0.7.0.zip
# pip3 install ./cairo-lang-0.7.0.zip

More Info : Quickstart

Step 2 : Compile a Cairo program

Open test.cairo

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.

  1. We write 1000 to the first free cell and then we move to the next cell (app++).
  2. We write 2000 to the second free cell and then we move to the next cell (app++).
  3. 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 test.cairo --output test_compiled.json

Step 3 : Run

Now run.

# cairo-run --program=test_compiled.json --print_output --print_info --relocate_prints
Addr  Value
-----------
⋮
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