-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hints): Add alternative hint string for nondet_bigint3 (#1071)
* Add alternative hint string for nondet_bigint_3 * Add integration test * Rename test file * Add changelog entry * Fix hint * Update CHANGELOG.md Co-authored-by: Tomás <47506558+MegaRedHand@users.noreply.github.com> --------- Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com> Co-authored-by: Tomás <47506558+MegaRedHand@users.noreply.github.com>
- Loading branch information
1 parent
47e7b34
commit 45a43aa
Showing
5 changed files
with
69 additions
and
3 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
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,45 @@ | ||
%builtins range_check | ||
|
||
from starkware.cairo.common.cairo_secp.bigint import BigInt3, BASE | ||
|
||
// Hint arguments: value. | ||
func nondet_bigint3{range_check_ptr}() -> (res: BigInt3) { | ||
// The result should be at the end of the stack after the function returns. | ||
let res: BigInt3 = [cast(ap + 5, BigInt3*)]; | ||
%{ | ||
from starkware.cairo.common.cairo_secp.secp_utils import split | ||
segments.write_arg(ids.res.address_, split(value)) | ||
%} | ||
// The maximal possible sum of the limbs, assuming each of them is in the range [0, BASE). | ||
const MAX_SUM = 3 * (BASE - 1); | ||
assert [range_check_ptr] = MAX_SUM - (res.d0 + res.d1 + res.d2); | ||
|
||
// Prepare the result at the end of the stack. | ||
tempvar range_check_ptr = range_check_ptr + 4; | ||
[range_check_ptr - 3] = res.d0, ap++; | ||
[range_check_ptr - 2] = res.d1, ap++; | ||
[range_check_ptr - 1] = res.d2, ap++; | ||
static_assert &res + BigInt3.SIZE == ap; | ||
return (res=res); | ||
} | ||
|
||
func main{range_check_ptr}() { | ||
alloc_locals; | ||
// Take these hints from div_mod_n just to have a value in scope | ||
local a: BigInt3 = BigInt3(1,2,3); | ||
local b: BigInt3 = BigInt3(4,5,6); | ||
%{ | ||
from starkware.cairo.common.cairo_secp.secp_utils import N, pack | ||
from starkware.python.math_utils import div_mod, safe_div | ||
|
||
a = pack(ids.a, PRIME) | ||
b = pack(ids.b, PRIME) | ||
value = res = div_mod(a, b, N) | ||
%} | ||
let (r) = nondet_bigint3(); | ||
assert r.d0 = 46511138620617205537268188; | ||
assert r.d1 = 26286155657000021849694253; | ||
assert r.d2 = 3102515549921694024741409; | ||
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
45a43aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.parse program
27010691
ns/iter (± 1135108
)18575731
ns/iter (± 178502
)1.45
build runner
3951733
ns/iter (± 149782
)2553314
ns/iter (± 1320
)1.55
This comment was automatically generated by workflow using github-action-benchmark.
CC: @unbalancedparentheses