Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for uint256_mul_div_mod possible overflow #1328

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,22 @@ compare_benchmarks: $(COMPILED_BENCHES)
cd bench && ./run_benchmarks.sh

compare_trace_memory: $(CAIRO_RS_TRACE) $(CAIRO_TRACE) $(CAIRO_RS_MEM) $(CAIRO_MEM)
cd src/tests; ./compare_vm_state.sh trace memory
cd vm/src/tests; ./compare_vm_state.sh trace memory

compare_trace: $(CAIRO_RS_TRACE) $(CAIRO_TRACE)
cd src/tests; ./compare_vm_state.sh trace
cd vm/src/tests; ./compare_vm_state.sh trace

compare_memory: $(CAIRO_RS_MEM) $(CAIRO_MEM)
cd src/tests; ./compare_vm_state.sh memory
cd vm/src/tests; ./compare_vm_state.sh memory

compare_trace_memory_proof: $(COMPILED_PROOF_TESTS) $(CAIRO_RS_TRACE_PROOF) $(CAIRO_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF) $(CAIRO_MEM_PROOF)
cd src/tests; ./compare_vm_state.sh trace memory proof_mode
cd vm/src/tests; ./compare_vm_state.sh trace memory proof_mode

compare_trace_proof: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_TRACE_PROOF)
cd src/tests; ./compare_vm_state.sh trace proof_mode
cd vm/src/tests; ./compare_vm_state.sh trace proof_mode

compare_memory_proof: $(CAIRO_RS_MEM_PROOF) $(CAIRO_MEM_PROOF)
cd src/tests; ./compare_vm_state.sh memory proof_mode
cd vm/src/tests; ./compare_vm_state.sh memory proof_mode

# Run with nightly enable the `doc_cfg` feature wich let us provide clear explaination about which parts of the code are behind a feature flag
docs:
Expand Down
10 changes: 10 additions & 0 deletions cairo_programs/uint256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func main{range_check_ptr: felt}() {
assert b_quotient_high = Uint256(0, 0);
assert b_remainder = Uint256(170141183460469231731687303715884105854, 1);

let (c_quotient_low, c_quotient_high, c_remainder) = uint256_mul_div_mod(
Uint256(340281070833283907490476236129005105807, 340282366920938463463374607431768211455),
Uint256(2447157533618445569039502, 0),
Uint256(0, 1),
);

assert c_quotient_low = Uint256(340282366920938463454053728725133866491, 2447157533618445569039501);
assert c_quotient_high = Uint256(0, 0);
assert c_remainder = Uint256(326588112914912836985603897252688572242, 0);

let (mult_low_a, mult_high_a) = uint256_mul(Uint256(59, 2), Uint256(10, 0));
assert mult_low_a = Uint256(590, 20);
assert mult_high_a = Uint256(0, 0);
Expand Down