Skip to content

Commit f799784

Browse files
Ajinkya Ghongefacebook-github-bot
Ajinkya Ghonge
authored andcommitted
Called the OramEncoder library.
Summary: # Context As per PC Translator design, we need a runtime library will be called during PC run. This library will be called at the beginning of PC run to encode specified fields in publisher side input into a encoded breakdown (aggregation) Ids based on active PC instruction sets for the run. The library will filter the active PC Instruction sets for the run based on parsing the pcs_features i.e. gatekeepers for the particular run. # Product decisions In this stack we would focus solely on functionality required for private lift runs. We would focus on the MVP implementation of the library and its integration with fbpcf ORAM encoder library in this stack. # Stack 1. Create runtime pc_translator library. 2. Add logic to retrieve and parse PC instruction set, filtered based on the active gatekeepers for the run. 3. Integrate pc_translator library with fbpcf ORAM encoder. 4. Add logic to generate transformed publisher output with encoded breakdown ID and write the output. # In this diff Integrate pc_translator library with fbpcf ORAM encoder. Differential Revision: D44634384 Privacy Context Container: L416713 fbshipit-source-id: 0c5c1463aeb6201bd1fbcfe6aa5c0ed6d5c01bac
1 parent 70e87f9 commit f799784

6 files changed

+115
-24
lines changed

fbpcs/pc_translator/PCTranslator.cpp

+55-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
#include <fbpcf/common/FunctionalUtil.h>
1212
#include <fbpcf/io/api/FileIOWrappers.h>
13+
#include <fbpcf/mpc_std_lib/oram/encoder/IFilter.h>
14+
#include <fbpcf/mpc_std_lib/oram/encoder/IOramEncoder.h>
15+
#include <fbpcf/mpc_std_lib/oram/encoder/OramEncoder.h>
16+
#include <algorithm>
1317
#include <set>
18+
#include "fbpcs/emp_games/common/Csv.h"
1419
#include "folly/String.h"
1520

