From c268306b2693ce7fa20e5924dfe83cd2d2e26ee3 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Fri, 7 Dec 2018 14:53:13 +0100 Subject: [PATCH] Include toString() functions to some relevant (serial classes) that can help for debugging. --- src/main/java/relations/objects/Assignment.java | 5 +++++ .../java/relations/objects/LinearCombination.java | 6 ++++++ src/main/java/relations/objects/LinearTerm.java | 5 +++++ .../java/relations/objects/R1CSConstraint.java | 11 +++++++++++ .../java/relations/objects/R1CSConstraints.java | 6 ++++++ src/main/java/relations/r1cs/R1CSRelation.java | 15 ++++++++++++++- .../zk_proof_systems/zkSNARK/objects/Proof.java | 5 +++++ .../zkSNARK/objects/ProvingKey.java | 7 +++++++ .../zkSNARK/objects/ProvingKeyRDD.java | 7 +++++++ .../zkSNARK/objects/VerificationKey.java | 7 +++++++ 10 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/main/java/relations/objects/Assignment.java b/src/main/java/relations/objects/Assignment.java index 07e2d67..7ff15d7 100755 --- a/src/main/java/relations/objects/Assignment.java +++ b/src/main/java/relations/objects/Assignment.java @@ -11,6 +11,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class Assignment> implements @@ -32,6 +33,10 @@ public Assignment(final Assignment primary, final Assignment aux elements.addAll(auxiliary.elements()); } + public String toString() { + return Arrays.toString(this.elements.toArray()); + } + public ArrayList elements() { return elements; } diff --git a/src/main/java/relations/objects/LinearCombination.java b/src/main/java/relations/objects/LinearCombination.java index 979b91e..b86ef8f 100755 --- a/src/main/java/relations/objects/LinearCombination.java +++ b/src/main/java/relations/objects/LinearCombination.java @@ -11,6 +11,7 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; public class LinearCombination> implements Serializable { @@ -73,4 +74,9 @@ public ArrayList> terms() { public int size() { return terms.size(); } + + @Override + public String toString() { + return Arrays.toString(this.terms.toArray()) + '\n'; + } } diff --git a/src/main/java/relations/objects/LinearTerm.java b/src/main/java/relations/objects/LinearTerm.java index 45234bf..62c0d87 100755 --- a/src/main/java/relations/objects/LinearTerm.java +++ b/src/main/java/relations/objects/LinearTerm.java @@ -26,4 +26,9 @@ public long index() { public FieldT value() { return value; } + + @Override + public String toString() { + return "c_" + index + ": " + value; + } } \ No newline at end of file diff --git a/src/main/java/relations/objects/R1CSConstraint.java b/src/main/java/relations/objects/R1CSConstraint.java index 5eb51f8..d45b996 100755 --- a/src/main/java/relations/objects/R1CSConstraint.java +++ b/src/main/java/relations/objects/R1CSConstraint.java @@ -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 @@ -61,4 +63,13 @@ public LinearCombination C() { return C; } + @Override + public String toString() { + List list = Arrays.asList( + "A: " + this.A, + "B: " + this.B, + "C: " + this.C + ); + return String.join(",", list) + "\n"; + } } diff --git a/src/main/java/relations/objects/R1CSConstraints.java b/src/main/java/relations/objects/R1CSConstraints.java index aff57de..7c1afc1 100755 --- a/src/main/java/relations/objects/R1CSConstraints.java +++ b/src/main/java/relations/objects/R1CSConstraints.java @@ -10,6 +10,7 @@ import algebra.fields.AbstractFieldElementExpanded; import java.io.Serializable; +import java.util.Arrays; import java.util.ArrayList; /** @@ -52,4 +53,9 @@ public ArrayList> constraints() { public int size() { return constraints.size(); } + + @Override + public String toString() { + return Arrays.toString(this.constraints.toArray()); + } } diff --git a/src/main/java/relations/r1cs/R1CSRelation.java b/src/main/java/relations/r1cs/R1CSRelation.java index d7f8e21..c9f420b 100755 --- a/src/main/java/relations/r1cs/R1CSRelation.java +++ b/src/main/java/relations/r1cs/R1CSRelation.java @@ -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 @@ -83,7 +85,7 @@ public boolean isSatisfied(final Assignment primary, final Assignment = " + a); System.out.println(" = " + b); System.out.println(" = " + c); @@ -110,4 +112,15 @@ public int numConstraints() { return numConstraints; } + public String toString() { + List list = Arrays.asList( + "numInputs: " + this.numInputs, + "numAuxiliary: " + this.numAuxiliary, + "numConstraints: " + this.numConstraints, + "Constraints: \n" + this.constraints.toString() + ); + return String.join("\n", list); + + } + } diff --git a/src/main/java/zk_proof_systems/zkSNARK/objects/Proof.java b/src/main/java/zk_proof_systems/zkSNARK/objects/Proof.java index 52d0177..4b35fcc 100755 --- a/src/main/java/zk_proof_systems/zkSNARK/objects/Proof.java +++ b/src/main/java/zk_proof_systems/zkSNARK/objects/Proof.java @@ -16,6 +16,11 @@ public class Proof, G2T extends AbstractG2> { 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; diff --git a/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKey.java b/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKey.java index 68eb7d0..0b3c104 100755 --- a/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKey.java +++ b/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKey.java @@ -93,4 +93,11 @@ public List queryH() { public R1CSRelation 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()); + } } diff --git a/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKeyRDD.java b/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKeyRDD.java index 93ed0c5..728af0e 100755 --- a/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKeyRDD.java +++ b/src/main/java/zk_proof_systems/zkSNARK/objects/ProvingKeyRDD.java @@ -93,4 +93,11 @@ public JavaPairRDD queryH() { public R1CSRelationRDD 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); + } } diff --git a/src/main/java/zk_proof_systems/zkSNARK/objects/VerificationKey.java b/src/main/java/zk_proof_systems/zkSNARK/objects/VerificationKey.java index 559e172..12aa12a 100755 --- a/src/main/java/zk_proof_systems/zkSNARK/objects/VerificationKey.java +++ b/src/main/java/zk_proof_systems/zkSNARK/objects/VerificationKey.java @@ -21,6 +21,13 @@ public class VerificationKey, G2T extends AbstractG2 private final G2T deltaG2; private final List 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,