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
504 stars 138 forks source link

Broken serialization for cairo programs returning tuples with arrays in cairo 1 with `print_output` flag #1644

Closed fmoletta closed 6 months ago

fmoletta commented 6 months ago

Describe the bug When running a program that returns a tuple with an array and an integer value, serialization fails.

To Reproduce Steps to reproduce the behavior:

Run the following cairo 1 program with print_output flag enabled:

use core::array::ArrayTrait;

fn main() -> (Array<u32>, u32) {
    let mut numbers = ArrayTrait::new();
    numbers.append(1);

    (numbers, 1)
}

See error:

Format error

Expected behavior The serialized output should be "[1] 1" instead of an error

What version/commit are you on? commit 4c08af0bee6f0106649b8efc24b8e2ca459895ba

Additional context The behaviour added by PR #1630 imposes the condition that iter.len() + 1) % 2) == 0 (ref) needs to be true in order to process a return value as an array, this works if the return value is only an array, or a tuple with the array at the end, but it breaks as soon as we add a single-felt value after the array in the return values