Skip to content

Commit

Permalink
refactor & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RajeshRk18 committed Jan 9, 2024
1 parent aa30849 commit 78a2daa
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
15 changes: 1 addition & 14 deletions circuits/circom/test/sha256Circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand All @@ -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
Expand Up @@ -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);
Expand All @@ -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
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 78a2daa

Please sign in to comment.