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
488 stars 133 forks source link

Panic in `cairo1-run` when printing the output of a Cairo program that initializes a struct from a function #1670

Closed raphaelDkhn closed 4 months ago

raphaelDkhn commented 4 months ago

Describe the bug

Hi, cairo1-run panics when I run cargo run programs/tensor_fp.sierra --layout all_cairo --print_output of the following Cairo program:

use orion::numbers::{FP16x16, FixedTrait};
use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor};

fn main() -> Tensor<FP16x16> {
     TensorTrait::new(
         array![1, 2].span(),
         array![
           FixedTrait::new(1, false), 
           FixedTrait::new(1, true)
         ].span()
    )
}
>>>
thread 'main' panicked at cairo1-run/src/cairo_run.rs:795:56:
called `Result::unwrap()` on an `Err` value: RelocatableSubDiffIndex((Relocatable { segment_index: 7, offset: 0 }, Relocatable { segment_index: 6, offset: 2 }))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

However when I initialize Tensor and FP16x16 structs without the new function as follow it returns the correct output:

use orion::numbers::{FP16x16, FixedTrait};
use orion::operators::tensor::{Tensor, TensorTrait, FP16x16Tensor};

fn main() -> Tensor<FP16x16> {
    Tensor {
        data: array![
            FP16x16 { mag: 1, sign: false }, 
            FP16x16 { mag: 2, sign: true },
        ].span(),
        shape: array![1, 2].span()
    }
}
>>>
Program Output : [1 2] [1 false 2 true]

What version/commit are you on? I get this issue when I'm using this PR #1665 (cc. @fmoletta)

Additional context Here are the initialized function new of Tensor and FP16x16 on Orion lib.

fmoletta commented 4 months ago

Hello! Thanks for reporting this! I just pushed a fix to #1665

raphaelDkhn commented 4 months ago

Thank you @fmoletta for the follow up, it's perfectly working!