Skip to content

Commit

Permalink
Merge pull request scipr-lab#10 from gnosis/toString
Browse files Browse the repository at this point in the history
Include toString() functions to some relevant (serial classes) that c…
  • Loading branch information
bh2smith authored Dec 10, 2018
2 parents f0066c0 + c268306 commit 730858e
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/relations/objects/Assignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Assignment<FieldT extends AbstractFieldElementExpanded<FieldT>> implements
Expand All @@ -32,6 +33,10 @@ public Assignment(final Assignment<FieldT> primary, final Assignment<FieldT> aux
elements.addAll(auxiliary.elements());
}

public String toString() {
return Arrays.toString(this.elements.toArray());
}

public ArrayList<FieldT> elements() {
return elements;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/relations/objects/LinearCombination.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;

public class LinearCombination<FieldT extends AbstractFieldElementExpanded<FieldT>> implements
Serializable {
Expand Down Expand Up @@ -73,4 +74,9 @@ public ArrayList<LinearTerm<FieldT>> terms() {
public int size() {
return terms.size();
}

@Override
public String toString() {
return Arrays.toString(this.terms.toArray()) + '\n';
}
}
5 changes: 5 additions & 0 deletions src/main/java/relations/objects/LinearTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public long index() {
public FieldT value() {
return value;
}

@Override
public String toString() {
return "c_" + index + ": " + value;
}
}
11 changes: 11 additions & 0 deletions src/main/java/relations/objects/R1CSConstraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import algebra.fields.AbstractFieldElementExpanded;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
* A R1CSRelation constraint is a formal expression of the form
Expand Down Expand Up @@ -61,4 +63,13 @@ public LinearCombination<FieldT> C() {
return C;
}

@Override
public String toString() {
List<String> list = Arrays.asList(
"A: " + this.A,
"B: " + this.B,
"C: " + this.C
);
return String.join(",", list) + "\n";
}
}
6 changes: 6 additions & 0 deletions src/main/java/relations/objects/R1CSConstraints.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import algebra.fields.AbstractFieldElementExpanded;

import java.io.Serializable;
import java.util.Arrays;
import java.util.ArrayList;

/**
Expand Down Expand Up @@ -52,4 +53,9 @@ public ArrayList<R1CSConstraint<FieldT>> constraints() {
public int size() {
return constraints.size();
}

@Override
public String toString() {
return Arrays.toString(this.constraints.toArray());
}
}
15 changes: 14 additions & 1 deletion src/main/java/relations/r1cs/R1CSRelation.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import relations.objects.R1CSConstraints;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
* A system of R1CSRelation constraints looks like
Expand Down Expand Up @@ -83,7 +85,7 @@ public boolean isSatisfied(final Assignment<FieldT> primary, final Assignment<Fi
final FieldT c = constraints.get(i).C().evaluate(oneFullAssignment);

if (!a.mul(b).equals(c)) {
System.out.println("R1CSConstraint unsatisfied:");
System.out.println("R1CSConstraint unsatisfied at row " + i);
System.out.println("<a,(1,x)> = " + a);
System.out.println("<b,(1,x)> = " + b);
System.out.println("<c,(1,x)> = " + c);
Expand All @@ -110,4 +112,15 @@ public int numConstraints() {
return numConstraints;
}

public String toString() {
List<String> list = Arrays.asList(
"numInputs: " + this.numInputs,
"numAuxiliary: " + this.numAuxiliary,
"numConstraints: " + this.numConstraints,
"Constraints: \n" + this.constraints.toString()
);
return String.join("\n", list);

}

}
5 changes: 5 additions & 0 deletions src/main/java/zk_proof_systems/zkSNARK/objects/Proof.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Proof<G1T extends AbstractG1<G1T>, G2T extends AbstractG2<G2T>> {
private final G2T gB;
private final G1T gC;

@Override
public String toString() {
return String.format("Proof:\ngA = [%s]\ngB = [%s]\ngC = [%s]\n", gA, gB, gC);
}

public Proof(final G1T _gA, final G2T _gB, final G1T _gC) {
gA = _gA;
gB = _gB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ public List<G1T> queryH() {
public R1CSRelation<FieldT> r1cs() {
return r1cs;
}

@Override
public String toString() {
return String.format(
"alphaG1 = %s\nbetaG1 = %s\nbetaG2 = %s\ndeltaG1 = %s\ndeltaG2 = %s\ndeltaABCG1 = %s\nqueryA = %s\nqueryB = %s\nqueryH = %s\n",
alphaG1, betaG1, betaG2, deltaG1, deltaG2, deltaABCG1.size(), queryA.size(), queryB.size(), queryH.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@ public JavaPairRDD<Long, G1T> queryH() {
public R1CSRelationRDD<FieldT> r1cs() {
return r1cs;
}

@Override
public String toString() {
return String.format(
"alphaG1 = %s\nbetaG1 = %s\nbetaG2 = %s\ndeltaG1 = %s\ndeltaG2 = %s\ndeltaABCG1 = %s\nqueryA = %s\nqueryB = %s\nqueryH = %s\n",
alphaG1, betaG1, betaG2, deltaG1, deltaG2, deltaABCG1, queryA, queryB, queryH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public class VerificationKey<G1T extends AbstractG1<G1T>, G2T extends AbstractG2
private final G2T deltaG2;
private final List<G1T> gammaABC;

@Override
public String toString() {
return String.format(
"Verification Key:\nalphaG1betaG2 = %s\ngammaG2 = %s\ndeltaG2 = %s\ngammaABC = %s\n",
alphaG1betaG2, gammaG2, deltaG2.bitSize(), gammaABC.size());
}

public VerificationKey(
final GTT _alphaG1betaG2,
final G2T _gammaG2,
Expand Down

0 comments on commit 730858e

Please sign in to comment.