emp-tool icon indicating copy to clipboard operation
emp-tool copied to clipboard

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

Open supercrush opened this issue 3 years ago • 3 comments

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?

supercrush avatar Mar 31 '22 09:03 supercrush

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

wangxiao1254 avatar Mar 31 '22 22:03 wangxiao1254

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.

supercrush avatar Apr 01 '22 11:04 supercrush

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?

Sherlock-feng avatar Aug 15 '23 00:08 Sherlock-feng