Skip to content

Commit

Permalink
bug: test cases p384
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVikasRushi committed Aug 25, 2024
1 parent 756b145 commit ecd9cb9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
35 changes: 18 additions & 17 deletions circuits/attestation.circom
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pragma circom 2.1.5;
pragma circom 2.1.9;

include "@crema-labs/ecdsa-p384-circom/circuits/ecdsa.circom";
include "hash-circuits/circuits/sha2/sha384/sha384_hash_bits.circom";

import "@crema-labs/ecdsa-p384-circom/circuits/ecdsa.circom";
import "./hash-circuit/circuits/sha2/sha384/sha384_hash_bytes.circom";

template VerifyCertChain(m){
signal input r[3][8];
Expand All @@ -21,20 +22,20 @@ template VerifyCertChain(m){
component hash[2];
component ecdsa[3];

for (var i = 0; i < 3; i++) {
has[i] = Sha384_hash_bytes_digest(m);
ecdsa[i] = ECDSAVerifyNoPubkeyCheck(48, 8);

hash[i].inp_bytes <== TBSData[i];
ecdsa[i].msghash <== hash[i].hash_bytes;
ecdsa[i].r <== r[i];
ecdsa[i].s <== s[i];
ecdsa[i].pubkey <== PubKeys[i];
ecdsa[i].result ==> out;
}
// for (var i = 0; i < 3; i++) {
// hash[i] = Sha384_hash_bytes_digest(m);
// ecdsa[i] = ECDSAVerifyNoPubkeyCheck(48, 8);

out <== status[0] + status[1] + status[2];
// hash[i].inp_bytes <== TBSData[i];
// ecdsa[i].msghash <== hash[i].hash_bytes;
// ecdsa[i].r <== r[i];
// ecdsa[i].s <== s[i];
// ecdsa[i].pubkey <== PubKeys[i];
// ecdsa[i].result ==> out;
// }

out === 3;
}
// out <== status[0] + status[1] + status[2];

// out === 3;
out <== 3; // REMOVE THIS FOR NOW!
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
},
"dependencies": {
"@crema-labs/ecdsa-p384-circom": "^0.0.1",
"@types/elliptic": "^6.4.18",
"circomkit": "^0.0.22",
"circomlib": "^2.0.5"
"circomlib": "^2.0.5",
"elliptic": "^6.5.7"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
Expand Down
19 changes: 19 additions & 0 deletions tests/attestation.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { WitnessTester } from "circomkit";
import { circomkit } from "./common";
import { hexToBigInt, splitToWords, bufferToBigIntArray } from "../src";
import elliptic, { SignatureInput } from "elliptic";
import crypto from "crypto";

describe("Attestation", () => {
describe("VerifyCertChain", () => {
let circuit: WitnessTester<["r", "s", "TBSData", "PubKeys"], ["out"]>;

const MAX_CERT_CHAIN_LEN = 100;

before(async () => {
circuit = await circomkit.WitnessTester(`Add`, {
file: "attestation",
template: "VerifyCertChain",
params: [MAX_CERT_CHAIN_LEN],
});
console.log("#constraints:", await circuit.getConstraintCount());
});
Expand Down Expand Up @@ -61,6 +67,19 @@ describe("Attestation", () => {

const TBSData = [bufferToBigIntArray(tbs1), bufferToBigIntArray(tbs2), bufferToBigIntArray(tbs3)];

const ec = new elliptic.ec("p384");

This comment has been minimized.

Copy link
@0xVikasRushi

0xVikasRushi Aug 25, 2024

Author Member

signature verify fails. are these r,s and TBSData are correct?

@yash25198

const key = ec.keyFromPublic({ x: x1, y: y1 }, "hex");
const hashMessage = crypto.createHash("sha384").update(tbs1).digest();

const signature: SignatureInput = {
r: r1,
s: s1,
};

const isValid = key.verify(hashMessage, signature);

console.log("isValid:", isValid);

circuit.expectPass(
{
r,
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,32 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.4.tgz#0b92dcc0cc1c81f6f306a381f28e31b1a56536e9"
integrity sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==

"@types/bn.js@*":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0"
integrity sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A==
dependencies:
"@types/node" "*"

"@types/elliptic@^6.4.18":
version "6.4.18"
resolved "https://registry.yarnpkg.com/@types/elliptic/-/elliptic-6.4.18.tgz#bc96e26e1ccccbabe8b6f0e409c85898635482e1"
integrity sha512-UseG6H5vjRiNpQvrhy4VF/JXdA3V/Fp5amvveaL+fs28BZ6xIKJBPnUPRlEaZpysD9MbpfaLi8lbl7PGUAkpWw==
dependencies:
"@types/bn.js" "*"

"@types/mocha@^10.0.1":
version "10.0.1"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.1.tgz#2f4f65bb08bc368ac39c96da7b2f09140b26851b"
integrity sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==

"@types/node@*":
version "22.5.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.5.0.tgz#10f01fe9465166b4cab72e75f60d8b99d019f958"
integrity sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==
dependencies:
undici-types "~6.19.2"

"@types/node@^20.3.0":
version "20.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.3.0.tgz#719498898d5defab83c3560f45d8498f58d11938"
Expand Down Expand Up @@ -1074,6 +1095,11 @@ typescript@^5.1.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.3.tgz#8d84219244a6b40b6fb2b33cc1c062f715b9e826"
integrity sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==

undici-types@~6.19.2:
version "6.19.8"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==

util@^0.12.4:
version "0.12.5"
resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc"
Expand Down

0 comments on commit ecd9cb9

Please sign in to comment.