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

Add `print_output` flag to `cairo-1` crate #1575

Closed fmoletta closed 9 months ago

fmoletta commented 9 months ago

When activating the print_output flag, the program output will be serialized and printed out by the CLI. This new serialization will recursively fetch arrays from memory and print them out instead of just showing the start and end addresses for the top-level array. For this example program:

use core::array::SpanTrait;
use core::array::ArrayTrait;

fn main() -> Array<Array<u32>> {
    let mut numbers = ArrayTrait::new();
    let mut numbers_a = ArrayTrait::new();
    let mut numbers_b = ArrayTrait::new();
    numbers_a.append(4_u32);
    numbers_a.append(3_u32);
    numbers_b.append(2_u32);
    numbers_b.append(1_u32);
    numbers.append(numbers_a);
    numbers.append(numbers_b);

    numbers
}

Current output (main branch), no flags:

Return values : [5:0, 5:4]

New output, print_output flag:

Program Output : [[4 3] [2 1]]

No output will be shown if print_output is not enabled (unless the program returns a panic result)

The decision to lock the output behind a cli flag is both to match the standard behaviour we have in the cairo-vm-cli crate for cairo 0 execution and to avoid having to execute the argument serialization logic when outputs are not needed

Addresses #1564

github-actions[bot] commented 9 months ago

Benchmark Results for unmodified programs :rocket:

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.242 ± 0.005 2.233 2.250 1.00
head big_factorial 2.247 ± 0.008 2.235 2.260 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.229 ± 0.009 2.219 2.244 1.01 ± 0.00
head big_fibonacci 2.217 ± 0.006 2.212 2.233 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 8.195 ± 0.052 8.150 8.325 1.00 ± 0.01
head blake2s_integration_benchmark 8.181 ± 0.053 8.124 8.271 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.284 ± 0.042 2.255 2.397 1.00 ± 0.02
head compare_arrays_200000 2.277 ± 0.011 2.264 2.297 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.438 ± 0.014 1.430 1.476 1.00
head dict_integration_benchmark 1.444 ± 0.007 1.437 1.458 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.288 ± 0.008 1.276 1.300 1.00
head field_arithmetic_get_square_benchmark 1.288 ± 0.007 1.281 1.299 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 8.236 ± 0.054 8.164 8.313 1.00 ± 0.01
head integration_builtins 8.200 ± 0.064 8.148 8.333 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.490 ± 0.072 8.431 8.601 1.00 ± 0.01
head keccak_integration_benchmark 8.487 ± 0.046 8.429 8.597 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.307 ± 0.010 2.288 2.326 1.00
head linear_search 2.325 ± 0.012 2.312 2.352 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.559 ± 0.004 1.553 1.567 1.00 ± 0.01
head math_cmp_and_pow_integration_benchmark 1.557 ± 0.008 1.550 1.575 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.430 ± 0.003 1.426 1.435 1.00
head math_integration_benchmark 1.431 ± 0.011 1.422 1.461 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.255 ± 0.010 1.245 1.280 1.00 ± 0.01
head memory_integration_benchmark 1.252 ± 0.006 1.246 1.268 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.601 ± 0.003 1.597 1.608 1.00 ± 0.00
head operations_with_data_structures_benchmarks 1.600 ± 0.007 1.595 1.618 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 602.5 ± 2.6 599.8 608.9 1.00 ± 0.00
head pedersen 602.3 ± 1.2 600.5 604.0 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.055 ± 0.006 1.048 1.063 1.00 ± 0.01
head poseidon_integration_benchmark 1.055 ± 0.005 1.046 1.058 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.931 ± 0.004 1.926 1.936 1.00
head secp_integration_benchmark 1.941 ± 0.011 1.933 1.972 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 748.0 ± 1.3 746.5 750.4 1.00
head set_integration_benchmark 748.9 ± 1.3 747.7 751.7 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.539 ± 0.036 4.500 4.611 1.00
head uint256_integration_benchmark 4.540 ± 0.024 4.520 4.584 1.00 ± 0.01
codecov[bot] commented 9 months ago

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (44c693c) 97.14% compared to head (f1c6731) 97.12%.

Files Patch % Lines
cairo1-run/src/main.rs 72.00% 14 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1575 +/- ## ========================================== - Coverage 97.14% 97.12% -0.03% ========================================== Files 91 91 Lines 37206 37246 +40 ========================================== + Hits 36145 36176 +31 - Misses 1061 1070 +9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.