Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: public key compression #77

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
refactor & fixes
RajeshRk18 committed Jan 9, 2024
commit 78a2daacb8958d411368984894ca801d90e1e204
15 changes: 1 addition & 14 deletions circuits/circom/test/sha256Circuit.test.ts
Original file line number Diff line number Diff line change
@@ -40,18 +40,6 @@ describe("SHA256 Circuit", () => {
hashedToCurveR,
];

const v1_sha256_preimage_bits = bufToSha256PaddedBitArr(
Buffer.from(
concatUint8Arrays(
sha_preimage_points.map((point) => point.toRawBytes(true)),
),
),
);
const v1_sha256_preimage_bit_length = parseInt(
v1_sha256_preimage_bits.slice(-64),
2,
);

const v1_binary_c = BigInt("0x" + c_v1)
.toString(2)
.split("")
@@ -72,11 +60,10 @@ describe("SHA256 Circuit", () => {
{
pk_compressed: public_key_compressed,
coordinates,
preimage_bit_length: v1_sha256_preimage_bit_length,
},
true,
);
await circuit.checkConstraints(w);
await circuit.assertOut(w, { out: v1_binary_c });
});
});
});
29 changes: 1 addition & 28 deletions circuits/circom/test/v1.test.ts
Original file line number Diff line number Diff line change
@@ -30,37 +30,10 @@ describe("V1 Circuit", () => {
const public_key_bytes = Array.from(testPublicKey);
const message_bytes = Array.from(testMessage);

const hashMPkPoint = new Point(
hexToBigInt(hashMPk.x.toString()),
hexToBigInt(hashMPk.y.toString()),
);

const hash_to_curve_inputs = utils.stringifyBigInts(
generate_inputs_from_array(message_bytes.concat(public_key_bytes)),
);

const sha_preimage_points: Point[] = [
Point.BASE,
Point.fromPrivateKey(testSecretKey),
hashMPkPoint,
nullifier,
rPoint,
hashedToCurveR,
];

const v1_sha256_preimage_bits = bufToSha256PaddedBitArr(
Buffer.from(
concatUint8Arrays(
sha_preimage_points.map((point) => point.toRawBytes(true)),
),
),
);

const v1_sha256_preimage_bit_length = parseInt(
v1_sha256_preimage_bits.slice(-64),
2,
);

test("V1 circuit works", async () => {
const p = path.join(__dirname, "./circuits/v1_test.circom");
const circuit = await wasm_tester(p);
@@ -77,4 +50,4 @@ describe("V1 Circuit", () => {
});
await circuit.checkConstraints(w);
});
});
});
5 changes: 0 additions & 5 deletions circuits/circom/verify_nullifier.circom
Original file line number Diff line number Diff line change
@@ -34,9 +34,6 @@ template plume_v1(n, k, message_length) {
component pk_compressor = compress_ec_point(n, k);
pk_compressor.uncompressed <== pk;

// precomputed value for the sha256 component. TODO: calculate internally in circom to simplify API
signal input sha256_preimage_bit_length;

component check_ec_equations = check_ec_equations(n, k, message_length);

check_ec_equations.c <== c;
@@ -64,7 +61,6 @@ template plume_v1(n, k, message_length) {
var g[2][100];
g[0] = get_genx(n, k);
g[1] = get_geny(n, k);
c_sha256.preimage_bit_length <== sha256_preimage_bit_length;
c_sha256.pk_compressed <== pk_compressor.compressed;

for (var i = 0; i < 2; i++) {
@@ -267,7 +263,6 @@ template a_div_b_pow_c(n, k) {
template sha256_12_coordinates(n, k) {
signal input pk_compressed[33];
signal input coordinates[10][k];
signal input preimage_bit_length;
signal output out[256];

// compress coordinates