-
Notifications
You must be signed in to change notification settings - Fork 133
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 newhint45-u128_add
- Loading branch information
Showing
19 changed files
with
1,086 additions
and
137 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
36 changes: 36 additions & 0 deletions
36
cairo_programs/benchmarks/field_arithmetic_get_square_benchmark.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,36 @@ | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.bool import TRUE | ||
from cairo_programs.uint384 import uint384_lib, Uint384, Uint384_expand | ||
from cairo_programs.uint384_extension import uint384_extension_lib | ||
from cairo_programs.field_arithmetic import field_arithmetic | ||
|
||
|
||
func run_get_square{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(prime: Uint384, generator: Uint384, num: Uint384, iterations: felt) { | ||
alloc_locals; | ||
if (iterations == 0) { | ||
return (); | ||
} | ||
|
||
let (square) = field_arithmetic.mul(num, num, prime); | ||
|
||
let (success, root_1) = field_arithmetic.get_square_root(square, prime, generator); | ||
assert success = 1; | ||
|
||
// We calculate this before in order to prevent revoked range_check_ptr reference due to branching | ||
let (root_2) = uint384_lib.sub(prime, root_1); | ||
let (is_first_root) = uint384_lib.eq(root_1, num); | ||
|
||
if ( is_first_root != TRUE) { | ||
assert root_2 = num; | ||
} | ||
|
||
return run_get_square(prime, generator, square, iterations -1); | ||
} | ||
|
||
func main{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}() { | ||
let p = Uint384(18446744069414584321, 0, 0); // Goldilocks Prime | ||
let x = Uint384(5, 0, 0); | ||
let g = Uint384(7, 0, 0); | ||
run_get_square(p, g, x, 100); | ||
return (); | ||
} |
Oops, something went wrong.