-
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 branch 'main' into execution-resources
- Loading branch information
Showing
15 changed files
with
1,685 additions
and
11 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 |
---|---|---|
|
@@ -27,3 +27,4 @@ func main{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}() { | |
|
||
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,32 @@ | ||
%builtins range_check | ||
from starkware.cairo.common.cairo_secp.bigint import BigInt3, nondet_bigint3 | ||
struct EcPoint { | ||
x: BigInt3, | ||
y: BigInt3, | ||
} | ||
|
||
func ec_double{range_check_ptr}(point: EcPoint, slope: BigInt3) -> (res: BigInt3) { | ||
%{ | ||
from starkware.cairo.common.cairo_secp.secp_utils import pack | ||
SECP_P = 2**255-19 | ||
slope = pack(ids.slope, PRIME) | ||
x = pack(ids.point.x, PRIME) | ||
y = pack(ids.point.y, PRIME) | ||
value = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P | ||
%} | ||
|
||
let (new_x: BigInt3) = nondet_bigint3(); | ||
return (res=new_x); | ||
} | ||
|
||
func main{range_check_ptr}() { | ||
let p = EcPoint(BigInt3(1,2,3), BigInt3(4,5,6)); | ||
let s = BigInt3(7,8,9); | ||
let (res) = ec_double(p, s); | ||
assert res.d0 = 21935; | ||
assert res.d1 = 12420; | ||
assert res.d2 = 184; | ||
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 @@ | ||
../usort.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,22 @@ | ||
%builtins range_check | ||
from starkware.cairo.common.usort import usort | ||
from starkware.cairo.common.alloc import alloc | ||
|
||
func main{range_check_ptr}() -> () { | ||
alloc_locals; | ||
let (input_array: felt*) = alloc(); | ||
assert input_array[0] = 2; | ||
assert input_array[1] = 1; | ||
assert input_array[2] = 0; | ||
|
||
let (output_len, output, multiplicities) = usort(input_len=3, input=input_array); | ||
|
||
assert output_len = 3; | ||
assert output[0] = 0; | ||
assert output[1] = 1; | ||
assert output[2] = 2; | ||
assert multiplicities[0] = 1; | ||
assert multiplicities[1] = 1; | ||
assert multiplicities[2] = 1; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package hint_codes | ||
|
||
const USORT_ENTER_SCOPE = "vm_enter_scope(dict(__usort_max_size = globals().get('__usort_max_size')))" | ||
|
||
const USORT_BODY = `from collections import defaultdict | ||
input_ptr = ids.input | ||
input_len = int(ids.input_len) | ||
if __usort_max_size is not None: | ||
assert input_len <= __usort_max_size, ( | ||
f"usort() can only be used with input_len<={__usort_max_size}. " | ||
f"Got: input_len={input_len}." | ||
) | ||
positions_dict = defaultdict(list) | ||
for i in range(input_len): | ||
val = memory[input_ptr + i] | ||
positions_dict[val].append(i) | ||
output = sorted(positions_dict.keys()) | ||
ids.output_len = len(output) | ||
ids.output = segments.gen_arg(output) | ||
ids.multiplicities = segments.gen_arg([len(positions_dict[k]) for k in output])` | ||
|
||
const USORT_VERIFY = `last_pos = 0 | ||
positions = positions_dict[ids.value][::-1]` | ||
|
||
const USORT_VERIFY_MULTIPLICITY_ASSERT = "assert len(positions) == 0" | ||
|
||
const USORT_VERIFY_MULTIPLICITY_BODY = `current_pos = positions.pop() | ||
ids.next_item_index = current_pos - last_pos | ||
last_pos = current_pos + 1` |
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.