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

How to generate a circuit containing out-of-circuit or fixed information? #160

Open
supercrush opened this issue Mar 31, 2022 · 3 comments

Comments

@supercrush
Copy link

supercrush commented Mar 31, 2022

I want to generate a simple circuit, which appends a single '0' (out-of-circuit information) at end of the bitstream.

Code:

    Integer in(1,1, ALICE);
    Integer p(1,0,PUBLIC);  //out-of-circuit information
    Integer out(2,0,PUBLIC);
    

    out[0] = in[0];
    out[1] = p[0];
    std::cout << out.reveal<string>(PUBLIC) << std::endl;

generated circuit:

3 4
1 0 2
                                                                                                                                                                                              
2 1 0 0 1 XOR    
2 1 1 0 2 XOR
2 1 1 0 3 XOR

x1 = XOR(x0, x0) // result is 0
x2 = XOR(x1, x0) // result depends on x0
x3 = XOR(x1, x0) // result depends on x0

The output doesn't contain any information of out-of-circuit information. The result of the two outputs x2, x3 is always the same as the input x0 and the out-of-circuit information is missing. What is the correct way to generate a circuit containing out-of-circuit information like appending a fix '0' at the end of the bitstream?

@wangxiao1254
Copy link
Member

All constants are hardcoded to minimize the number of gates. All XOR gates here are only to gather outputs.

@supercrush
Copy link
Author

Hi. Thank you very much for your reply!

There is no problem in directly running my previous snippet when creating two instances.

However, if I generate a circuit and load it to compute the result, the outcome is incorrect. The outcome of both bits depends on wire[0] as mentioned above, i.e., in[0] (x0). When a[0] = wire[0]=1, the result will be 11, and vice versa.
Code snippet:

    Integer in(1,1, ALICE);
    Integer out(2,0,PUBLIC);
    std::string filepath = "./circuit.txt";
    emp::BristolFormat cf(filepath.c_str());
    cf.compute(out.bits.data(), in.bits.data(), nullptr);
    std::cout <<out.reveal<string>() << std::endl;

In other words, is it not suitable for loading such generated bristol format circuits and running in sh2pc or ag2pc? How can I run such an application (appending constant) in ag2pc. I assume it requires a circuit to run in ag2pc.

@Sherlock-feng
Copy link

Hi, I have a problem. Readme doesn't show how to use the library. Besides, I don't know where is the interface in the library and how to run my own code. Can you tell me which step to follow to run the code like you did?

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

3 participants