-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into improve_zerodict
- Loading branch information
Showing
36 changed files
with
821 additions
and
211 deletions.
There are no files selected for viewing
3 changes: 0 additions & 3 deletions
3
integration_tests/cairo_zero_file_tests/test.starknet_with_keccak.cairo
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
integration_tests/cairo_zero_hint_tests/assert_250_bits.small.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// The content of this file has been borrowed from LambdaClass Cairo VM in Rust | ||
// See https://github.com/lambdaclass/cairo-vm/blob/5d1181185a976c77956aaa4247846babd4d0e2df/cairo_programs/assert_250_bit_element_array.cairo | ||
|
||
%builtins range_check | ||
|
||
from starkware.cairo.common.math import assert_250_bit | ||
from starkware.cairo.common.alloc import alloc | ||
|
||
func assert_250_bit_element_array{range_check_ptr: felt}( | ||
array: felt*, array_length: felt, iterator: felt | ||
) { | ||
if (iterator == array_length) { | ||
return (); | ||
} | ||
assert_250_bit(array[iterator]); | ||
return assert_250_bit_element_array(array, array_length, iterator + 1); | ||
} | ||
|
||
func fill_array(array: felt*, base: felt, step: felt, array_length: felt, iterator: felt) { | ||
if (iterator == array_length) { | ||
return (); | ||
} | ||
assert array[iterator] = base + step * iterator; | ||
return fill_array(array, base, step, array_length, iterator + 1); | ||
} | ||
|
||
func main{range_check_ptr: felt}() { | ||
alloc_locals; | ||
tempvar array_length = 10; | ||
let (array: felt*) = alloc(); | ||
fill_array(array, 70000000000000000000, 300000000000000000, array_length, 0); | ||
assert_250_bit_element_array(array, array_length, 0); | ||
return (); | ||
} |
32 changes: 32 additions & 0 deletions
32
integration_tests/cairo_zero_hint_tests/assert_not_equal.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// The content of this file has been borrowed from LambdaClass Cairo VM in Rust | ||
// See https://github.com/lambdaclass/cairo-vm/blob/5d1181185a976c77956aaa4247846babd4d0e2df/cairo_programs/compare_different_arrays.cairo | ||
|
||
from starkware.cairo.common.math import assert_not_equal | ||
from starkware.cairo.common.alloc import alloc | ||
|
||
func compare_different_arrays(array_a: felt*, array_b: felt*, array_length: felt, iterator: felt) { | ||
if (iterator == array_length) { | ||
return (); | ||
} | ||
assert_not_equal(array_a[iterator], array_b[iterator]); | ||
return compare_different_arrays(array_a, array_b, array_length, iterator + 1); | ||
} | ||
|
||
func fill_array(array: felt*, base: felt, step: felt, array_length: felt, iterator: felt) { | ||
if (iterator == array_length) { | ||
return (); | ||
} | ||
assert array[iterator] = base + step * iterator; | ||
return fill_array(array, base, step, array_length, iterator + 1); | ||
} | ||
|
||
func main() { | ||
alloc_locals; | ||
tempvar array_length = 10; | ||
let (array_a: felt*) = alloc(); | ||
let (array_b: felt*) = alloc(); | ||
fill_array(array_a, 3, 90, array_length, 0); | ||
fill_array(array_b, 7, 3, array_length, 0); | ||
compare_different_arrays(array_a, array_b, array_length, 0); | ||
return (); | ||
} |
15 changes: 15 additions & 0 deletions
15
integration_tests/cairo_zero_hint_tests/assert_not_zero.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// The content of this file has been partially borrowed from LambdaClass Cairo VM in Rust | ||
// See https://github.com/lambdaclass/cairo-vm/blob/5d1181185a976c77956aaa4247846babd4d0e2df/cairo_programs/assert_not_zero.cairo | ||
|
||
from starkware.cairo.common.math import assert_not_zero | ||
|
||
func main() { | ||
assert_not_zero(1); | ||
assert_not_zero(-1); | ||
let x = 500 * 5; | ||
assert_not_zero(x); | ||
tempvar y = -80; | ||
assert_not_zero(y); | ||
return (); | ||
} |
27 changes: 27 additions & 0 deletions
27
integration_tests/cairo_zero_hint_tests/blake.starknet_with_keccak.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// inspired from the blake integration tests in the lambdaclass cairo-vm codebase | ||
|
||
%builtins range_check bitwise | ||
|
||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.cairo_blake2s.blake2s import blake2s | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
|
||
func test_hash{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() { | ||
alloc_locals; | ||
let inputs: felt* = alloc(); | ||
assert inputs[0] = 'Hell'; | ||
assert inputs[1] = 'o Wo'; | ||
assert inputs[2] = 'rld'; | ||
let (local blake2s_ptr_start) = alloc(); | ||
let blake2s_ptr = blake2s_ptr_start; | ||
let (output) = blake2s{range_check_ptr=range_check_ptr, blake2s_ptr=blake2s_ptr}(inputs, 9); | ||
assert output.low = 219917655069954262743903159041439073909; | ||
assert output.high = 296157033687865319468534978667166017272; | ||
return (); | ||
} | ||
|
||
func main{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() { | ||
test_hash(); | ||
|
||
return (); | ||
} |
125 changes: 125 additions & 0 deletions
125
integration_tests/cairo_zero_hint_tests/cmp.small.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// The content of this file has been borrowed from LambdaClass Cairo VM in Rust | ||
// See https://github.com/lambdaclass/cairo-vm/blob/5d1181185a976c77956aaa4247846babd4d0e2df/cairo_programs/math_cmp_and_pow_integration_tests.cairo | ||
|
||
%builtins range_check | ||
|
||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.pow import pow | ||
from starkware.cairo.common.math import assert_le_felt, assert_lt_felt | ||
from starkware.cairo.common.math_cmp import ( | ||
is_not_zero, | ||
is_nn, | ||
is_le, | ||
is_nn_le, | ||
is_in_range, | ||
is_le_felt, | ||
) | ||
|
||
const CONSTANT = 3 ** 10; | ||
const RC_BOUND = 2 ** 128; | ||
|
||
func fill_array_with_pow{range_check_ptr}( | ||
array_start: felt*, base: felt, step: felt, exp: felt, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let (res) = pow(base + step, exp); | ||
assert array_start[iter] = res; | ||
return fill_array_with_pow(array_start, base + step, step, exp, iter + 1, last); | ||
} | ||
|
||
func test_is_not_zero{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_not_zero(base_array[iter]); | ||
assert new_array[iter] = res; | ||
return test_is_not_zero(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_nn{range_check_ptr}(base_array: felt*, new_array: felt*, iter: felt, last: felt) -> ( | ||
) { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_nn(base_array[iter]); | ||
assert new_array[iter] = res; | ||
return test_is_nn(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_le{range_check_ptr}(base_array: felt*, new_array: felt*, iter: felt, last: felt) -> ( | ||
) { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_le(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_le(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_nn_le{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_nn_le(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_nn_le(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_in_range{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_in_range(CONSTANT, base_array[iter], base_array[iter + 1]); | ||
assert new_array[iter] = res; | ||
return test_is_in_range(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func test_is_le_felt{range_check_ptr}( | ||
base_array: felt*, new_array: felt*, iter: felt, last: felt | ||
) -> () { | ||
if (iter == last) { | ||
return (); | ||
} | ||
let res = is_le_felt(base_array[iter], CONSTANT); | ||
assert new_array[iter] = res; | ||
return test_is_le_felt(base_array, new_array, iter + 1, last); | ||
} | ||
|
||
func run_tests{range_check_ptr}(array_len: felt) -> () { | ||
alloc_locals; | ||
let (array: felt*) = alloc(); | ||
fill_array_with_pow(array, 0, 3, 3, 0, array_len); | ||
|
||
let (array_is_not_zero: felt*) = alloc(); | ||
test_is_not_zero(array, array_is_not_zero, 0, array_len); | ||
|
||
let (array_is_nn: felt*) = alloc(); | ||
test_is_nn(array, array_is_nn, 0, array_len); | ||
|
||
let (array_is_le: felt*) = alloc(); | ||
test_is_le(array, array_is_le, 0, array_len); | ||
|
||
let (array_is_nn_le: felt*) = alloc(); | ||
test_is_nn_le(array, array_is_nn_le, 0, array_len); | ||
|
||
let (array_is_in_range: felt*) = alloc(); | ||
test_is_in_range(array, array_is_in_range, 0, array_len - 1); | ||
|
||
let (array_is_le_felt: felt*) = alloc(); | ||
test_is_le_felt(array, array_is_le_felt, 0, array_len); | ||
|
||
return (); | ||
} | ||
|
||
func main{range_check_ptr}() { | ||
run_tests(10); | ||
return (); | ||
} |
70 changes: 70 additions & 0 deletions
70
integration_tests/cairo_zero_hint_tests/dict_squash.small.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
%builtins range_check | ||
|
||
from starkware.cairo.common.default_dict import default_dict_new | ||
from starkware.cairo.common.dict import dict_write, dict_update, dict_squash | ||
from starkware.cairo.common.squash_dict import squash_dict | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.dict_access import DictAccess | ||
|
||
func test_squash_dict{range_check_ptr}() -> () { | ||
alloc_locals; | ||
|
||
let (dict_start: DictAccess*) = alloc(); | ||
|
||
assert dict_start[0] = DictAccess(key=0, prev_value=100, new_value=100); | ||
assert dict_start[1] = DictAccess(key=1, prev_value=50, new_value=50); | ||
assert dict_start[2] = DictAccess(key=0, prev_value=100, new_value=200); | ||
assert dict_start[3] = DictAccess(key=1, prev_value=50, new_value=100); | ||
assert dict_start[4] = DictAccess(key=0, prev_value=200, new_value=300); | ||
assert dict_start[5] = DictAccess(key=1, prev_value=100, new_value=150); | ||
|
||
let dict_end = dict_start + 6 * DictAccess.SIZE; | ||
|
||
// (dict_start, dict_end) now represents the dictionary | ||
// {0: 100, 1: 50, 0: 200, 1: 100, 0: 300, 1: 150}. | ||
|
||
// Squash the dictionary from an array of 6 DictAccess structs | ||
// to an array of 2, with a single DictAccess entry per key. | ||
let (local squashed_dict_start: DictAccess*) = alloc(); | ||
let (squashed_dict_end) = squash_dict{range_check_ptr=range_check_ptr}( | ||
dict_start, dict_end, squashed_dict_start | ||
); | ||
|
||
// Check the values of the squashed_dict | ||
// should be: {0: (100, 300), 1: (50, 150)} | ||
assert squashed_dict_start[0] = DictAccess(key=0, prev_value=100, new_value=300); | ||
assert squashed_dict_start[1] = DictAccess(key=1, prev_value=50, new_value=150); | ||
|
||
return (); | ||
} | ||
|
||
func test_dict_squash{range_check_ptr}() -> () { | ||
let (dict_start) = default_dict_new(17); | ||
let dict_end = dict_start; | ||
dict_write{dict_ptr=dict_end}(0, 1); | ||
dict_write{dict_ptr=dict_end}(1, 10); | ||
dict_write{dict_ptr=dict_end}(2, -2); | ||
dict_update{dict_ptr=dict_end}(0, 1, 2); | ||
dict_update{dict_ptr=dict_end}(0, 2, 3); | ||
dict_update{dict_ptr=dict_end}(0, 3, 4); | ||
dict_update{dict_ptr=dict_end}(1, 10, 15); | ||
dict_update{dict_ptr=dict_end}(1, 15, 20); | ||
dict_update{dict_ptr=dict_end}(1, 20, 25); | ||
dict_update{dict_ptr=dict_end}(2, -2, -4); | ||
dict_update{dict_ptr=dict_end}(2, -4, -8); | ||
dict_update{dict_ptr=dict_end}(2, -8, -16); | ||
let (squashed_dict_start, squashed_dict_end) = dict_squash{range_check_ptr=range_check_ptr}( | ||
dict_start, dict_end | ||
); | ||
assert squashed_dict_end[0] = DictAccess(key=0, prev_value=1, new_value=4); | ||
assert squashed_dict_end[1] = DictAccess(key=1, prev_value=10, new_value=25); | ||
assert squashed_dict_end[2] = DictAccess(key=2, prev_value=-2, new_value=-16); | ||
return (); | ||
} | ||
|
||
func main{range_check_ptr}() { | ||
test_squash_dict(); | ||
test_dict_squash(); | ||
|
||
return (); | ||
} |
Oops, something went wrong.