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

How to directly execute a Sierra program in vm #1906

Open
Subway2023 opened this issue Jan 3, 2025 · 6 comments
Open

How to directly execute a Sierra program in vm #1906

Subway2023 opened this issue Jan 3, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@Subway2023
Copy link

I want to directly execute a Sierra program, but I don't know how to construct contracts_info.

pub fn load_sierra_path(program_path: &str) -> SierraCasmRunner {
    let sierra_code = match fs::read_to_string("some_file_path") {
        Ok(code) => code,
        Err(e) => {
            eprintln!("Failed to read Sierra file: {}", e);
            std::process::exit(1);
        }
    };
    let program = match ProgramParser::new().parse(&sierra_code) {
        Ok(p) => p,
        Err(_) => {
            eprintln!(
                "Failed to parse sierra program."
            );
            std::process::exit(1);
        }
    };

    let runner = SierraCasmRunner::new(
        program.clone(),
        Some(Default::default()),
        contracts_info,    // how to construct contracts_info.
        None,
    )
    .unwrap();

    runner
}
@Subway2023 Subway2023 added the enhancement New feature or request label Jan 3, 2025
@Subway2023
Copy link
Author

Can contracts_info be generated if only the Sierra program is available? I see that contracts_info requires the cairo program to generate.

@azteca1998
Copy link
Collaborator

It can if you know what it has, but I'll assume you don't.

By Sierra do you mean a JSON with lots of data, or actual Sierra code? If it's a JSON then that information should already be embedded within. If your code is not throwing an error when calling ProgramParser::parse(...) then you most likely have actual Sierra code, which doesn't have that information anymore.

If you can get your hands on the JSON Sierra then you should load it with serde and extract the Program and ContractInfo from there.

@Subway2023
Copy link
Author

In the case where only the Sierra program is available (without a JSON file), how should the ContractInfo be constructed in order to execute the Sierra program?

@azteca1998
Copy link
Collaborator

As I said, you don't have that information therefore you can't do it.

If you absolutely have to then just create this structure manually with the correct contract entry points and their identifiers. Note that we will not be able to help you with that.

@Subway2023
Copy link
Author

ok,thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants