-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add div by zero error * Add ec_recover_prod integration test * Add unit tests * Cargo fmt * Update changelog * Add integration tests * Correct error message * Fix bug add tests * Remove space * Run cargo fmt * Add integration test program --------- Co-authored-by: juan.mv <[email protected]>
- Loading branch information
Showing
7 changed files
with
361 additions
and
2 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
26 changes: 26 additions & 0 deletions
26
cairo_programs/bad_programs/ec_recover_div_mod_n_packed_n_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,26 @@ | ||
struct BigInt3 { | ||
d0: felt, | ||
d1: felt, | ||
d2: felt, | ||
} | ||
|
||
func main() { | ||
let x = BigInt3(d0=0, d1=0, d2=1); | ||
let s = BigInt3(d0=0, d1=0, d2=1); | ||
let n = BigInt3(d0=0, d1=0, d2=0); | ||
ec_recover_product(x, s, n); | ||
return(); | ||
} | ||
|
||
func ec_recover_product(x:BigInt3, s:BigInt3, n:BigInt3) { | ||
%{ | ||
from starkware.cairo.common.cairo_secp.secp_utils import pack | ||
from starkware.python.math_utils import div_mod, safe_div | ||
N = pack(ids.n, PRIME) | ||
x = pack(ids.x, PRIME) % N | ||
s = pack(ids.s, PRIME) % N | ||
value = res = div_mod(x, s, N) | ||
%} | ||
return(); | ||
} |
28 changes: 28 additions & 0 deletions
28
cairo_programs/bad_programs/ec_recover_product_mod_m_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,28 @@ | ||
struct BigInt3 { | ||
d0: felt, | ||
d1: felt, | ||
d2: felt, | ||
} | ||
|
||
func main() { | ||
let a = BigInt3(d0=0, d1=0, d2=1); | ||
let b = BigInt3(d0=0, d1=0, d2=1); | ||
let m = BigInt3(d0=0, d1=0, d2=0); | ||
ec_recover_product(a, b, m); | ||
return(); | ||
} | ||
|
||
func ec_recover_product(a:BigInt3, b:BigInt3, m:BigInt3) { | ||
%{ | ||
from starkware.cairo.common.cairo_secp.secp_utils import pack | ||
from starkware.python.math_utils import div_mod, safe_div | ||
a = pack(ids.a, PRIME) | ||
b = pack(ids.b, PRIME) | ||
product = a * b | ||
m = pack(ids.m, PRIME) | ||
value = res = product % m | ||
%} | ||
return(); | ||
} |
57 changes: 57 additions & 0 deletions
57
cairo_programs/bad_programs/uint512_unsigned_div_rem_div_is_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,57 @@ | ||
|
||
struct MyStruct1 { | ||
d0: felt, | ||
d1: felt, | ||
d2: felt, | ||
d3: felt, | ||
} | ||
struct MyStruct0 { | ||
low: felt, | ||
high: felt, | ||
} | ||
func main() { | ||
let x =MyStruct1(d0=1, d1=1, d2=1, d3=1); | ||
let div = MyStruct0(low=0, high=0); | ||
hint_func(x, div); | ||
return(); | ||
} | ||
|
||
func hint_func(x: MyStruct1, div: MyStruct0) { | ||
alloc_locals; | ||
local quotient: MyStruct1; | ||
local remainder: MyStruct0; | ||
|
||
%{ | ||
def split(num: int, num_bits_shift: int, length: int): | ||
a = [] | ||
for _ in range(length): | ||
a.append( num & ((1 << num_bits_shift) - 1) ) | ||
num = num >> num_bits_shift | ||
return tuple(a) | ||
|
||
def pack(z, num_bits_shift: int) -> int: | ||
limbs = (z.low, z.high) | ||
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs)) | ||
|
||
def pack_extended(z, num_bits_shift: int) -> int: | ||
limbs = (z.d0, z.d1, z.d2, z.d3) | ||
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs)) | ||
|
||
x = pack_extended(ids.x, num_bits_shift = 128) | ||
div = pack(ids.div, num_bits_shift = 128) | ||
|
||
quotient, remainder = divmod(x, div) | ||
|
||
quotient_split = split(quotient, num_bits_shift=128, length=4) | ||
|
||
ids.quotient.d0 = quotient_split[0] | ||
ids.quotient.d1 = quotient_split[1] | ||
ids.quotient.d2 = quotient_split[2] | ||
ids.quotient.d3 = quotient_split[3] | ||
|
||
remainder_split = split(remainder, num_bits_shift=128, length=2) | ||
ids.remainder.low = remainder_split[0] | ||
ids.remainder.high = remainder_split[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
Oops, something went wrong.
1b8e5c0
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
.add_u64_with_felt/1
4
ns/iter (± 0
)2
ns/iter (± 0
)2
add_u64_with_felt/2
4
ns/iter (± 0
)2
ns/iter (± 0
)2
add_u64_with_felt/3
2
ns/iter (± 0
)1
ns/iter (± 0
)2
add_u64_with_felt/4
2
ns/iter (± 0
)1
ns/iter (± 0
)2
add_u64_with_felt/5
2
ns/iter (± 0
)1
ns/iter (± 0
)2
add_u64_with_felt/6
4
ns/iter (± 0
)2
ns/iter (± 0
)2
add_u64_with_felt/7
4
ns/iter (± 0
)2
ns/iter (± 0
)2
add_u64_with_felt/8
3
ns/iter (± 0
)2
ns/iter (± 0
)1.50
This comment was automatically generated by workflow using github-action-benchmark.
CC: @unbalancedparentheses