Visa-Research / volepsi

Efficient Private Set Intersection base on VOLE
MIT License
98 stars 31 forks source link

How to use it without communication connection? #17

Closed TY-cc closed 1 year ago

TY-cc commented 1 year ago

If there are Server and Client, and they can't communicate directly. How to use thie library in this scene? What I am thinking about is storing the content that needs to be communicated into a file and then transferring the file. But I can't do it.

ladnir commented 1 year ago

See the message passing example. You can put the messages in a file, as the examples shows. Then it's up to you to send them.

TY-cc commented 1 year ago

I know this example. But isn 't there a bug in this example as https://github.com/Visa-Research/volepsi/issues/15

ladnir commented 1 year ago

It might be a bug with the example as opposed to the actual library. Not sure. Also, I'll be fixing it next week so should be fine to assume that it works and wait for the fix.

TY-cc commented 1 year ago

Okey, I see what your mean. Thanks

TY-cc commented 1 year ago

I have some problems about the message passing example. Why does the example need to loop reading and writing file when the protocol.is_ready() == false ? And why does each party produce three files(0,1,2) in this process?

TY-cc commented 1 year ago

In the message passing example, receiver write information, sender can read correctly. But sender write file, receiver can't read correctly. Another issue is that who first write file have some effect?

ladnir commented 1 year ago

That example shows how to generically execute any protocol. They send messages back and forth. The number of rounds is some constant. So I guess its 3 in this case?

Yeah, i suspect there is some bug in the example code. Still haven't had time to debug it. The main idea is that you need to pass the outbound message to the other other party who uses it as an inbound message.

TY-cc commented 1 year ago

I can't understant some code in messagePassingExample.h as follow: // The sender we generate the first message. if (!sender) write(); // While the protocol is not done we alternate between reading and writing messages. while (protocol.is_ready() == false) { read(); write(); }

that part result 3 file for each party

ladnir commented 1 year ago

The example code has been fixed. See the other thread for details. But the change also increased the number of messages from 3 to 6. With time ill get 3 messages working again.

The protocol looks like

Sender               Receiver
        <------------   mr_0
ms_0 -------------> 
        <------------   mr_1
ms_1 -------------> 
...

        <------------   mr_n
ms_n -------------> 

mr_i is computed using the receiver's internal state and the sender's msg ms_{i-1} (if one exists). ms_i is computed using the sender's internal state and the receiver's msg mr_i.

protocol.is_ready() returns true if the protocol is done. If its not done, then that means you need to read the incoming message i.e. call read() and generate an outgoing message, i.e. call write().

Im not sure how to be more clear. Maybe you can explain whats confusing.

TY-cc commented 1 year ago

I have copy the file"RsPsi.cpp", "messagePassingExample.h"and "networkSocketExample.h". And used make to compile project. When i using ./frontend -messagePass, it can't end properly, only show sender done. Is it a bug?

And the message mr_1 and mr_2 written by receiver is inconsistent with the message read by sender.

I want to know about more detail about generate the message? Do you have some suggestation? thanks

ladnir commented 1 year ago

if you have your own copy make sure the last param to init(...) is false. Otherwise the intersection is always empty.

https://github.com/Visa-Research/volepsi/blob/main/frontend/messagePassingExample.h#L176

ladnir commented 1 year ago

If that doenst fix your issue then try ./frontend -messagePass -v and show the output.

TY-cc commented 1 year ago

I am sure the last param to init(...) is false. When i try ./frontend -messagePass -v and the output as follow

recver start sender start sender write 0 e68eb4e4ce6f89169220130a96df816c sender file renamed successfully recver read 0 e68eb4e4ce6f89169220130a96df816c recver write 0 064d82349ace9b3218434d4a353678d7 recver file renamed successfully recver read 1 4f738545cd9e0e69f9287a218daf31aa recver write 1 93cee510e3acf452ba764321784be96f recver file renamed successfully sender read 0 064d82349ace9b3218434d4a353678d7 sender write 1 0b1ff0a15fd677beea843b60fa9f489b sender file renamed successfully sender read 1 93cee510e3acf452ba764321784be96f sender write 2 c71d71a77e51ad20c7ca98376e8c3001 sender file renamed successfully recver read 2 c71d71a77e51ad20c7ca98376e8c3001 recver write 2 f2e9d74c0bf115546b33335e575ec3c3 recver file renamed successfully sender read 2 f2e9d74c0bf115546b33335e575ec3c3 sender done

Note that this does not end, just stay here

ladnir commented 1 year ago

And what happens when you run the unit tests frontend -u

TY-cc commented 1 year ago

The last output as follow

============================================= All Passed (46)

WARNING: This program made use of the LPN silver encoder. This encoder is experimental and should not be used in production. Rebuild libOTe with -DNO_SILVER_WARNING=TRUE to disable this message or build the library with -DENABLE_BITPOLYMUL=TRUE to use an encoding with provable minimum distance. /home/cc/VOLE/volepsi-main/out/libOTe/libOTe/TwoChooseOne/Silent/SilentOtExtSender.cpp:60

ladnir commented 1 year ago

When you run the example does the program finish or hang

ladnir commented 1 year ago

Have you modified the example at all?

TY-cc commented 1 year ago

when use ./frontend -messagePass , the program was hang. And finished when use frontend -u.

I just copy the content of last file messagePassingexample.h, RsPsi.cpp, and networkSocketExample

ladnir commented 1 year ago

try this example:


