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

Question about Using SoftSpokenOT in latest version of libOTe #158

Closed
kafei-cy opened this issue Jan 13, 2025 · 1 comment
Closed

Question about Using SoftSpokenOT in latest version of libOTe #158

kafei-cy opened this issue Jan 13, 2025 · 1 comment

Comments

@kafei-cy
Copy link

Professor, hello, I have been trying to use the latest version of the SoftSpokenOT code from libOTe/libOTe/TwoChooseOne/SoftSpokenOT. However, I encountered an issue where the sender receives two identical messages, which leads to incorrect results. Here is the testing function I used:

void softSend(u32 numElements, Socket &chl, PRNG& prng, u32 numThreads, AlignedVector<std::array<block, 2>> &sMsgs, bool fakeBase)
{
    SoftSpokenShOtSender<> sender;
    sender.init(fieldBits, true);
    const size_t numBaseOTs = sender.baseOtCount();
    PRNG prngOT(prng.get<block>());
    AlignedVector<block> baseMsg;
    // choice bits for baseOT
    BitVector baseChoice;
    if (fakeBase) {
        baseMsg.resize(numBaseOTs, ZeroBlock);
        baseChoice.resize(numBaseOTs, 0);
    } else {
        // OTE's sender is base OT's receiver
        DefaultBaseOT base;
        baseMsg.resize(numBaseOTs);
        // randomize the base OT's choice bits
        baseChoice.resize(numBaseOTs);
        baseChoice.randomize(prngOT);
        // perform the base ot, call sync_wait to block until they have completed.
        coproto::sync_wait(base.receive(baseChoice, baseMsg, prngOT, chl));
    } 
    sender.setBaseOts(baseMsg, baseChoice);
    // perform random ots

    sMsgs.resize(numElements);
    coproto::sync_wait(sender.send(sMsgs, prngOT, chl));

}

void softRecv(u32 numElements, BitVector bitV, Socket &chl, PRNG& prng, u32 numThreads, AlignedVector<block> &rMsgs, bool fakeBase)
{

    SoftSpokenShOtReceiver<> receiver;
    receiver.init(fieldBits, true);
    const size_t numBaseOTs = receiver.baseOtCount();
    AlignedVector<std::array<block, 2>> baseMsg(numBaseOTs);
    PRNG prngOT(prng.get<block>());
    if (fakeBase) {
        baseMsg.resize(numBaseOTs);
        for(auto & blk : baseMsg) {
            blk[0] = ZeroBlock;
            blk[1] = ZeroBlock;
        }
    } else {
        // OTE's receiver is base OT's sender
        DefaultBaseOT base;
        // perform the base ot, call sync_wait to block until they have completed.
        coproto::sync_wait(base.send(baseMsg, prngOT, chl));
    }
    receiver.setBaseOts(baseMsg);

    rMsgs.resize(numElements);
    coproto::sync_wait(receiver.receive(bitV, rMsgs, prngOT, chl));

}

When I tested with the following code, I found that sMsgs[i][1] is identical to sMsgs[i][0].

void ssrot_test(u32 idx, u32 logNum, u32 numThreads){

    u32 numElements = 1 << logNum;
    oc::CuckooParam params = oc::CuckooIndex<>::selectParams(numElements, ssp, 0, 3);
    u32 numBins = params.numBins();       

    Socket chl;
    chl = coproto::asioConnect("localhost:" + std::to_string(PORT + 101), idx);
    PRNG prng(sysRandomSeed());

    AlignedVector<std::array<block, 2>> sMsgs(numElements);
    AlignedVector<block> rMsgs(numElements);


    // std::cout<< "1" << std::endl;

    if(idx == 0){
        softSend(numElements, chl, prng, numThreads, sMsgs);
    }
    else if (idx == 1){
        
        BitVector bitV(numElements);
        bitV.randomize(prng);

        u32 weight = 0;
        for (u32 i = 0; i < numElements; i++){
            // std::cout<< (u32) bitV[i] << std::endl;
            if(bitV[i] == 0){
                weight += 1;
            }
        }        
        softRecv(numElements, bitV, chl, prng, numThreads, rMsgs);
        std::cout<< weight << std::endl;
    }
    // std::cout<< "2" << std::endl;


    if(idx == 1){
        coproto::sync_wait(chl.send(rMsgs));
    }
    else if (idx == 0){
        AlignedVector<block> rMsgs1(numElements);
        coproto::sync_wait(chl.recv(rMsgs1));


        u32 cout = 0;
        for(u32 i = 0; i < numElements; ++i){
            std::cout<< rMsgs1[i] << std::endl;
            if(sMsgs[i][1]== sMsgs[i][0]){
                cout += 1;
            }
        }

        std::cout<< cout << std::endl;

    }
    coproto::sync_wait(chl.flush());
    coproto::sync_wait(chl.close());

}

Could you help me understand why this is happening and how to fix it?
Thank you!

@ladnir
Copy link
Member

ladnir commented Jan 13, 2025

base ots must be random. you are getting them to zero. this has the observed effects.

@ladnir ladnir closed this as completed Jan 13, 2025
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

2 participants