encryptogroup / MOTION

An efficient, user-friendly, modular, and extensible framework for mixed-protocol secure multi-party computation with two or more parties
MIT License
85 stars 40 forks source link

Using the circuit generated by hycc to achieve the millionaire problem with two parties. #23

Closed scg258 closed 2 years ago

scg258 commented 2 years ago

The circuit generated by hycc is used to achieve the millionaire problem of parties. It was compiled successfully, but the program crashed when it ran to the 7th line (const auto result{input.Evaluate(millionaires_algorithm)};) . Can you help me point out the error?

void EvaluateProtocol(mo::PartyPointer& party, std::uint32_t value) {

  encrypto::motion::ShareWrapper input{party->In<encrypto::motion::MpcProtocol::kBmr>(mo::ToInput(value),0)};

  const auto kPathToAlgorithm{std::string(encrypto::motion::kRootDir)+"/circuits/advanced/millionaires.bristol"};
  const auto millionaires_algorithm{encrypto::motion::AlgorithmDescription::FromBristol(kPathToAlgorithm)};
  const auto result{input.Evaluate(millionaires_algorithm)};

  encrypto::motion::ShareWrapper output;
  output=result.Out();

  party->Run();
  party->Finish();

  auto richer=output.As<std::uint32_t>();
  std::cout<<"Party "<<richer<<" is the richest party."<<std::endl;

}

The files entered into hycc are as follows:

void mpc_main(){
    int INPUT_A_money;
    int INPUT_B_money;
    int OUTPUT_res=0;
    if(INPUT_B_money>INPUT_A_money){
        OUTPUT_res=1;
    }
}
scg258 commented 2 years ago

Should I change it as the following?

void EvaluateProtocol(mo::PartyPointer& party, std::uint32_t value) {

  encrypto::motion::ShareWrapper input0{party->In<encrypto::motion::MpcProtocol::kBmr>(mo::ToInput(value),0)};
  encrypto::motion::ShareWrapper input1{party->In<encrypto::motion::MpcProtocol::kBmr>(mo::ToInput(value),1)};

  const auto kPathToAlgorithm{std::string(encrypto::motion::kRootDir)+"/circuits/advanced/millionaires.bristol"};
  const auto millionaires_algorithm{encrypto::motion::AlgorithmDescription::FromBristol(kPathToAlgorithm)};
  const auto result{input0.Evaluate(millionaires_algorithm)};
  const auto result{input1.Evaluate(millionaires_algorithm)};

  encrypto::motion::ShareWrapper output;
  output=result.Out();

  party->Run();
  party->Finish();

  auto richer=output.As<std::uint32_t>();
  std::cout<<"Party "<<richer<<" is the richest party."<<std::endl;

}
scg258 commented 2 years ago

I have solved.