Skip to content

Conversation

@enitrat
Copy link
Contributor

@enitrat enitrat commented Feb 26, 2025

Fix handling of unfilled values in mul mod runner

Description

Closes #1975
Description of the pull request changes and motivation.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

@JulianGCalderon
Copy link
Contributor

Hi @enitrat! Thanks for the contribution.

  • Could you update the changelog?
  • Also, do you have an example of a program that causes an infinite loop?. Could you add it as a test?

@enitrat
Copy link
Contributor Author

enitrat commented Feb 28, 2025

Hi @JulianGCalderon, I'll try to push the program next week. I think it was this one:

func assert_neq{range_check96_ptr: felt*, add_mod_ptr: ModBuiltin*, mul_mod_ptr: ModBuiltin*}(
    x: UInt384*, y: UInt384*, p: UInt384*
) {
    let (_, pc) = get_fp_and_pc();

    pc_label:
    let add_mod_offsets_ptr = pc + (add_offsets - pc_label);
    let mul_mod_offsets_ptr = pc + (mul_offsets - pc_label);

    assert [range_check96_ptr + 0] = 1;
    assert [range_check96_ptr + 1] = 0;
    assert [range_check96_ptr + 2] = 0;
    assert [range_check96_ptr + 3] = 0;
    assert [range_check96_ptr + 4] = 0;
    assert [range_check96_ptr + 5] = 0;
    assert [range_check96_ptr + 6] = 0;
    assert [range_check96_ptr + 7] = 0;

    assert [range_check96_ptr + 8] = x.d0;
    assert [range_check96_ptr + 9] = x.d1;
    assert [range_check96_ptr + 10] = x.d2;
    assert [range_check96_ptr + 11] = x.d3;
    assert [range_check96_ptr + 12] = y.d0;
    assert [range_check96_ptr + 13] = y.d1;
    assert [range_check96_ptr + 14] = y.d2;
    assert [range_check96_ptr + 15] = y.d3;

    run_mod_p_circuit(
        p=[p],
        values_ptr=cast(range_check96_ptr, UInt384*),
        add_mod_offsets_ptr=add_mod_offsets_ptr,
        add_mod_n=2,
        mul_mod_offsets_ptr=mul_mod_offsets_ptr,
        mul_mod_n=1,
    );

    let range_check96_ptr = range_check96_ptr + 28;

    return ();

    add_offsets:
    dw 4;
    dw 0;
    dw 16;
    dw 20;
    dw 12;
    dw 8;

    mul_offsets:
    dw 24;
    dw 20;
    dw 16;
}

with a specific set of inputs.

@enitrat
Copy link
Contributor Author

enitrat commented Mar 10, 2025

hey @JulianGCalderon i haven't been able to retrieve the exact set of inputs that lead to this condition as it was discovered in our fuzzing process and we've made breaking changes since then. The fix still holds but I wont be able to submit a program that triggers it. I update the changelog

@edg-l edg-l requested a review from noaov1 as a code owner March 11, 2025 14:24
@enitrat enitrat force-pushed the fix/mulmod-unfilled-value branch from a317e2c to 88d7cda Compare March 11, 2025 14:33
@enitrat enitrat force-pushed the fix/mulmod-unfilled-value branch from 88d7cda to df347dc Compare March 11, 2025 14:34
@JulianGCalderon
Copy link
Contributor

Hyper Thereading Benchmark results

hyperfine -r 2 -n "hyper_threading_main threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_main' -n "hyper_threading_pr threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 1
Time (mean ± σ): 26.410 s ± 0.015 s [User: 25.658 s, System: 0.750 s]
Range (min … max): 26.400 s … 26.421 s 2 runs

Benchmark 2: hyper_threading_pr threads: 1
Time (mean ± σ): 26.352 s ± 0.022 s [User: 25.619 s, System: 0.731 s]
Range (min … max): 26.336 s … 26.367 s 2 runs

Summary
hyper_threading_pr threads: 1 ran
1.00 ± 0.00 times faster than hyper_threading_main threads: 1

hyperfine -r 2 -n "hyper_threading_main threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_main' -n "hyper_threading_pr threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 2
Time (mean ± σ): 14.659 s ± 0.003 s [User: 25.768 s, System: 0.740 s]
Range (min … max): 14.656 s … 14.661 s 2 runs

Benchmark 2: hyper_threading_pr threads: 2
Time (mean ± σ): 14.793 s ± 0.164 s [User: 25.893 s, System: 0.771 s]
Range (min … max): 14.677 s … 14.909 s 2 runs

Summary
hyper_threading_main threads: 2 ran
1.01 ± 0.01 times faster than hyper_threading_pr threads: 2

hyperfine -r 2 -n "hyper_threading_main threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_main' -n "hyper_threading_pr threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 4
Time (mean ± σ): 10.986 s ± 0.007 s [User: 38.148 s, System: 0.968 s]
Range (min … max): 10.982 s … 10.991 s 2 runs

Benchmark 2: hyper_threading_pr threads: 4
Time (mean ± σ): 10.353 s ± 0.025 s [User: 38.517 s, System: 0.927 s]
Range (min … max): 10.335 s … 10.370 s 2 runs

Summary
hyper_threading_pr threads: 4 ran
1.06 ± 0.00 times faster than hyper_threading_main threads: 4

