You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug div_mod implementation differs from python's implementation.
defdiv_mod(n, m, p):
""" Finds a nonnegative integer x < p such that (m * x) % p == n. """a, b, c=igcdex(m, p)
assertc==1return (n*a) %p
///Finds a nonnegative integer x < p such that (m * x) % p == n.pubfndiv_mod(n:&BigInt,m:&BigInt,p:&BigInt) -> BigInt{let a = mul_inv(m, p);(n * a).mod_floor(p)}
Python's assert makes it so that m != p
To Reproduce
Create any program with a hint that uses the div_mod function, here is an example:
struct MyStruct0 {
high: felt,
low: felt,
}
func main() {
let a = MyStruct0(high=1, low=340282366920938463463374607431768211456);
let b = MyStruct0(high=1, low=1);
let p = MyStruct0(high=1, low=1);
let (a, b, p, b_inverse_mod_p) = hint_func(a, b, p);
return();
}
func hint_func(a: MyStruct0, b: MyStruct0, p: MyStruct0) -> (MyStruct0, MyStruct0, MyStruct0, MyStruct0) {
alloc_locals;
local b_inverse_mod_p: MyStruct0;
%{
from starkware.python.math_utils import div_mod
def split(a: int):
return (a & ((1 << 128) - 1), a >> 128)
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))
a = pack(ids.a, 128)
b = pack(ids.b, 128)
p = pack(ids.p, 128)
# For python3.8 and above the modular inverse can be computed as follows:
# b_inverse_mod_p = pow(b, -1, p)
# Instead we use the python3.7-friendly function div_mod from starkware.python.math_utils
b_inverse_mod_p = div_mod(1, b, p)
b_inverse_mod_p_split = split(b_inverse_mod_p)
ids.b_inverse_mod_p.low = b_inverse_mod_p_split[0]
ids.b_inverse_mod_p.high = b_inverse_mod_p_split[1]
%}
return(a, b, p, b_inverse_mod_p);
}
Expected behavior
Why does python check that condition?
What version/commit are you on?
v0.8.6
The text was updated successfully, but these errors were encountered:
Describe the bug
div_mod
implementation differs from python's implementation.Python's assert makes it so that
m != p
To Reproduce
Create any program with a hint that uses the
div_mod
function, here is an example:Expected behavior
Why does python check that condition?
What version/commit are you on?
v0.8.6
The text was updated successfully, but these errors were encountered: