Closed mvievaz closed 1 month ago
Hi, yes, the problem is that you use mpc.mod(b, m)
where m
is not a public value. The function mpc.mod()
calls mpc._mod()
and there this constraint applies.
This constraint will be lifted in the near future say. The raw material to handle the general case of a secret-shared m
is already present in MPyC as we need it to work with secure (secret-shared) class groups.
So, if you add this line mpyc.secgroups import _divmod
at the top of your program, then you can replace the call to mpc.mod()
by:
_, m = _divmod(b, m)
Note that _divmod()
gives you the secure integer division with remainder that you are aiming for with your program. Actually, because your program reveals the outcomes of intermediate tests as in while await mpc.output(mpc.ge(a, b))
, it is not secure (not privacy-preserving). The solution underlying _ divmod()
avoids revealing any intermediate values.
Hi, thanks for your help!
We tested and it work perfectly. We close the issue .Thanks for your note too ;)
The code is attached in case someone needs it in the future:
from mpyc.runtime import mpc
from mpyc.secgroups import _divmod
bits= 64
async def mod_inverse(b, m):
original_m = m
sec_int = mpc.SecInt(bits)
sec_int_one = sec_int(1)
x0, x1 = sec_int(0), sec_int(1)
if await mpc.output(mpc.eq(m,sec_int_one)):
return 0
while await mpc.output(mpc.ge(b,sec_int(2))):
b2 = m
q, m = _divmod(b, m)
b = b2
x0, x1 = x1 - q * x0, x0
if await mpc.output(mpc.lt(x1,sec_int(0))):
x1 = x1 + original_m
return x1
async def main():
await mpc.start()
sec_int = mpc.SecInt(bits)
print("TESTING INVERSE-MOD")
# Example of inverse mod with 3 and 7 (sol = 5)
b = sec_int(3)
m = sec_int(7)
sol = await mod_inverse(b,m)
print(await mpc.output(sol))
await mpc.shutdown()
if __name__ == "__main__":
mpc.run(main())
Executing my program I found an error on mpyc/thresha.py:
To reproduce this error we have to execute the following code:
We are testing this code with 3 players on local. This are the output for each player (We tested various times and we get the same errors on different players. Not always the same error for the same player)
PLAYER 0 (HANGED)
PLAYER 1
PLAYER 2
We tested with 2 players and it work, but the errors appears when we started to use more than 2 players.
I hope this issue can help to improve the repo and we can find a solution for this problem. Thanks for your work at MPyC :)