hyperfine -r 2 -n "hyper_threading_main threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_main' -n "hyper_threading_pr threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 6
Time (mean ± σ): 10.342 s ± 0.035 s [User: 38.838 s, System: 0.929 s]
Range (min … max): 10.317 s … 10.366 s 2 runs

Benchmark 2: hyper_threading_pr threads: 6
Time (mean ± σ): 10.689 s ± 0.046 s [User: 38.026 s, System: 0.933 s]
Range (min … max): 10.656 s … 10.721 s 2 runs

Summary
hyper_threading_main threads: 6 ran
1.03 ± 0.01 times faster than hyper_threading_pr threads: 6

hyperfine -r 2 -n "hyper_threading_main threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_main' -n "hyper_threading_pr threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 8
Time (mean ± σ): 10.286 s ± 0.019 s [User: 38.742 s, System: 0.942 s]
Range (min … max): 10.272 s … 10.299 s 2 runs

Benchmark 2: hyper_threading_pr threads: 8
Time (mean ± σ): 10.394 s ± 0.044 s [User: 38.682 s, System: 0.932 s]
Range (min … max): 10.363 s … 10.425 s 2 runs

Summary
hyper_threading_main threads: 8 ran
1.01 ± 0.00 times faster than hyper_threading_pr threads: 8

hyperfine -r 2 -n "hyper_threading_main threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_main' -n "hyper_threading_pr threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 16
Time (mean ± σ): 10.437 s ± 0.242 s [User: 39.125 s, System: 1.065 s]
Range (min … max): 10.266 s … 10.608 s 2 runs

Benchmark 2: hyper_threading_pr threads: 16
Time (mean ± σ): 10.281 s ± 0.013 s [User: 39.143 s, System: 1.047 s]
Range (min … max): 10.272 s … 10.290 s 2 runs

Summary
hyper_threading_pr threads: 16 ran
1.02 ± 0.02 times faster than hyper_threading_main threads: 16

@JulianGCalderon
Copy link
Contributor

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.157 ± 0.032 2.131 2.234 1.00
head big_factorial 2.157 ± 0.044 2.122 2.260 1.00 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.077 ± 0.010 2.063 2.094 1.00
head big_fibonacci 2.090 ± 0.022 2.066 2.149 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.975 ± 0.139 7.807 8.302 1.01 ± 0.02
head blake2s_integration_benchmark 7.902 ± 0.093 7.821 8.149 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.208 ± 0.033 2.176 2.290 1.00 ± 0.02
head compare_arrays_200000 2.198 ± 0.016 2.172 2.221 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.452 ± 0.014 1.437 1.475 1.00
head dict_integration_benchmark 1.457 ± 0.008 1.448 1.477 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.235 ± 0.008 1.226 1.248 1.00
head field_arithmetic_get_square_benchmark 1.240 ± 0.008 1.228 1.253 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.925 ± 0.054 7.834 8.010 1.00
head integration_builtins 7.996 ± 0.183 7.833 8.444 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.248 ± 0.046 8.178 8.320 1.00 ± 0.01
head keccak_integration_benchmark 8.232 ± 0.102 8.124 8.462 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.186 ± 0.026 2.158 2.244 1.00
head linear_search 2.195 ± 0.025 2.157 2.243 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.527 ± 0.005 1.518 1.535 1.00
head math_cmp_and_pow_integration_benchmark 1.541 ± 0.012 1.529 1.571 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.477 ± 0.012 1.466 1.503 1.00
head math_integration_benchmark 1.477 ± 0.007 1.469 1.494 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.235 ± 0.005 1.225 1.242 1.00
head memory_integration_benchmark 1.239 ± 0.006 1.233 1.255 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.592 ± 0.017 1.576 1.634 1.00
head operations_with_data_structures_benchmarks 1.600 ± 0.013 1.582 1.622 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 536.4 ± 2.6 533.0 542.0 1.00
head pedersen 536.5 ± 3.0 532.7 543.8 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 632.4 ± 4.7 624.7 637.1 1.01 ± 0.01
head poseidon_integration_benchmark 629.0 ± 2.7 626.7 635.5 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.879 ± 0.006 1.873 1.896 1.00
head secp_integration_benchmark 1.892 ± 0.014 1.875 1.920 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 629.7 ± 2.4 627.5 636.1 1.00
head set_integration_benchmark 630.2 ± 2.3 627.2 634.4 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint[25](https://github.com/lambdaclass/cairo-vm/actions/runs/13906263955/job/38910013391?pr=1976#step:8:26)6_integration_benchmark 4.344 ± 0.048 4.275 4.430 1.00 ± 0.01
head uint256_integration_benchmark 4.338 ± 0.043 4.285 4.414 1.00

@JulianGCalderon
Copy link
Contributor

I've added a test for the failing case. It should be good to merge now.

@gabrielbosio gabrielbosio enabled auto-merge March 17, 2025 23:17
@gabrielbosio gabrielbosio added this pull request to the merge queue Mar 17, 2025
Merged via the queue into lambdaclass:main with commit 9690634 Mar 18, 2025
181 of 184 checks passed
gabrielbosio added a commit that referenced this pull request May 21, 2025
* fix: handle unfilled values in mul mod runner

* update changelog

* Move changelog entry

* Remove whiteline

* Add test

---------

Co-authored-by: Gabriel Bosio <[email protected]>
Co-authored-by: Julián González Calderón <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Missing Error Handling in ModBuiltinRunner::fill_value

4 participants