Giter Club home page Giter Club logo

Comments (10)

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

One way that you can know the id of each wire is to cast the block into an array of uint64_t. the higher int is the id.
See e.g.: https://github.com/emp-toolkit/emp-tool/blob/master/emp-tool/execution/plain_circ.h#L65

from emp-tool.

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

On a second examination, I think the wires should all be ordered as one would expect rather than the order you mentioned above. Can you double-check? :)

from emp-tool.

gconeice avatar gconeice commented on June 9, 2024

Hi. Thank you very much for your reply!

I retried to generate the circuit but it still not works as my expectation. Specifically, the program I executed is as follow:

#include <emp-tool/execution/plain_prot.h>
#include <emp-sh2pc/emp-sh2pc.h>
#include <emp-tool/circuits/bit.h>
#include <emp-tool/circuits/circuit_file.h>

#include <iostream>

static const char* FILENAME = "test.txt";

int main() {
  using Circuit = emp::BristolFormat;
  {
    emp::setup_plain_prot(true, FILENAME);
    emp::Integer a {2, 0, emp::ALICE};
    emp::Integer b {2, 0, emp::ALICE};
    emp::Bit cond1 = (b > a);
    cond1.reveal<bool>();
    emp::finalize_plain_prot();	  
  }
}

The test.txt will be:

13 17
4 0 1
                                                                                                                                                                                            
2 1 0 2 4 XOR
2 1 4 2 5 AND
2 1 1 3 6 XOR
2 1 5 3 7 XOR
2 1 6 5 8 XOR
2 1 6 7 9 AND
2 1 5 9 10 XOR
2 1 1 3 11 XOR
2 1 11 10 12 XOR
1 1 12 13 INV
1 1 13 14 INV
2 1 0 0 15 XOR
2 1 15 14 16 XOR

I tried to set in[0..3] and see out[16], for example:

in[0..3] := 1000 ---> out[16] = 0
in[0..3] := 0100 ---> out[16] = 1
in[0..3] := 0010 ---> out[16] = 1
in[0..3] := 0001 ---> out[16] = 0

which means in[0] and in[3] belong to emp::Integer a && in[1] and in[2] belong to emp::Integer b.

from emp-tool.

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

little-endian or big-endian in your representation? Try 0011 :)

from emp-tool.

gconeice avatar gconeice commented on June 9, 2024

Hi!

in[0..3] := 1000 <——> in[0] := 1, in[1] := 0, in[2] := 0, in[3] := 0

Therefore, 0011 will result in 0.

from emp-tool.

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

Please try this example

setup_plain_prot(true, "sort.txt");
Integer a(2,0,ALICE);
Integer b(2,0,ALICE);
(a[0] & b[0]).reveal();

You will see that the output circuit is
3 7
4 0 1

2 1 0 2 4 AND
2 1 0 0 5 XOR
2 1 5 4 6 XOR

Here only wire 0 and 2 are used. This is because 0 is for a[0] and 2 is for b[0].

from emp-tool.

gconeice avatar gconeice commented on June 9, 2024

Thank you very much! I tried your example (with a[0]&a[1], a[0]&b[1] ...). It indeed works.

The experiment shows that a[0] := in[0], a[1] := in[1], b[0] := in[2] and b[1] := in[3].

Then, there must be some problem in (b > a) circuit generating procedure. Let's set
a[0] = in[0] := 0
a[1] = in[1] := 1
b[0] = in[2] := 0
b[1] = in[3] := 0

(b > a) should be 0, obviously.

However, based on the BF circuit in my previous reply, which is:

13 17
4 0 1
                                                                                                                                                                                            
2 1 0 2 4 XOR
2 1 4 2 5 AND
2 1 1 3 6 XOR
2 1 5 3 7 XOR
2 1 6 5 8 XOR
2 1 6 7 9 AND
2 1 5 9 10 XOR
2 1 1 3 11 XOR
2 1 11 10 12 XOR
1 1 12 13 INV
1 1 13 14 INV
2 1 0 0 15 XOR
2 1 15 14 16 XOR

The entire calculation process will be:

wire[0] = 0
wire[1] = 1
wire[2] = 0
wire[3] = 0
wire[4] = wire[0] XOR wire[2] = 0
wire[5] = wire[4] AND wire[2] = 0
wire[6] = wire[1] XOR wire[3] = 1
wire[7] = wire[5] XOR wire[3] = 0
wire[8] = wire[6] XOR wire[5] = 1
wire[9] = wire[6] AND wire[7] = 0
wire[10] = wire[5] XOR wire[9] = 0
wire[11] = wire[1] XOR wire[3] = 1
wire[12] = wire[10] XOR wire[11] = 1
wire[13] = INV wire[12] = 0
wire[14] = INV wire[13] = 1
wire[15] = wire[0] XOR wire[0] = 0
wire[16] = wire[14] XOR wire[15] = 1, which is wrong.

from emp-tool.

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

actually, the comparison assumes signed input. so if the highest bit is 1. it is a negative number.

from emp-tool.

gconeice avatar gconeice commented on June 9, 2024

Oops, I also realized this problem after going into integer.hpp source code just now. Thank you very much for your kindly help! Sorry for causing troubles.

from emp-tool.

wangxiao1254 avatar wangxiao1254 commented on June 9, 2024

np. closing the issue.

from emp-tool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.