Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to generate trace and memory file using cairo-vm-cli 1.0.1 #1837

Open
anonymouspanda-23 opened this issue Sep 12, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@anonymouspanda-23
Copy link

Describe the bug
When attempting to run the following commands, I get the respective errors.

Command 1: cairo-vm-cli a.cairo

Error 1:

expected value at line 1 column 1
Error: Runner(Program(Parse(Error("expected value", line: 1, column: 1))))

Command 2: cairo-vm-cli a.sierra

Error 2:

expected ident at line 1 column 2
Error: Runner(Program(Parse(Error("expected ident", line: 1, column: 2))))

Command 3: cairo-vm-cli a.casm

Error 3:

expected value at line 1 column 2
Error: Runner(Program(Parse(Error("expected value", line: 1, column: 2))))

To Reproduce

  1. Create a file called a.cairo.
  2. Place the following into a.cairo.
use core::felt252;

fn main() -> felt252 {
    let n = 2 + 3;
    n
}
  1. In the same directory, create a Dockerfile.
  2. Add the following into the Dockerfile.
FROM debian:stable-slim

COPY *.cairo .
COPY *.sh .

RUN chmod +x prepare-env.sh

ENTRYPOINT [ "bash", "-c", "./prepare-env.sh && tail -f /dev/null" ]
  1. In the same directory, create a file called prepare-env.sh.
  2. Add the following into prepare-env.sh.
#!/bin/bash

# Update and upgrade packages.
apt-get update -y
apt-get upgrade -y

# Install dependencies
apt-get install apt-utils -y
apt-get install curl -y
apt-get install git-all -y

# Clean up
apt autoremove

# Install Starkli
curl https://get.starkli.sh | sh
PATH=$PATH:$HOME/.starkli/bin
starkliup -v v0.3.4
echo starkli --version

# Install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
echo "export PATH=\"$HOME/.cargo/bin:$PATH\"" >> ~/.bashrc
source $HOME/.cargo/env
cargo test

# Install Scarb
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh
echo "export PATH=\"$HOME/.local/bin:$PATH\"" >> ~/.bashrc

# Install Starknet Foundry
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
echo "export PATH=\"$HOME/.local/bin:$PATH\"" >> ~/.bashrc
snfoundryup

source ~/.bashrc

# Ensure the installation path is in /root/.local/bin, since it's installed for root
if ! command -v scarb &> /dev/null
then
    echo "scarb installation failed or PATH is not correctly set."
    echo "Current PATH: $PATH"
    exit 1
fi

# Verify Scarb installation
scarb --version

# Install Cairo-VM
git clone https://github.com/lambdaclass/cairo-vm.git
cd cairo-vm
make build-cairo-1-compiler

# Return to original directory.
cd /

# Compile Cairo to Sierra to CASM
cairo-compile a.cairo a.sierra
sierra-compile a.sierra a.casm

# Execute the main container command.
exec "$@"
source ~/.bashrc
  1. In the same directory, run docker build -t proof-generator:latest .
  2. In the same directory, run docker run proof-generator:latest

Expected behavior
I expect the output of the program to be shown, which is 5 in this case.

What version/commit are you on?
I am using cairo-vm-cli v1.0.1, cairo-lang-compiler v1.1.1, and cairo-lang-sierra-to-casm v1.1.1.

Additional context
I have tried different compiler versions, the different make commands, different Cairo codes and none of them have worked yet. Also, a.casm matches what I expected given the code on the hosted cairo-vm.

@anonymouspanda-23 anonymouspanda-23 added the bug Something isn't working label Sep 12, 2024
@anonymouspanda-23
Copy link
Author

Update: I have managed to get a JSON in a similar format to the one shown in cairo_programs/manually_compiled, however it still does not return a trace and memory proof using cairo-vm-cli.

  1. Create a file called starknet_sample.cairo
  2. Copy the following into the newly created file.
#[contract]
mod Ownable {
    use starknet::ContractAddress;
    use starknet::get_caller_address;

    #[event]
    fn OwnershipTransferred(previous_owner: ContractAddress, new_owner: ContractAddress) {}

    struct Storage {
        owner: ContractAddress,
    }

    #[constructor]
    fn constructor(init_owner: ContractAddress) {
        owner::write(init_owner);
    }

    #[view]
    fn get_owner() -> ContractAddress {
        owner::read()
    }

    #[external]
    fn transfer_ownership(new_owner: ContractAddress) {
        only_owner();
        let previous_owner = owner::read();
        owner::write(new_owner);
        OwnershipTransferred(previous_owner, new_owner);
    }

    fn only_owner() {
        let caller = get_caller_address();
        assert(caller == owner::read(), 'Caller is not the owner');
    }
}
  1. Run starknet-compile starknet_sample.cairo starknet_sample.sierra
  2. Run starknet-sierra-compile starknet_sample.sierra starknet_sample.json
  3. Run cairo-vm-cli starknet_sample.json

Running step 5 gives the following error:

root@8a59b77272b2:/# cairo-vm-cli starknet_sample.json                  
invalid type: sequence, expected a map at line 1067 column 11
Error: Runner(Program(Parse(Error("invalid type: sequence, expected a map", line: 1067, column: 11))))

Note that the software versions have not changed.

@neilscallywag
Copy link

ups

@FrancoGiachetta
Copy link
Contributor

FrancoGiachetta commented Dec 12, 2024

Hi @anonymouspanda-23
Were you able to make it work? I was following you instructions you've passed to replicate the error, but starknet-compile fails to compile the .cairo to .sierra. I think the example code in starknet_sample.cairo might not be correct.

error: Plugin diagnostic: The 'contract' attribute was deprecated, please use `starknet::contract` instead.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:1:1
#[contract]
^*********^

error: Plugin diagnostic: Unsupported attribute.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:1:1
#[contract]
^*********^

error: Plugin diagnostic: Unsupported attribute.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:18:5
    #[view]
    ^*****^

error: Identifier not found.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:15:9
        owner::write(init_owner);
        ^***^

error: Identifier not found.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:20:9
        owner::read()
        ^***^

error: Identifier not found.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:26:30
        let previous_owner = owner::read();
                             ^***^

error: Identifier not found.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:27:9
        owner::write(new_owner);
        ^***^

error: Identifier not found.
 --> /Users/franco/Documents/Projects/cairo-vm/starknet_sample.cairo:33:26
        assert(caller == owner::read(), 'Caller is not the owner');
                         ^***^

Error: Compilation failed.

@FrancoGiachetta
Copy link
Contributor

The error you are getting is due to the fact that cairo-vm-cli only works with cairo 0. This explains why you are getting parse errors. You should try using cairo1-run instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants