Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior after using B2A and A2B gate #204

Open
winnnnnny opened this issue Jun 28, 2023 · 0 comments
Open

Strange behavior after using B2A and A2B gate #204

winnnnnny opened this issue Jun 28, 2023 · 0 comments

Comments

@winnnnnny
Copy link

Hello, sorry for disturbing you.

When I using B2A and A2B gates to perform conversions between arithmetic and Boolean, I observed a strange behavior. After a value from PutGTGate in the Boolean circuit is converted to arithmetic and converted back to the Boolean, though its value keeps the same, its inversion is changed.

Here is an example.

int32_t test(e_role role, const std::string& address, uint16_t port, seclvl seclvl,
uint32_t numbers, uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mt_alg,
e_sharing sharing) {
    ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads, mt_alg);
    std::vector<Sharing*>& sharings = party->GetSharings();
    BooleanCircuit* circ = (BooleanCircuit*) sharings[sharing]->GetCircuitBuildRoutine();
    BooleanCircuit* Ycirc = (BooleanCircuit*) sharings[S_YAO]->GetCircuitBuildRoutine();
    ArithmeticCircuit* Acirc = (ArithmeticCircuit*) sharings[S_ARITH]->GetCircuitBuildRoutine();
    share *var1, *var2, *result, *result_inv, *out, *out_inv;

    uint32_t var1_c = 61;
    uint32_t var2_c = 18;
    var1 = circ -> PutINGate(var1_c, 32, SERVER);
    var2 = circ -> PutINGate(var2_c, 32, CLIENT);
    result = circ -> PutGTGate(var1 , var2);
    circ -> PutPrintValueGate(result, "result");
    result = Acirc -> PutB2AGate(result);
    result = circ -> PutA2BGate(result, Ycirc);
    result_inv = circ -> PutINVGate(result);
    circ -> PutPrintValueGate(result_inv, "result_inv");
    out = circ->PutOUTGate(result_inv, ALL);
    out_inv = circ->PutOUTGate(result, ALL);
    party->ExecCircuit();
    delete var1;
    delete var2;
    delete result;
    delete result_inv;
    delete party;
    return 0;
}

In the code, I compare two variables and get the result correctly. After I convert the result from Boolean to arithmetic and convert it back, though the result keeps the same, the result_inv is different.

The output is shown below.

result: 1
result_inv: 65534

If two lines that perform the conversion "result = Acirc -> PutB2AGate(result);result = circ -> PutA2BGate(result, Ycirc);" is deleted, the output is shown below.

result: 1
result_inv: 0

I cannot find the reason behind this behavior. Could you help me to explain this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant