lambdaclass / cairo-vm

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.
https://lambdaclass.github.io/cairo-vm
Apache License 2.0
517 stars 148 forks source link

Error in Cairo Program Execution: AddressNotRelocatable Issue in PR #1551 #1563

Closed raphaelDkhn closed 9 months ago

raphaelDkhn commented 9 months ago

Describe the bug

Hello @fmoletta, I've come across an issue with your PR #1551 in the cairo1-run environment.

When running the command cargo run ../cairo_programs/cairo-1-programs/with_input/tensor_test.cairo --layout all_cairo --args '[2 2 2 4 1 2 3 4]', an error occurs:

Error: VirtualMachine(Memory(AddressNotRelocatable))

The Cairo program used is as follows:

#[derive(Copy, Drop)]
struct Tensor {
    shape: Span<u32>,
    data: Span<u32>
}

fn main(tensor: Tensor) -> u32 {
    *tensor.data.at(0)
}

Notably, when the Tensor is initialized inside the main function instead of being passed as an argument, the program runs without issues:

#[derive(Copy, Drop)]
struct Tensor {
    shape: Span<u32>,
    data: Span<u32>
}

fn main() -> u32 {
    let tensor = Tensor {
    shape: array![2, 2].span(),
    data: array![1, 2, 3, 4].span(),
    };
    *tensor.data.at(0)
}

Moreover, when I modify the main function to simply return the passed Tensor, like this:

fn main(tensor: Tensor) -> Tensor {
    tensor
}

It works correctly, which suggests that the argument passing mechanism for structs is functioning well.

What version/commit are you on? Current Version/Commit: Branch cairo-1-input-args

fmoletta commented 9 months ago

Hello! a fix related to this problem was recently merged in the cairo repo, I already applied it to our mirrored code in PR #1551. Running cargo run ../cairo_programs/cairo-1-programs/tensor.cairo --layout all_cairo --args '[2 2] [1 2 3 4]' should now work. (Note: the Tensor struct consists of two spans, so we need to input two separate arrays, --args '[2 2 1 2 3 4]' will not work)

raphaelDkhn commented 9 months ago

Thank you a lot, it's working well !