Skip to content

Commit

Permalink
coefficients for constraints decided at Ali phase
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRiabzev committed Mar 18, 2018
1 parent a783f5d commit 337c172
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 89 deletions.
21 changes: 19 additions & 2 deletions libstark-tests/BairToAcsp/boundaryConstraints_UTEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,31 @@ using libstark::CBairToAcsp;
using libstark::BairWitness;
using libstark::BairInstance;
using libstark::AcspWitnessChecker;
using Algebra::FieldElement;
using Algebra::generateRandom;
using std::pair;
using std::vector;

typedef pair<BairInstance,BairWitness> BairPair;

/******************************************
* Input consistency tests
******************************************/
vector<FieldElement> getRandVector(const unsigned int len){
vector<FieldElement> res(len);
for(auto& e : res){
e = generateRandom();
}
return res;
}

TEST(BairToAcsp_boundaryConstraints,complitness){
const BairPair src = PCP_UTESTS::generate_valid_boundary();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto& bairInstance = src.first;
const auto coeffsPi = getRandVector(bairInstance.constraintsPermutation().numMappings());
const auto coeffsChi = getRandVector(bairInstance.constraintsAssignment().numMappings());
const auto instance = CBairToAcsp::reduceInstance(bairInstance, coeffsPi, coeffsChi);
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_TRUE(AcspWitnessChecker::verify_boundary(*instance,*witness));
Expand All @@ -29,7 +43,10 @@ TEST(BairToAcsp_boundaryConstraints,complitness){
TEST(BairToAcsp_boundaryConstraints,soundness){
const BairPair src = PCP_UTESTS::generate_invalid_boundary();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto& bairInstance = src.first;
const auto coeffsPi = getRandVector(bairInstance.constraintsPermutation().numMappings());
const auto coeffsChi = getRandVector(bairInstance.constraintsAssignment().numMappings());
const auto instance = CBairToAcsp::reduceInstance(bairInstance, coeffsPi, coeffsChi);
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_FALSE(AcspWitnessChecker::verify_boundary(*instance,*witness));
Expand Down
32 changes: 20 additions & 12 deletions libstark-tests/BairToAcsp/constraints_UTEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ using std::move;
using std::max;
using std::vector;

vector<FieldElement> genRandVector(const unsigned int len){
vector<FieldElement> res(len);
for(auto& e : res){
e = generateRandom();
}
return res;
}

typedef pair<BairInstance,BairWitness> BairPair;

/*************************************************************
Expand All @@ -54,7 +62,7 @@ class BairToAcsp_tester : private CBairToAcsp, private witnessReduction{
static AcspWitness ruinRoutingBit(const BairPair& bair_pair){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
witnessMappings witnessMapping(commonDef);

//ordered basis for witness space
Expand Down Expand Up @@ -95,7 +103,7 @@ class BairToAcsp_tester : private CBairToAcsp, private witnessReduction{
static AcspWitness ruinDeBruijnLastColumn(const BairPair& bair_pair){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
witnessMappings witnessMapping(commonDef);

//ordered basis for witness space
Expand Down Expand Up @@ -131,7 +139,7 @@ class BairToAcsp_tester : private CBairToAcsp, private witnessReduction{
static AcspWitness ruinAdditionalElementRouting(const BairPair& bair_pair){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
witnessMappings witnessMapping(commonDef);

//ordered basis for witness space
Expand Down Expand Up @@ -167,7 +175,7 @@ class BairToAcsp_tester : private CBairToAcsp, private witnessReduction{
static AcspWitness ruinDeBruijnVertexData(const BairPair& bair_pair){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
witnessMappings witnessMapping(commonDef);

//ordered basis for witness space
Expand Down Expand Up @@ -211,7 +219,7 @@ class BairToAcsp_tester : private CBairToAcsp, private witnessReduction{
TEST(BairToAcsp_Constraints,reductionCompletness){
const BairPair src = PCP_UTESTS::generate_valid_pair();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_TRUE(AcspWitnessChecker::verify_vanishing(*instance,*witness));
Expand All @@ -220,7 +228,7 @@ TEST(BairToAcsp_Constraints,reductionCompletness){
TEST(BairToAcsp_Constraints,reductionSoundness_routingBits){
const BairPair src = PCP_UTESTS::generate_valid_pair();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = BairToAcsp_tester::ruinRoutingBit(src);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,witness));
Expand All @@ -229,7 +237,7 @@ TEST(BairToAcsp_Constraints,reductionSoundness_routingBits){
TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnLastColumn){
const BairPair src = PCP_UTESTS::generate_valid_pair();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = BairToAcsp_tester::ruinDeBruijnLastColumn(src);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,witness));
Expand All @@ -238,7 +246,7 @@ TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnLastColumn){
TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnLastAdditionalElementRouting){
const BairPair src = PCP_UTESTS::generate_valid_pair();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = BairToAcsp_tester::ruinAdditionalElementRouting(src);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,witness));
Expand All @@ -247,7 +255,7 @@ TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnLastAdditionalElementRout
TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnDataRouting){
const BairPair src = PCP_UTESTS::generate_valid_pair();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = BairToAcsp_tester::ruinDeBruijnVertexData(src);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,witness));
Expand All @@ -256,7 +264,7 @@ TEST(BairToAcsp_Constraints,reductionSoundness_DeBruijnDataRouting){
TEST(BairToAcsp_Constraints,reductionComplitness_Constraints){
const BairPair src = PCP_UTESTS::generate_valid_constraints();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_TRUE(AcspWitnessChecker::verify_vanishing(*instance,*witness));
Expand All @@ -265,7 +273,7 @@ TEST(BairToAcsp_Constraints,reductionComplitness_Constraints){
TEST(BairToAcsp_Constraints,reductionSoundness_Permutation_Constraints){
const BairPair src = PCP_UTESTS::generate_invalid_constraints_Permutation();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,*witness));
Expand All @@ -274,7 +282,7 @@ TEST(BairToAcsp_Constraints,reductionSoundness_Permutation_Constraints){
TEST(BairToAcsp_Constraints,reductionSoundness_Assignment_Constraints){
const BairPair src = PCP_UTESTS::generate_invalid_constraints_Assignment();

const auto instance = CBairToAcsp::reduceInstance(src.first);
const auto instance = CBairToAcsp::reduceInstance(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const auto witness = CBairToAcsp::reduceWitness(src.first,src.second);

EXPECT_FALSE(AcspWitnessChecker::verify_vanishing(*instance,*witness));
Expand Down
44 changes: 26 additions & 18 deletions libstark-tests/BairToAcsp/neighborsConstructor_UTES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ using std::vector;

namespace{

vector<FieldElement> genRandVector(const unsigned int len){
vector<FieldElement> res(len);
for(auto& e : res){
e = generateRandom();
}
return res;
}

typedef pair<BairInstance,BairWitness> BairPair;

vector<pair<size_t,size_t>> constructNeighborsLocations(const vector<vector<unique_ptr<const UnivariatePolynomialInterface>>>& neighborsVec){
Expand All @@ -51,7 +59,7 @@ vector<pair<size_t,size_t>> constructNeighborsLocations(const vector<vector<uniq

void verifyID(const BairPair& bair_pair, const AcspNeighbors& neighbors){

const common defs(bair_pair.first);
const common defs(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);

//some constants
Expand Down Expand Up @@ -91,7 +99,7 @@ void verifyID(const BairPair& bair_pair, const AcspNeighbors& neighbors){

void verifyTwinLayer(const BairPair& bair_pair, const AcspNeighbors& neighbors){

const common defs(bair_pair.first);
const common defs(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);

//some constants
Expand Down Expand Up @@ -139,7 +147,7 @@ size_t cyclicShift(const size_t src, const char bitsAmount){

void verifyDeBruijn(const BairPair& bair_pair, const AcspNeighbors& neighbors){

const common defs(bair_pair.first);
const common defs(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);

//some constants
Expand Down Expand Up @@ -203,7 +211,7 @@ void verifyDeBruijn(const BairPair& bair_pair, const AcspNeighbors& neighbors){

void verifyRoutingBit(const BairPair& bair_pair, const AcspNeighbors& neighbors){

const common defs(bair_pair.first);
const common defs(bair_pair.first,genRandVector(bair_pair.first.constraintsPermutation().numMappings()),genRandVector(bair_pair.first.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);

//some constants
Expand Down Expand Up @@ -246,7 +254,7 @@ void verifyRoutingBit(const BairPair& bair_pair, const AcspNeighbors& neighbors)
void verifyPermutationConstraints(const BairPair& bair_pair, const AcspNeighbors& neighbors, const CS_testLocations& testLocations){

const BairInstance& partialInstance = bair_pair.first;
const common defs(partialInstance);
const common defs(partialInstance,genRandVector(partialInstance.constraintsPermutation().numMappings()),genRandVector(partialInstance.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);
const instanceMappings& mappings_common(defs);

Expand Down Expand Up @@ -339,7 +347,7 @@ void verifyPermutationConstraints(const BairPair& bair_pair, const AcspNeighbors
void verifyAssignmentConstraints(const BairPair& bair_pair, const AcspNeighbors& neighbors, const CS_testLocations& testLocations){

const BairInstance& partialInstance = bair_pair.first;
const common defs(partialInstance);
const common defs(partialInstance,genRandVector(partialInstance.constraintsPermutation().numMappings()),genRandVector(partialInstance.constraintsAssignment().numMappings()));
const witnessMappings mappings(defs);
const instanceMappings& mappings_common(defs);

Expand Down Expand Up @@ -461,9 +469,9 @@ void verifyAssignmentConstraints(const BairPair& bair_pair, const AcspNeighbors&
TEST(BairToAcspNeighbors,verifyID){
//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

verifyID(src,neighbors);
Expand All @@ -473,9 +481,9 @@ TEST(BairToAcspNeighbors,verifyTwinLayer){

//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

//if there is no routing network, there is not expected a
Expand All @@ -489,9 +497,9 @@ TEST(BairToAcspNeighbors,verifyDeBruijn){

//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

//if there is no routing network, there is not expected a
Expand All @@ -505,9 +513,9 @@ TEST(BairToAcspNeighbors,verifyRoutingBit){

//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

//if there is no routing network, there is not expected a
Expand All @@ -521,9 +529,9 @@ TEST(BairToAcspNeighbors,verifyPermutationConstraintsSystem){

//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

verifyPermutationConstraints(src,neighbors,testLocations);
Expand All @@ -533,9 +541,9 @@ TEST(BairToAcspNeighbors,verifyAssignmentConstraintsSystem){

//initialize neighbors instance
const BairPair src = PCP_UTESTS::generate_valid_constraints();
const common defs(src.first);
const common defs(src.first,genRandVector(src.first.constraintsPermutation().numMappings()),genRandVector(src.first.constraintsAssignment().numMappings()));
const instanceMappings mappings(defs);
const CS_testLocations testLocations(src.first);
const CS_testLocations testLocations(defs);
const AcspNeighbors neighbors(src.first,defs,mappings,testLocations);

verifyAssignmentConstraints(src,neighbors,testLocations);
Expand Down
6 changes: 3 additions & 3 deletions libstark-tests/BairToAcsp/witnessReduction_UTEST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FieldElement advanceToNextRow(const FieldElement src, const common& commonInfo){
void verifyIntegrity(const BairPair& bair_pair, const AcspWitness& acsp_witness){

//get common information
const common commonDef(bair_pair.first);
const common commonDef(bair_pair.first,vector<FieldElement>(), vector<FieldElement>());
const witnessMappings witnessMapping(commonDef);
const commonMappings& commonMapping = witnessMapping;

Expand Down Expand Up @@ -143,7 +143,7 @@ size_t cyclicShift(const size_t src, const char bitsAmount){
void verifyRoutingNetwork(const BairPair& bair_pair, const AcspWitness& acsp_witness){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,vector<FieldElement>(), vector<FieldElement>());
witnessMappings witnessMapping(commonDef);

//get the Bair pair
Expand Down Expand Up @@ -243,7 +243,7 @@ void verifyRoutingNetwork(const BairPair& bair_pair, const AcspWitness& acsp_wit
void verifyPermutation_aditionalElement(const BairPair& bair_pair, const AcspWitness& acsp_witness){

//get common information
common commonDef(bair_pair.first);
common commonDef(bair_pair.first,vector<FieldElement>(), vector<FieldElement>());
witnessMappings witnessMapping(commonDef);

//get the Bair pair
Expand Down
2 changes: 2 additions & 0 deletions libstark/src/protocols/Ali/common_details/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class verifierMsg : public TranscriptMessage{
public:
virtual ~verifierMsg(){};
randomCoeffsSet_t randomCoefficients;
std::vector<Algebra::FieldElement> coeffsPi;
std::vector<Algebra::FieldElement> coeffsChi;
Ali::details::rawQueries_t queries;
std::unique_ptr<TranscriptMessage> RS_verifier_witness_msg;
std::unique_ptr<TranscriptMessage> RS_verifier_composition_msg;
Expand Down
Loading

0 comments on commit 337c172

Please sign in to comment.