clementwalter / cairo-vm-gs Goto Github PK
View Code? Open in Web Editor NEWA google app script implementation of the Cairo VM
Home Page: https://cairovm.gs
A google app script implementation of the Cairo VM
Home Page: https://cairovm.gs
Currently, the VM logic optimistically fills the memory to fit the res logic and opcode. There is however no check that the operation is legit. For example, an assert 0 = 1
would just lead to a memory written to 0, then overridden to 1.
Raise in step
when the operation is not possible
The project currently uses vanilla js. It would be better (easier to maintain, to understand) to use typescript.
Rewrite all the codebase in typescript
types.ts
file gathering all the typesIn the current PoC, there is only a step
method that generate the next step of the VM. We need a method to make the whole run directly as well
Create a run method, and a Run menu item, to end the run
See the while
loop of the python vm
https://github.com/starkware-libs/cairo-lang/blob/efa9648f57568aad8f8a13fbf027d2de7c63c2c0/src/starkware/cairo/lang/vm/cairo_runner.py#L343
Logic is the same, where the final_pc has been put in the Execution column in the initialize
step (see #3).
The function should at any stage of the run, ie. from the beginning (right after initialization) or after few steps have already been executed.
The cairo VM runs cairo wasm, and cairo0 is very close to it.
poetry init
poetry add cairo-lang
Create a fibonacci.cairo
, fill with a simple function like this one https://github.com/ClementWalter/hello-starknet/blob/main/src/jump.cairo, build and commit
The Cairo VM uses memory segments to track values. In short and almost true, a memory segment is just a list of values, ie. here a list of felt
(felt
is the only native type of cairo, think of felt
as uint252
).
A run of the VM actually consists in filling values in memory segments; allocating a segment just means creating an empty list at index i in the segments manager of the VM, much like
{
0: [],
1: [],
42: [],
}
could be a memory with 3 initialized segments (with indexes 0, 1 and 42).
Segments can be allocated during the run (when the dev uses the alloc()
function) or by the VM itself at the beginning of a run for given builtins. In cairo0, these builtins are declared at the tile level using the % builtin
directive, and at the function level using corresponding implicit arguments.
The list of builtins actually available is:
[
"output",
"pedersen",
"range_check",
"ecdsa",
"bitwise",
"ec_op",
"keccak",
"poseidon",
]
Each builtin requires its own memory segment as these builtins actually enforces some rules over the segment. For example, the range_check
segment will enforce that every values contained in this segment are actually no greater than 2**128
.
Consequently, when initializing the VM for running a program, one needs to create as much memory segments as required.
The Cairo VM gs uses native sheet columns as memory segments.
The function should add the corresponding column with their header as names next to the Execution
column
Follow the python VM https://github.com/starkware-libs/cairo-lang/blob/efa9648f57568aad8f8a13fbf027d2de7c63c2c0/src/starkware/cairo/lang/vm/cairo_runner.py#L216
Note that program_base is always the first segment, and Execution the second.
Add a menu in the UI to actually trigger the call
The CairoVM will for now only run the main entrypoint, so the final fp and pc segments should be added last, and their reference be added in the execution segment.
Currently, the PoC showcase a small fibonacci program copy/pasted. We need to be able to load any compiled artifact instead.
Add a menu in the UI to load a program. This should open a file picker to upload a json file. Once uploaded and validated, the sheet should be updated as follows:
DECODE_INSTRUCTION(A)
as as requiredFor the file picker, check the google doc
For the segment initialization, see #3
The fibonacci example is a very simple function not using any builtins. We want to add simple function with builtins as well.
Copy the file from https://github.com/ClementWalter/hello-starknet/blob/main/src/dict.cairo next to fibonacci, compile and commit result.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.