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

Question about PutSharedIN/OUTGate #167

Closed
Moriarty002 opened this issue Aug 26, 2020 · 7 comments
Closed

Question about PutSharedIN/OUTGate #167

Moriarty002 opened this issue Aug 26, 2020 · 7 comments

Comments

@Moriarty002
Copy link

How to use these two function
I try to use them in my way like below

if(role == SERVER){
            server=bc->PutINGate(a_int,bitlen,SERVER);
            client=bc->PutDummyINGate(bitlen);
}
else if(role == CLIENT){
            client=bc->PutINGate(a_int,bitlen,CLIENT);
            server=bc->PutDummyINGate(bitlen);
}
out[0]=bc-> PutSharedOUTGate(server);
party->ExecCircuit();
party->Reset();
share *s;
s=out[0]->get_wire_ids_as_share (bc->PutSharedINGate(result[0]));
out[1]=bc->PutOUTGate(s,ALL);
party->ExecCircuit();

I expect that the out[1] is same as server input , but the output of out[1] is 0
I want to know how to use PutSharedIN/OUT correctly

@dd23
Copy link
Member

dd23 commented Aug 26, 2020

Can you explain what this line is supposed to do?
s=out[0]->get_wire_ids_as_share (bc->PutSharedINGate(result[0]));

@Moriarty002
Copy link
Author

Because PutSharedINGate return "gate id" , and what I want is an 'share' object
This line is supposed to get the share* and assign it to 's' .
Did it wrong ?

@dd23
Copy link
Member

dd23 commented Aug 26, 2020

There is a version of PutSharedINGate that returns a share*, which is probably what you want.
Have a look at §3.1.2 in the developer guide.

@aben20807
Copy link

Hi @Moriarty002

I think you just slightly misunderstood the functions.

Following is an example for PutSharedOUTGate and PutSharedINGate

    uint32_t a_int = 3;
    uint32_t b_int = 4;

    share* s_a;
    share* s_b;
    share* s_c;
    // Input
    if(role == SERVER){
        s_a = bc->PutINGate(a_int, bitlen, SERVER);
        s_b = bc->PutDummyINGate(bitlen);
    }
    else if(role == CLIENT){
        s_a = bc->PutDummyINGate(bitlen);
        s_b = bc->PutINGate(b_int, bitlen, CLIENT);
    }
    s_c = bc->PutADDGate(s_a, s_b);
    share* out = bc->PutSharedOUTGate(s_c);

    // Execute and get shared output
    party->ExecCircuit();
    uint32_t c_int_shared = out->get_clear_value<uint32_t>();
    std::cout << (role == SERVER?"server: ":"client: ") << c_int_shared << std::endl; // here output the shared value.
    party->Reset(); // Reset after getting the output value

    // Put shared value as input
    out = bc->PutSharedINGate(c_int_shared, bitlen);
    out = bc->PutOUTGate(out, ALL);

    // Execute agagin and get the reconstructed result
    party->ExecCircuit();
    uint32_t c_int = out->get_clear_value<uint32_t>();
    std::cout << "Result: " << c_int << std::endl; // here output the reconstructed value 7, the result of 3+4.
    party->Reset();

@Moriarty002
Copy link
Author

Thanks very much .
All problem are cleared

@L-coder148
Copy link

L-coder148 commented Nov 12, 2021

Hello,sorry to bother you @dd23 @aben20807 , would you please take a look at my code, it does not output as expected.
Suppose x1 and x2 are two shares of x, y1 and y2 are two shares of y, and Client holds x1 and y1,Server holds x2 and y2, it satisfies x1+x2=x, y1+y2=y. Now I want to compute x*y=z, at the end, each party holds a share of z, and output their share respectively. For example, Client holds z1 and Server holds z2, such that z1+z2=z, I could not find any problem, but it does not output the expected number , I use ARITH citcuit to compute.

    uint32_t x1 = 1, x2 = 3, y1 = 2, y2 = 4;
    share* x1_shared,*x2_shared,*y1_shared,*y2_shared;
    //x1+x2=x
    x1_shared = addcirc->PutSharedINGate(x1, bitlen);
    x2_shared = addcirc->PutSharedINGate(x2, bitlen);
    y1_shared = addcirc->PutSharedINGate(y1, bitlen);
    y2_shared = addcirc->PutSharedINGate(y2, bitlen);

    share *s_z1, *s_z2, *s_z;
    s_z1 = addcirc->PutADDGate(x1_shared, x2_shared);
    s_z2 = addcirc->PutADDGate(y1_shared, y2_shared);
    s_z = addcirc->PutMULGate(s_z1, s_z2);
    s_z = addcirc->PutSharedOUTGate(s_z);

    party->ExecCircuit();

    uint32_t output = s_z->get_clear_value<uint32_t>();

    if (role == 1)
        std::cout << "client:" << output << std::endl;
    else
        std::cout << "server:" << output << std::endl;
    std::cout << (x1 + x2) * (y1 + y2) << std::endl;

the result is as follows
image

Hope for your guidance.

@L-coder148
Copy link

L-coder148 commented Nov 12, 2021

solved

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

4 participants