diff --git a/fbpcf/scheduler/EagerScheduler.cpp b/fbpcf/scheduler/EagerScheduler.cpp index 4e139b4a..f5486dbb 100644 --- a/fbpcf/scheduler/EagerScheduler.cpp +++ b/fbpcf/scheduler/EagerScheduler.cpp @@ -166,42 +166,88 @@ std::vector> EagerScheduler::privateAndPrivateComposite( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + nonFreeGates_ += rights.size(); + std::vector rightValues(rights.size()); + for (size_t i = 0; i < rights.size(); i++) { + rightValues[i] = wireKeeper_->getBooleanValue(rights[i]); + } + auto index = engine_->scheduleCompositeAND( + wireKeeper_->getBooleanValue(left), rightValues); + engine_->executeScheduledAND(); + auto result = engine_->getCompositeANDExecutionResult(index); + std::vector> outputWires( + result.size()); + for (size_t i = 0; i < rights.size(); i++) { + outputWires[i] = wireKeeper_->allocateBooleanValue(result[i]); + } + return outputWires; } std::vector> EagerScheduler::privateAndPrivateCompositeBatch( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + auto leftValues = wireKeeper_->getBatchBooleanValue(left); + nonFreeGates_ += leftValues.size() * rights.size(); + std::vector> rightValues; + for (size_t i = 0; i < rights.size(); i++) { + rightValues.push_back(wireKeeper_->getBatchBooleanValue(rights[i])); + } + + auto index = engine_->scheduleBatchCompositeAND(leftValues, rightValues); + engine_->executeScheduledAND(); + auto result = engine_->getBatchCompositeANDExecutionResult(index); + std::vector> outputWires( + result.size()); + for (size_t i = 0; i < result.size(); i++) { + outputWires[i] = wireKeeper_->allocateBatchBooleanValue(result[i]); + } + return outputWires; } std::vector> EagerScheduler::privateAndPublicComposite( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + freeGates_ += rights.size(); + std::vector> outputWires( + rights.size()); + for (size_t i = 0; i < rights.size(); i++) { + outputWires[i] = wireKeeper_->allocateBooleanValue(engine_->computeFreeAND( + wireKeeper_->getBooleanValue(left), + wireKeeper_->getBooleanValue(rights[i]))); + } + return outputWires; } std::vector> EagerScheduler::privateAndPublicCompositeBatch( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + auto leftValues = wireKeeper_->getBatchBooleanValue(left); + freeGates_ += leftValues.size() * rights.size(); + std::vector> outputWires( + rights.size()); + for (size_t i = 0; i < rights.size(); i++) { + outputWires[i] = + wireKeeper_->allocateBatchBooleanValue((engine_->computeBatchFreeAND( + leftValues, wireKeeper_->getBatchBooleanValue(rights[i])))); + } + return outputWires; } std::vector> EagerScheduler::publicAndPublicComposite( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + return privateAndPublicComposite(left, rights); } std::vector> EagerScheduler::publicAndPublicCompositeBatch( IScheduler::WireId left, std::vector> rights) { - throw std::runtime_error("Not implemented"); + return privateAndPublicCompositeBatch(left, rights); } IScheduler::WireId EagerScheduler::privateXorPrivate( diff --git a/fbpcf/scheduler/test/SchedulerTest.cpp b/fbpcf/scheduler/test/SchedulerTest.cpp index b9e177b0..2e24be43 100644 --- a/fbpcf/scheduler/test/SchedulerTest.cpp +++ b/fbpcf/scheduler/test/SchedulerTest.cpp @@ -497,7 +497,8 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( SchedulerType::Plaintext, SchedulerType::NetworkPlaintext, - SchedulerType::Lazy), + SchedulerType::Lazy, + SchedulerType::Eager), ::testing::Values(16, 256, 1024)), [](const testing::TestParamInfo& info) {