Skip to content

Commit dfa4ee8

Browse files
Add constant_collision.cairo example
1 parent 39f5bd5 commit dfa4ee8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
%builtins range_check
2+
3+
from starkware.cairo.common.math import assert_le
4+
from starkware.cairo.common.math import split_felt
5+
6+
func override_constants{range_check_ptr}() {
7+
const MAX_HIGH = -1;
8+
const MAX_LOW = -1;
9+
return ();
10+
}
11+
func split_felt_ok{range_check_ptr}(value) -> (high: felt, low: felt) {
12+
const MAX_HIGH = (-1) / 2 ** 128;
13+
const MAX_LOW = 0;
14+
let low = [range_check_ptr];
15+
let high = [range_check_ptr + 1];
16+
let range_check_ptr = range_check_ptr + 2;
17+
18+
%{
19+
from starkware.cairo.common.math_utils import assert_integer
20+
assert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128
21+
assert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW
22+
assert_integer(ids.value)
23+
ids.low = ids.value & ((1 << 128) - 1)
24+
ids.high = ids.value >> 128
25+
%}
26+
27+
assert value = high * (2 ** 128) + low;
28+
if (high == MAX_HIGH) {
29+
assert_le(low, MAX_LOW);
30+
} else {
31+
assert_le(high, MAX_HIGH - 1);
32+
}
33+
return (high=high, low=low);
34+
}
35+
36+
func main{range_check_ptr: felt}() {
37+
let (m, n) = split_felt_ok(5784800237655953878877368326340059594760);
38+
assert m = 17;
39+
assert n = 8;
40+
return ();
41+
}

vm/src/tests/cairo_run_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,10 @@ fn cairo_run_data_availability_reduced_mul() {
13611361
include_bytes!("../../../cairo_programs/cairo-0-kzg-da-hints/reduced_mul.json");
13621362
run_program_simple(program_data.as_slice());
13631363
}
1364+
1365+
#[test]
1366+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
1367+
fn constant_collision() {
1368+
let program_data = include_bytes!("../../../cairo_programs/constant_collision.json");
1369+
run_program_simple(program_data.as_slice());
1370+
}

0 commit comments

Comments
 (0)