Skip to content

Commit

Permalink
Add Eager Scheduler support for composite AND operation (#100)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #100

- Adds support for the Eager Scheduler to call composite AND operations in secret share engine
- Added EagerScheduler to composite AND test fixture

Reviewed By: elliottlawrence

Differential Revision: D34701213

fbshipit-source-id: 4374cdde90818a375af3e1a255cb49c4df59183d
  • Loading branch information
Tal Davidi authored and facebook-github-bot committed Mar 17, 2022
1 parent 4c695e0 commit 2e1a00d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
58 changes: 52 additions & 6 deletions fbpcf/scheduler/EagerScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,42 +166,88 @@ std::vector<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::privateAndPrivateComposite(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
nonFreeGates_ += rights.size();
std::vector<bool> 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<IScheduler::WireId<IScheduler::Boolean>> outputWires(
result.size());
for (size_t i = 0; i < rights.size(); i++) {
outputWires[i] = wireKeeper_->allocateBooleanValue(result[i]);
}
return outputWires;
}

std::vector<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::privateAndPrivateCompositeBatch(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
auto leftValues = wireKeeper_->getBatchBooleanValue(left);
nonFreeGates_ += leftValues.size() * rights.size();
std::vector<std::vector<bool>> 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<IScheduler::WireId<IScheduler::Boolean>> outputWires(
result.size());
for (size_t i = 0; i < result.size(); i++) {
outputWires[i] = wireKeeper_->allocateBatchBooleanValue(result[i]);
}
return outputWires;
}

std::vector<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::privateAndPublicComposite(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
freeGates_ += rights.size();
std::vector<IScheduler::WireId<IScheduler::Boolean>> 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<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::privateAndPublicCompositeBatch(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
auto leftValues = wireKeeper_->getBatchBooleanValue(left);
freeGates_ += leftValues.size() * rights.size();
std::vector<IScheduler::WireId<IScheduler::Boolean>> 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<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::publicAndPublicComposite(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
return privateAndPublicComposite(left, rights);
}

std::vector<IScheduler::WireId<IScheduler::Boolean>>
EagerScheduler::publicAndPublicCompositeBatch(
IScheduler::WireId<IScheduler::Boolean> left,
std::vector<IScheduler::WireId<IScheduler::Boolean>> rights) {
throw std::runtime_error("Not implemented");
return privateAndPublicCompositeBatch(left, rights);
}

IScheduler::WireId<IScheduler::Boolean> EagerScheduler::privateXorPrivate(
Expand Down
3 changes: 2 additions & 1 deletion fbpcf/scheduler/test/SchedulerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompositeSchedulerTestFixture::ParamType>&
info) {
Expand Down

0 comments on commit 2e1a00d

Please sign in to comment.