-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into add-divrem-hints
- Loading branch information
Showing
26 changed files
with
2,139 additions
and
29 deletions.
There are no files selected for viewing
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,31 @@ | ||
%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 (); | ||
} |
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,13 @@ | ||
%builtins ecdsa | ||
from starkware.cairo.common.cairo_builtins import SignatureBuiltin | ||
from starkware.cairo.common.signature import verify_ecdsa_signature | ||
|
||
func main{ecdsa_ptr: SignatureBuiltin*}() { | ||
verify_ecdsa_signature( | ||
2718, | ||
1735102664668487605176656616876767369909409133946409161569774794110049207117, | ||
3086480810278599376317923499561306189851900463386393948998357832163236918254, | ||
598673427589502599949712887611119751108407514580626464031881322743364689811, | ||
); | ||
return (); | ||
} |
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,29 @@ | ||
%builtins range_check | ||
|
||
from starkware.cairo.common.dict_access import DictAccess | ||
from starkware.cairo.common.dict import dict_write, dict_update, dict_squash | ||
from starkware.cairo.common.default_dict import default_dict_new | ||
|
||
func main{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 (); | ||
} |
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,42 @@ | ||
%builtins range_check | ||
|
||
from starkware.cairo.common.math import assert_le | ||
from starkware.cairo.common.math import split_felt | ||
|
||
func split_felt_manual_implemetation{range_check_ptr}(value) -> (high: felt, low: felt) { | ||
// Note: the following code works because PRIME - 1 is divisible by 2**128. | ||
const MAX_HIGH = (-1) / 2 ** 128; | ||
const MAX_LOW = 0; | ||
|
||
// Guess the low and high parts of the integer. | ||
let low = [range_check_ptr]; | ||
let high = [range_check_ptr + 1]; | ||
let range_check_ptr = range_check_ptr + 2; | ||
|
||
%{ | ||
from starkware.cairo.common.math_utils import assert_integer | ||
assert ids.MAX_HIGH < 2**128 and ids.MAX_LOW < 2**128 | ||
assert PRIME - 1 == ids.MAX_HIGH * 2**128 + ids.MAX_LOW | ||
assert_integer(ids.value) | ||
ids.low = ids.value & ((1 << 128) - 1) | ||
ids.high = ids.value >> 128 | ||
%} | ||
|
||
assert value = high * (2 ** 128) + low; | ||
if (high == MAX_HIGH) { | ||
assert_le(low, MAX_LOW); | ||
} else { | ||
assert_le(high, MAX_HIGH - 1); | ||
} | ||
return (high=high, low=low); | ||
} | ||
|
||
func main{range_check_ptr: felt}() { | ||
let (m, n) = split_felt_manual_implemetation(5784800237655953878877368326340059594760); | ||
assert m = 17; | ||
assert n = 8; | ||
let (x, y) = split_felt(5784800237655953878877368326340059594760); | ||
assert x = 17; | ||
assert y = 8; | ||
return (); | ||
} |
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,33 @@ | ||
%builtins range_check | ||
|
||
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 main{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 (); | ||
} |
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
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
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
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
Oops, something went wrong.