Skip to content

mpc.xor producing incorrect value #103

@SynthLuvr

Description

@SynthLuvr
import sys

from mpyc import mpctools
from mpyc.runtime import mpc


async def main():
    my_input = int(sys.argv[1], 16)
    secint = mpc.SecInt(256)

    await mpc.start()
    all_inputs = mpc.input(secint(my_input))
    combined_inputs = mpctools.reduce(mpc.xor, all_inputs)
    entropy = await mpc.output(combined_inputs)
    await mpc.shutdown()

    key = hex(entropy)[2:]
    print(key)


mpc.run(main())

Run with:

➜ python src/compute.py -M2 -I0 --no-log 6bf558aeeb81970a5d82e63f8c785f6a03b0f5355f276ef986b8b8b1cff1c6cb
➜ python src/compute.py -M2 -I1 --no-log 96dc2474ff71bab6001c1b81c0d1ff13a8e64264e68c031666cc521a662dbe14
102d17d23eaf351c05d9f01c14d4a5e7dac97379a45b3720fed850acc361f84df

The first issue is there's an overflow, 257 bit instead of 256. Second issue is that this value is incorrect. Correct result:

hex1 = "6bf558aeeb81970a5d82e63f8c785f6a03b0f5355f276ef986b8b8b1cff1c6cb"
hex2 = "96dc2474ff71bab6001c1b81c0d1ff13a8e64264e68c031666cc521a662dbe14"

num1 = int(hex1, 16)
num2 = int(hex2, 16)

final = num1 ^ num2

key = hex(final)[2:]
print(key)

Running this produces fd297cda14f02dbc5d9efdbe4ca9a079ab56b751b9ab6defe074eaaba9dc78df, whereas running via mpc.xor produces 102d17d23eaf351c05d9f01c14d4a5e7dac97379a45b3720fed850acc361f84df

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions