cryptobiu / libscapi

Comprehensive Open Source Library for Secure Multiparty Computation
MIT License
180 stars 66 forks source link

Error running a segment of the code of OTExample #78

Closed andremmvgabriel closed 4 years ago

andremmvgabriel commented 4 years ago

Hello everyone,

Hope I find you well!

Issue Description

So, after trying for a while to compile the example script with no success, I've decided to analise the code inside each example main in order to understand all the steps.

For each example, I've started by creating an empty script and copy piece by piece segments of your example code. For each segment copied, I compiled the code, printed the outputs, and commented the code (just for sake of my own understanding).

Everything went fine for the Communication example. However, in the Oblivious Transfer example, I can't get rid of an error which is:

terminate called after throwing an instance of 'char const*' Aborted (core dumped)

This error occurs when I try to run the code in line: auto dlog = make_shared\<OpenSSLDlogECF2m>(); inside the readConfigFile function.


How to reproduce the bug

This is my "test_oblivious_transfer.cpp" file (I didn't manage to copy much of the example code because the errors occurs very soon in the code). You have to copy this code inside a cpp. Pay attention to the "../../../../" on the includes in order to understand in what folder the file should be put in.

/*
This is just a test script.
*/

#include <iostream>

#include <boost/thread/thread.hpp>
#include "../../../../libscapi/include/infra/ConfigFile.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTSemiHonest.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTPrivacyOnly.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTOneSidedSimulation.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTFullSimulation.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTFullSimulationROM.hpp"
#include "../../../../libscapi/include/interactive_mid_protocols/OTUC.hpp"
#include "../../../../libscapi/include/primitives/Prg.hpp"

struct ObliviousTransConfig
{
    //IpAddress sender_ip;
    //IpAddress receiver_ip;
    std::string sender_ip;
    std::string receiver_ip;
    int sender_port;
    int receiver_port;
    std::string protocol_name;
    shared_ptr<GroupElement> g0;
    shared_ptr<GroupElement> g1;
    shared_ptr<GroupElement> h0;
    shared_ptr<GroupElement> h1;

    /*/ Constructor
    ObliviousTransConfig(IpAddress senderIp, IpAddress receiverIp, int senderPort, int receiverPort, string protocolName)
    {
        this->sender_ip = senderIp;
        this->receiver_ip = receiverIp;
        this->sender_port = senderPort;
        this->receiver_port = receiverPort;
        this->protocol_name = protocolName;
    }*/
};

void usageMessage()
{
    auto message = R"(
        To be able to run this script you need to execute it as:

        ./executable_file <party_number> <path_to_config_file>

        Where:
        <party_number> can be 1 or 2
    )";

    std::cerr << message << std::endl;
}

ObliviousTransConfig readConfigFile(std::string configFile)
{
    // Read the config file
    ConfigFile cf(configFile);

    // Creates a new ObliviousTransferConfig Object
    ObliviousTransConfig output;

    // Fills the object atributes
    output.sender_ip = cf.Value("", "senderIp");
    output.receiver_ip = cf.Value("", "receiverIp");
    output.sender_port = std::stoi(cf.Value("", "senderPort"));
    output.receiver_port = std::stoi(cf.Value("", "receiverPort"));
    output.protocol_name = cf.Value("", "protocolName");

    std::cerr << "Sender IP: " << output.sender_ip << std::endl;
    std::cerr << "Receiver IP: " << output.receiver_ip << std::endl;
    std::cerr << "Sender PORT: " << output.sender_port << std::endl;
    std::cerr << "Receiver PORT: " << output.receiver_port << std::endl;
    std::cerr << "Protocol Name: " << output.protocol_name << std::endl;

    if(output.protocol_name == "UCOnByteArray" || output.protocol_name == "UCOnGroupElement")
    {
        // Creates a discrete log group
        auto dlog = make_shared<OpenSSLDlogECF2m>();

        // Creates a vector of big integers with a size of 2
        std::vector<biginteger> point(2);

        // Generate First Element
        point[0] =  biginteger("4373527398576640063579304354969275615843559206632");
        point[1] =  biginteger("3705292482178961271312284701371585420180764402649");
        output.g0 = dlog->generateElement(false, point);

        // Generate Second Element
        point[0] =  biginteger("5358538915372747505940066348728070469076553372492");
        point[1] =  biginteger("9028382283996304130045455598981082528772297505697");
        output.g1 = dlog->generateElement(false, point);

        // Generate Third Element
        point[0] =  biginteger("582941706599807092180704244329891555852679544026");
        point[1] =  biginteger("9405288600072608660829837034337429060956333420529");
        output.h0 = dlog->generateElement(false, point);

        // Generate Fourth Element
        point[0] =  biginteger("5171406319926278015143700754389901479380894481649");
        point[1] =  biginteger("4324109033029607118050375077650365756171591181543");
        output.h1 = dlog->generateElement(false, point);

        std::cerr << "G0: " << output.g0 << std::endl;
        std::cerr << "G1: " << output.g1 << std::endl;
        std::cerr << "H0: " << output.h0 << std::endl;
        std::cerr << "H1: " << output.h1 << std::endl;
    }

    return output;
}

int main(int argc, char* argv[])
{
    // Do not let the code compile if there are not enough arguments given by the user
    if(argc < 2)
    {
        // Prints an example command line
        usageMessage();
        return 1;
    }

    std::cerr << "Argument 1: " << argv[1] << std::endl;
    std::cerr << "Argument 2: " << argv[2] << std::endl;

    // Read the configuration file for the oblivious transfer
    ObliviousTransConfig otConfig = readConfigFile(argv[2]);

    return 0;
}

Along side with this file, I've copied the OTConfig file inside the libscapi OTExample folder.

Compile and run it. To run the code I type the command: ./compiled_file (which in my case was ./exe_oblivious_transfer 1 "test_oblivious_transfer_config.txt").


Machine details


Did anyone else had this error? Can someone help me?

Thanks. Best regards, André

liorko87 commented 4 years ago

Hello,

The code required a config file: ConfigFile cf(configFile); What is the path you are passing to the function as configFile?

andremmvgabriel commented 4 years ago

Hello, and thanks for answering.

I have the config file in the same folder as the cpp file. So, after compiling the cpp, I run the code with the command line:

./exe_oblivious_transfer 1 "test_oblivious_transfer_config.txt"

Since both files are in the same folder, I'm assuming that I can specify its path with only its name "test_oblivious_transfer_config.txt"

Let me check what happens if I specify all the path to it.

andremmvgabriel commented 4 years ago

Yes, the same error occurs when I specify the entire path to the config file.

liorko87 commented 4 years ago

The error come from this line at your code: auto dlog = make_shared<OpenSSLDlogECF2m>(); The error message comes from this line at libscapi, and does not related to your OT file.

When you are using this object, it relies that a file called: ../include/configFiles/NISTEC.txt exists.

andremmvgabriel commented 4 years ago

Hmm, I've suspected also that because in the libscapi documentation, in the "Quickstart" tab, you have a sample code with the following line:

DlogGroup* dlog = new OpenSSLDlogECF2m("include/configFiles/NISTEC.txt", "K-233");

Where the path to the NISTEC file is specified. So should the error be fixed if I change the line that is giving an error as following?

auto dlog = make_shared<OpenSSLDlogECF2m>("path_to_NISTEC.txt", "K-233");
liorko87 commented 4 years ago

Yes, it should work.

andremmvgabriel commented 4 years ago

Okay, so I've changed the error line to:

auto dlog = make_shared<OpenSSLDlogECF2m>("../../../../libscapi/include/configFiles/NISTEC.txt", "K-233");

The error about the const char* was solved indeed! Thanks! However, now there is another issue showing in the console, which is:

terminate called after throwing an instance of 'std::invalid_argument'
what():  x, y values are not a point on this curve

This happens in the line: output.g0 = dlog->generateElement(false, point); Is this error because of the "K-233" specified previously?

liorko87 commented 4 years ago

I tried to run your code with K-163 and it works fine.

andremmvgabriel commented 4 years ago

Perfect! Works fine now!

Thank you for all the help you have provided.