1621
namespace pc_translator {
@@ -20,8 +25,8 @@ std::string PCTranslator::encode(const std::string& input_dataset) {
2025
PCTranslator::retrieveInstructionSetNamesForRun(pcs_features_);
2126
auto pcInstructionSets =
2227
PCTranslator::retrieveInstructionSets(validInstructionSetNames);
23-
PCTranslator::transformDataset(input_dataset, pcInstructionSets);
24-
return "";
28+
return PCTranslator::transformDataset(
29+
input_dataset, pcInstructionSets.front());
2530
}
2631

2732
std::string PCTranslator::decode(const std::string& aggregated_output_dataset) {
@@ -33,7 +38,13 @@ PCTranslator::retrieveInstructionSets(
3338
std::vector<std::string>& instructionSetNames) {
3439
std::vector<std::shared_ptr<PCInstructionSet>> pcInstructionSets;
3540
for (auto instructionSetName : instructionSetNames) {
36-
auto file_path = instruction_set_base_path + instructionSetName + ".json";
41+
instructionSetName.erase(
42+
remove(instructionSetName.begin(), instructionSetName.end(), '\''),
43+
instructionSetName.end());
44+
instructionSetName.erase(
45+
remove(instructionSetName.begin(), instructionSetName.end(), ' '),
46+
instructionSetName.end());
47+
auto file_path = instruction_set_base_path_ + instructionSetName + ".json";
3748
auto contents = fbpcf::io::FileIOWrappers::readFile(file_path);
3849
pcInstructionSets.push_back(PCTranslator::parseInstructionSet(contents));
3950
}
@@ -54,16 +65,52 @@ std::vector<std::string> PCTranslator::retrieveInstructionSetNamesForRun(
5465
enabledFeatureFlags.begin(),
5566
enabledFeatureFlags.end(),
5667
std::back_inserter(validPCInstructionSets),
57-
[](const std::string& feature) { return feature.find("pc_instr") == 0; });
68+
[](const std::string& feature) {
69+
return feature.find("pc_instr") != std::string::npos;
70+
});
5871

5972
return validPCInstructionSets;
6073
}
6174

62-
void PCTranslator::transformDataset(
75+
std::string PCTranslator::transformDataset(
6376
const std::string& input_data,
64-
const std::vector<std::shared_ptr<pc_translator::PCInstructionSet>>&
65-
pcInstructionSets) {
66-
throw std::runtime_error("Unimplemented");
77+
std::shared_ptr<pc_translator::PCInstructionSet> pcInstructionSet) {
78+
// Parse the input CSV
79+
auto lineNo = 0;
80+
std::vector<std::vector<uint32_t>> inputColums;
81+
private_measurement::csv::readCsv(
82+
input_data,
83+
[&](const std::vector<std::string>& header,
84+
const std::vector<std::string>& parts) {
85+
std::vector<uint32_t> inputColumnPerRow;
86+
for (std::vector<std::string>::size_type i = 0; i < header.size();
87+
++i) {
88+
auto column = header[i];
89+
auto value = std::atoi(parts[i].c_str());
90+
auto iter = std::find(
91+
pcInstructionSet->getGroupByIds().begin(),
92+
pcInstructionSet->getGroupByIds().end(),
93+
column);
94+
if (iter != pcInstructionSet->getGroupByIds().end()) {
95+
inputColumnPerRow.push_back(value);
96+
}
97+
}
98+
99+
inputColums.push_back(inputColumnPerRow);
100+
lineNo++;
101+
});
102+
103+
auto filters = std::make_unique<
104+
std::vector<std::unique_ptr<fbpcf::mpc_std_lib::oram::IFilter>>>(0);
105+
std::unique_ptr<fbpcf::mpc_std_lib::oram::IOramEncoder> encoder =
106+
std::make_unique<fbpcf::mpc_std_lib::oram::OramEncoder>(
107+
std::move(filters));
108+
109+
auto encodedIndexes = encoder->generateORAMIndexes(inputColums);
110+
111+
// TODO : Append the enodedIndexes at the end of publisher output and return
112+
// output path.
113+
return "";
67114
}
68115

69116
std::shared_ptr<PCInstructionSet> PCTranslator::parseInstructionSet(

fbpcs/pc_translator/PCTranslator.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ class PCTranslator {
2626
explicit PCTranslator(const std::string& pcs_features)
2727
: pcs_features_(pcs_features) {}
2828

29-
/*
30-
* Method to encode the configurable fields in input dataset as per the active
31-
* pc instruction sets for the run. This method will output the path of
32-
* transformed input dataset, which can be used in further PC run.
33-
*/
29+
explicit PCTranslator(
30+
const std::string& pcs_features,
31+
const std::string& instruction_set_base_path)
32+
: pcs_features_(pcs_features),
33+
instruction_set_base_path_(instruction_set_base_path) {}
34+
3435
std::string encode(const std::string& input_dataset);
3536

3637
/*
@@ -43,18 +44,17 @@ class PCTranslator {
4344

4445
private:
4546
std::string pcs_features_;
46-
const std::string instruction_set_base_path =
47+
std::string instruction_set_base_path_ =
4748
"https://pc-translator.s3.us-west-2.amazonaws.com/";
4849
std::vector<std::shared_ptr<PCInstructionSet>> retrieveInstructionSets(
4950
std::vector<std::string>& instructionSetNames);
5051
std::vector<std::string> retrieveInstructionSetNamesForRun(
5152
const std::string& pcs_features);
5253
std::shared_ptr<PCInstructionSet> parseInstructionSet(
5354
const std::string& instructionSet);
54-
void transformDataset(
55+
std::string transformDataset(
5556
const std::string& input_data,
56-
const std::vector<std::shared_ptr<pc_translator::PCInstructionSet>>&
57-
pcInstructionSets);
57+
std::shared_ptr<pc_translator::PCInstructionSet> pcInstructionSet);
5858
};
5959

6060
} // namespace pc_translator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <gtest/gtest.h>
9+
#include "../../emp_games/common/TestUtil.h"
10+
#include "fbpcs/pc_translator/PCTranslator.h"
11+
12+
namespace pc_translator {
13+
class TestPCTranslator : public ::testing::Test {
14+
public:
15+
protected:
16+
std::string pcs_features_;
17+
std::string test_instruction_set_base_path_;
18+
std::string test_publisher_input_path_;
19+
20+
void SetUp() override {
21+
pcs_features_ =
22+
"'num_mpc_container_mutation', 'private_lift_unified_data_process', 'pc_instr_test_instruction_set'";
23+
std::string baseDir =
24+
private_measurement::test_util::getBaseDirFromPath(__FILE__);
25+
test_instruction_set_base_path_ = baseDir + "input_processing/";
26+
test_publisher_input_path_ = baseDir + "publisher_unittest.csv";
27+
}
28+
};
29+
30+
TEST_F(TestPCTranslator, TestEncode) {
31+
auto pcTranslator = std::make_shared<PCTranslator>(
32+
pcs_features_, test_instruction_set_base_path_);
33+
auto outputPath = pcTranslator->encode(test_publisher_input_path_);
34+
EXPECT_EQ(outputPath, "");
35+
}
36+
} // namespace pc_translator

fbpcs/pc_translator/tests/input_processing/TestPCInstructionSet.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <gtest/gtest.h>
1414
#include "../../../emp_games/common/TestUtil.h"
1515
#include "fbpcs/pc_translator/input_processing/PCInstructionSet.h"
16-
#include "folly/Random.h"
1716

1817
namespace pc_translator {
1918
class TestPCInstructionSet : public ::testing::Test {
@@ -24,7 +23,7 @@ class TestPCInstructionSet : public ::testing::Test {
2423
void SetUp() override {
2524
std::string baseDir =
2625
private_measurement::test_util::getBaseDirFromPath(__FILE__);
27-
test_instruction_set_path_ = baseDir + "test_instruction_set.json";
26+
test_instruction_set_path_ = baseDir + "pc_instr_test_instruction_set.json";
2827
}
2928
};
3029

@@ -35,7 +34,7 @@ TEST_F(TestPCInstructionSet, TestStandardWorkflowTest) {
3534
auto groupByIds = pcInstructionSet->getGroupByIds();
3635
auto filterConstraints = pcInstructionSet->getFilterConstraints();
3736
EXPECT_EQ(groupByIds.size(), 2);
38-
EXPECT_EQ(filterConstraints.size(), 4);
37+
EXPECT_EQ(filterConstraints.size(), 3);
3938
EXPECT_EQ(filterConstraints[0].getName(), "gender");
4039
EXPECT_EQ(filterConstraints[0].getType(), "EQ");
4140
EXPECT_EQ(filterConstraints[0].getValue(), 0);

fbpcs/pc_translator/tests/input_processing/test_instruction_set.json fbpcs/pc_translator/tests/input_processing/pc_instr_test_instruction_set.json

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
{
3131
"constraint_type": "EQ",
3232
"value": "0"
33-
},
34-
{
35-
"constraint_type": "EQ",
36-
"value": "1"
3733
}
3834
]
3935
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
id_,opportunity,test_flag,opportunity_timestamp, age, gender
2+
cfcd208495d565ef66e7dff9f98764da,1,0,1600000430, 25, 0
3+
c4ca4238a0b923820dcc509a6f75849b,1,1,1600000401, 26, 1
4+
c81e728d9d4c2f636f067f89cc14862c,0,0,0, 44, 0
5+
eccbc87e4b5ce2fe28308fd9f2a7baf3,0,0,0, 23, 0
6+
a87ff679a2f3e71d9181a67b7542122c,0,0,0, 25, 0
7+
e4da3b7fbbce2345d7772b0674a318d5,1,1,1600000461, 24, 1
8+
1679091c5a880faf6fb5e6087eb1b2dc,1,0,1600000052, 25, 1
9+
8f14e45fceea167a5a36dedd4bea2543,1,0,1600000831, 26, 0
10+
c9f0f895fb98ab9159f51fd0297e236d,1,0,1600000530, 50, 0
11+
45c48cce2e2d7fbdea1afc51c7c6ad26,1,0,1600000972, 25, 1
12+
d3d9446802a44259755d38e6d163e820,0,0,0, 25, 0
13+
6512bd43d9caa6e02c990b0a82652dca,0,0,0, 25, 0

0 commit comments

Comments
 (0)