Last active
July 4, 2017 10:18
-
-
Save tjade273/89419dd2c12ad7c0c57f4da19ca1e3fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include <gadgetlib2/gadget.hpp> | |
#include "gadgetlib2/adapters.hpp" | |
#include "gadgetlib2/integration.hpp" | |
#include "relations/constraint_satisfaction_problems/r1cs/examples/r1cs_examples.hpp" | |
#include "gadgetlib2/examples/simple_example.hpp" | |
#include "zk_proof_systems/ppzksnark/r1cs_ppzksnark/examples/run_r1cs_ppzksnark.hpp" | |
using namespace libsnark; | |
using namespace gadgetlib2; | |
TEST(Examples, Multiply){ | |
typedef Fr<default_ec_pp> FieldT; | |
initPublicParamsFromDefaultPp(); | |
ProtoboardPtr pb = Protoboard::create(R1P); | |
VariableArray input(2, "input"); | |
Variable output("output"); | |
pb->addRank1Constraint(input[0], input[1], output, | |
"input[0] * input[1] = input[2]"); | |
pb->val(input[0]) = 13; | |
pb->val(input[1]) = 17; | |
pb->val(output) = 100; | |
EXPECT_FALSE(pb->isSatisfied()); | |
pb->val(output) = 221; | |
EXPECT_TRUE(pb->isSatisfied()); | |
r1cs_constraint_system<FieldT> cs = get_constraint_system_from_gadgetlib2(*pb); | |
const r1cs_variable_assignment<FieldT> full_assignment = get_variable_assignment_from_gadgetlib2(*pb); | |
const r1cs_primary_input<FieldT> primary_input(full_assignment.begin(), full_assignment.begin() + cs.num_inputs()); | |
const r1cs_auxiliary_input<FieldT> auxiliary_input(full_assignment.begin() + cs.num_inputs(), full_assignment.end()); | |
std::cerr << "[ ] num_imputs = " << cs.num_inputs()<< std::endl; | |
EXPECT_TRUE(cs.is_satisfied(primary_input, auxiliary_input)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment