Skip to content

Latest commit

 

History

History
109 lines (90 loc) · 2.9 KB

1.environment-setup.md

File metadata and controls

109 lines (90 loc) · 2.9 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

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

Step 2 : Compile a Cairo program

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.

  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 contracts/test.cairo --output build/test_compiled.json

Step 3 : Run

Now run.

# cairo-run --program=build/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