void messagePassingExampleBoth(oc::CLP& cmd)
{
    // The sender set size.
    auto ns = cmd.getOr("senderSize", 100);

    // The receiver set size.
    auto nr = cmd.getOr("receiverSize", 100);
    auto verbose = cmd.isSet("v");

    // The statistical security parameter.
    auto ssp = cmd.getOr("ssp", 40);

    // Malicious Security.
    auto mal = cmd.isSet("malicious");

    // The vole type.
#ifdef ENABLE_BITPOLYMUL
    auto type = cmd.isSet("useSilver") ? oc::MultType::slv5 : oc::MultType::QuasiCyclic;
#else
    auto type = oc::MultType::slv5;
#endif

    // A buffering socket. This socket type internally buffers the 
    // protocol messages. It is then up to the user to manually send
    // and receive messages via the getOutbond(...) and processInbount(...)
    // methods.
    coproto::BufferingSocket senderSock, recverSock;

    // Sets are always represented as 16 byte values. To support longer elements one can hash them.
    std::vector<oc::block> senderSet, recverSet;
    volePSI::RsPsiSender sender;
    senderSet.resize(ns);

    // in this example we use the set {0,1,...}.
    for (oc::u64 i = 0; i < ns; ++i)
        senderSet[i] = oc::block(0, i);

    sender.setMultType(type);
    sender.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, false);

    if (verbose)
        std::cout << "sender start\n";

    // Eagerly start the protocol. This will run the protocol up to the point
    // that it need to receive a message from the other party.
    coproto::optional<macoro::eager_task<>> senderProto =
        sender.run(senderSet, senderSock) | macoro::make_eager();

    // in this example we use the set {0,1,...}.
    recverSet.resize(nr);
    for (oc::u64 i = 0; i < nr; ++i)
        recverSet[i] = oc::block(0, i);

    volePSI::RsPsiReceiver recevier;
    recevier.setMultType(type);
    recevier.init(ns, nr, ssp, oc::sysRandomSeed(), mal, 1, false);

    if (verbose)
        std::cout << "recver start\n";

    // Eagerly start the protocol. This will run the protocol up to the point
    // that it need to receive a message from the other party.
    coproto::optional<macoro::eager_task<>> recverProto =
        recevier.run(recverSet, recverSock) | macoro::make_eager();
    try
    {
        while (recverProto || senderProto)
        {
            if (recverProto && recverProto->is_ready())
            {
                coproto::sync_wait(*recverProto);
                std::cout << "recver done " << recevier.mIntersection.size() << " \n";
                recverProto.reset();
            }

            if (senderProto && senderProto->is_ready())
            {
                coproto::sync_wait(*senderProto);
                std::cout << "sender done " << " \n";
                senderProto.reset();
            }
            auto recverMsg = recverSock.getOutbound();
            if (recverMsg.has_value())
                senderSock.processInbound(*recverMsg);

            auto senderMsg = senderSock.getOutbound();
            if (senderMsg)
                recverSock.processInbound(*senderMsg);
        }

    }
    catch (std::exception& e)
    {
        std::cout << "Exception: " << e.what() << std::endl;
    }

}
TY-cc commented 1 year ago

I use the function messagePassingExampleBoth to replace the messagePassingExanple, but can't compile. It show:

/home/cc/VOLE/volepsi-main/frontend/messagePassingExample.h:196:52: error: cannot convert ‘std::remove_reference<std::vector&>::type’ {aka ‘std::vector’} to ‘coproto::span’ {aka ‘nonstd::span_lite::span<unsigned char, 18446744073709551615>’} 196 senderSock.processInbound(std::move(*recverMsg)); ~~~^~~~~~
std::remove_reference<std::vector&>::type {aka std::vector}

compilation terminated due to -Wfatal-errors.

ladnir commented 1 year ago

I updated the code above. Try again

ladnir commented 1 year ago

https://github.com/Visa-Research/volepsi/issues/17#issuecomment-1429274372

TY-cc commented 1 year ago

OK, I update the code. It is successed. The output when i use the command ./frontend -messagePassing

recver done 100 sender done
recver done 100 sender done

The output when i use the command ./frontend -messagePassing -v

sender start sender start recver start recver start recver done 100 sender done
recver done 100 sender done

ladnir commented 1 year ago

great. All good?

ladnir commented 1 year ago

Also fixed the previous issue with using fewer rounds. See this options https://github.com/Visa-Research/volepsi/blob/main/frontend/messagePassingExample.h#L136

When set, the protocol does a bit more work but required fewer messages to be sent.

TY-cc commented 1 year ago

Well, I 've updated all the files you 've updated, and re-compile the project. But the function messagePassingExampleRun in file messagePassingExample.h still can't to work properly. The function messagePassingExampleBoth can work , but it can't generate the message file.

ladnir commented 1 year ago

Write the message file yourself. Seems like a simple task. Use messagePassingExampleBoth as a starting point. You have a vector of bytes. Write them to a file or send them however you want.

TY-cc commented 1 year ago

Indeed, I can imitate the function communicate.

The last question, I want to know more details about the message to be transmitted. How to generate,and what is it related to?

Thank you very much. It 's too much trouble.

ladnir commented 1 year ago

Well you can read the papers linked in the Readme. If you used the reduced round setting, then the first messages are the base ots. This consist a one message from each party. These are then used to construct the vole by send one more message. The receiver encodes their set and sends it to the sender. Finally the sender encodes their set using the vole and sends it to the receiver.

TY-cc commented 1 year ago

Thank for your help. Your description is very clear. Thanks again.