GithubHelp home page GithubHelp logo

lambdaclass / cairo-vm Goto Github PK

View Code? Open in Web Editor NEW
490.0 10.0 137.0 190.61 MB

cairo-vm is a Rust implementation of the Cairo VM. Cairo (CPU Algebraic Intermediate Representation) is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly without the need for this party to re-execute the same program.

Home Page: https://lambdaclass.github.io/cairo-vm

License: Apache License 2.0

Rust 82.14% Makefile 0.64% Shell 0.46% Cairo 15.66% Python 0.67% HTML 0.06% CSS 0.04% JavaScript 0.32%
blockchain compiler programming-language cryptography rust zkp stark

cairo-vm's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cairo-vm's Issues

Document hints

  • Expected output: a good walkthrough on how existing hints work in cairo and oraic

Improve is_zero

Perhaps the is_zero function in vm_core might be improved by using the is_zero method from the num_bigint library instead of constructing a zero value and comparing against it.

Add fuzzing

  • Research which fuzzy testing Rust tool to use.
  • Find possible areas in cleopatra in which to apply fuzzing testing.
  • Expected output: a decision on which fuzzy testing library to use and which tests to add.

Remove all program.json files

Remove all the Cairo compiled programs (program.json files) from the Repo.

Programs should be compiled using the python cairo compiler.

Remove duplicated Memory in VirtualMachine

Currently, VirtualMachine contains a context (RunContext) with a Memory, and it (VirtualMachine) also contains a ValidatedMemoryDict which also contains a Memory. Both of this Memories contain the same information, in order to avoid double reference/ duplication, we could keep only one Memory in VirtualMachine (removing memory from the context and getting rid of ValidatedMemoryDict altogether), and move the validated_addresses to VirtualMachine.

Refactor if clause in verify_auto_deductions function

   pub fn verify_auto_deductions(&mut self) -> Result<(), VirtualMachineError> {
        for (i, segment) in self.memory.data.iter().enumerate() {
            for (j, value) in segment.iter().enumerate() {
                for (name, builtin) in self.builtin_runners.iter_mut() {
                    match builtin.base() {
                        Some(builtin_base) => {
                            if builtin_base.segment_index == i {
                                match builtin.deduce_memory_cell(
                                    &MaybeRelocatable::from((i, j)),
                                    &self.memory,
                                ) {
                                    Ok(None) => None,
                                    Ok(Some(deduced_memory_cell)) => {
                                        if Some(&deduced_memory_cell) != value.as_ref()
                                            && value != &None
                                        {
                                            return Err(
                                                VirtualMachineError::InconsistentAutoDeduction(
                                                    name.to_owned(),
                                                    deduced_memory_cell,
                                                    value.to_owned(),
                                                ),
                                            );
                                        }
                                        Some(deduced_memory_cell)
                                    }
                                    _ => {
                                        return Err(VirtualMachineError::InvalidInstructionEncoding)
                                    }
                                };
                            }
                        }
                        _ => return Err(VirtualMachineError::InvalidInstructionEncoding),
                    }
                }
            }
        }
        Ok(())
    }

Add a CLI option to specify the entrypoint

Currently the entrypoint to the cairo file being run is hardcoded to the main function.
Since we'd like at Onlydust to leverage your VM to build a fast Cairo test runner, we would need to be able to specify a different entrypoint, let's say my_function for example.

I plan to work on this, I open the issue to start the conversation and get your point of view on this.

cleopatra vm fail to run my cairo program

Here is my code:

%builtins output pedersen

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.hash import hash2

func main{output_ptr, pedersen_ptr: HashBuiltin*}():
    let (res) = hash2{hash_ptr=pedersen_ptr}(1, 2)

    res = [output_ptr]

    let output_ptr = output_ptr + 1
    return()
end

cairo-compile && cairo-run works

cairo-compile check_hash.cairo --output check_hash_compiled.json
cairo-run --program=check_hash_compiled.json --layout=small --print_output 
Program output:
  -1025514936890165471153863463586721648332140962090141185746964417035414175707

But cleaopatra doesn't

cargo run -- ~/Documents/rusty-crew/cairo_test/check_hash_compiled.json  
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/cleopatra-run /Users/tdelabro/Documents/rusty-crew/cairo_test/check_hash_compiled.json`
thread 'main' panicked at 'Couldn't compute or deduce op1', src/vm/vm_core.rs:441:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Why is that ?

Research cross-platform tests

Eventually, we will want to have tests that ensure parity across Cairo VM implementations.
How exactly to achieve that is an open question, but it will likely involve a Python testing framework.

  • Research and document
    • how tests are run in the cairo-lang repositor,
    • what kind of tests they are,
    • what they test,
    • what dependencies they have
    • and if possible, how they could be made vm-agnostic.

Expected outcome: a through discussion on how to test results of different vm implementations.

Add --memory_file

We should be able to output the relocated memory to a file like cairo_run does.

Research using kani

Rustdoc documentation

  • The rustdoc comments should be polished and expanded in general.
  • cleopatra is yet green to publish to crate.io and thus docs.rs but perhaps work could be done on the CI to add the rendered docs to the repo's github pages.

Discuss and analyze webassembly security

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.