Skip to content

Commit

Permalink
chore: npm pkg in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVikasRushi committed Sep 1, 2024
1 parent 96f8ad1 commit 059036d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This repository provides implementations of Elliptic Curve Digital Signature Alg

> Note: These circuits not audited and not yet recommended for production use.
## Usage

```bash
yarn add @crema-labs/ecdsa-p384-circom
```

```circom
include "@crema-labs/ecdsa-p384-circom/circuits/ecdsa.circom";
```

## Setup

```sh
Expand Down Expand Up @@ -39,17 +49,19 @@ yarn test -g <template-name>
```

## Benchmarks
All tests were performed on a MacBook Pro M1 2020 with 8GB RAM.
| Operation | Constraints | Time (ms) |
| ------------------------------ | ----------- | --------- |
| ECDSA Signature Verification | 4,429,227 | 4,21,394 |
| ECDSA Point Addition (Unequal) | 4,352 | 850 |
| ECDSA Point Addition (Equal) | 6,000 | 573 |
| ECDSA Scalar Multiplication | 3,977,848 | 4,20,964 |

All tests were performed on a MacBook Pro M1 2020 with 8GB RAM.
| Operation | Constraints | Time (ms) |
| ------------------------------ | ----------- | --------- |
| ECDSA Signature Verification | 4,429,227 | 4,21,394 |
| ECDSA Point Addition (Unequal) | 4,352 | 850 |
| ECDSA Point Addition (Equal) | 6,000 | 573 |
| ECDSA Scalar Multiplication | 3,977,848 | 4,20,964 |

# Credits

This project was made possible thanks to the support of [ZK Email](https://github.com/zkemail) and [OpenPassport](https://github.com/zk-passport) for the grant.

# Acknowledgments

This project builds upon the excellent work of the [circom-ecdsa-p256](https://github.com/privacy-scaling-explorations/circom-ecdsa-p256) by PSE and [circom-ecdsa](https://github.com/0xPARC/circom-ecdsa) by 0xPARC. We are grateful for their contributions to implementation of ECDSA in Circom, which formed the foundation for our work.
Expand Down
17 changes: 10 additions & 7 deletions tests/ecdsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { circomkit } from "./common";
import { decode } from "./utils";

describe("ECDSA", () => {
describe('should be able to verify signature', () => {
describe("should be able to verify signature", () => {
let circuit: WitnessTester<["r", "s", "msghash", "pubkey"], ["result"]>;

before(async () => {
circuit = await circomkit.WitnessTester(`ECDSAVerifyNoPubkeyCheck_64_6`, {
circuit = await circomkit.WitnessTester(`ECDSAVerifyNoPubkeyCheck_48_8`, {
file: "ecdsa",
template: "ECDSAVerifyNoPubkeyCheck",
params: [48, 8],
Expand All @@ -19,7 +19,7 @@ describe("ECDSA", () => {
});

it("should be able to verify signatures", () => {
const p384 = new ec('p384');
const p384 = new ec("p384");
const keyPair = p384.genKeyPair();

const msgHash = crypto.createHash("sha384").update("hello world").digest("hex");
Expand All @@ -33,7 +33,10 @@ describe("ECDSA", () => {
const pubkey_x = splitToWords(hexToBigInt(pubkey.subarray(1, 1 + 48).toString("hex")), 48n, 8n);
const pubkey_y = splitToWords(hexToBigInt(pubkey.subarray(49, 49 + 48).toString("hex")), 48n, 8n);

circuit.expectPass({ r, s, msghash: splitToWords(hexToBigInt(msgHash), 48n, 8n), pubkey: [pubkey_x, pubkey_y] }, { result: [1] });
})
})
})
circuit.expectPass(
{ r, s, msghash: splitToWords(hexToBigInt(msgHash), 48n, 8n), pubkey: [pubkey_x, pubkey_y] },
{ result: [1] }
);
});
});
});
33 changes: 17 additions & 16 deletions tests/p384.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import { circomkit } from "./common";
import P384TestCases from "./testcases/p384.json";

describe("ECDSA P384", () => {

const G_X = hexToBigInt(
"aa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"
);
const G_Y = hexToBigInt(
"3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"
);

const G_X_WORDS = splitToWords(G_X, 48n, 8n);
const G_Y_WORDS = splitToWords(G_Y, 48n, 8n);
const G_WORDS = [G_X_WORDS, G_Y_WORDS];

describe("ECDSA Point Addition Unequal", () => {
let circuit: WitnessTester<["a", "b"], ["out"]>;
before(async () => {
circuit = await circomkit.WitnessTester(`P384AddUnequal_64_6`, {
circuit = await circomkit.WitnessTester(`P384AddUnequal_48_8`, {
file: "p384",
template: "P384AddUnequal",
params: [48, 8],
Expand Down Expand Up @@ -48,15 +47,14 @@ describe("ECDSA P384", () => {
it(`for ${currentPoint.k}G + G == ${RESULT.k}G`, async () => {
await circuit.expectPass({ a: G_WORDS, b: currentPoint_WORDS }, { out: RESULT_WORDS });
});

}
});
});

describe("ECDSA Point Addition Equal", () => {
let circuit: WitnessTester<["in"], ["out"]>;
before(async () => {
circuit = await circomkit.WitnessTester(`P384Double_64_6`, {
circuit = await circomkit.WitnessTester(`P384Double_48_8`, {
file: "p384",
template: "P384Double",
params: [48, 8],
Expand All @@ -65,18 +63,18 @@ describe("ECDSA P384", () => {
});

it("should compute properly", async () => {
const G_X_2 = splitToWords(hexToBigInt(P384TestCases[1].x), 48n, 8n);
const G_Y_2 = splitToWords(hexToBigInt(P384TestCases[1].y), 48n, 8n);
const G_2_WORDS = [G_X_2, G_Y_2];
const G_X_2 = splitToWords(hexToBigInt(P384TestCases[1].x), 48n, 8n);
const G_Y_2 = splitToWords(hexToBigInt(P384TestCases[1].y), 48n, 8n);
const G_2_WORDS = [G_X_2, G_Y_2];

await circuit.expectPass({ in: G_WORDS }, { out: G_2_WORDS });
await circuit.expectPass({ in: G_WORDS }, { out: G_2_WORDS });
});
});

describe("ECDSA Scalar Multiplication", () => {
let circuit: WitnessTester<["scalar", "point"], ["out"]>;
before(async () => {
circuit = await circomkit.WitnessTester(`P384ScalarMult_64_6`, {
circuit = await circomkit.WitnessTester(`P384ScalarMult_48_8`, {
file: "p384",
template: "P384ScalarMult",
params: [48, 8],
Expand All @@ -85,18 +83,21 @@ describe("ECDSA P384", () => {
});

describe("should compute properly", async () => {
for(let i = 23; i < 24; i++) {
for (let i = 23; i < 24; i++) {
const currentPoint = P384TestCases[i];
const currentPoint_X = currentPoint.x;
const currentPoint_Y = currentPoint.y;
const currentPoint_X_WORDS = splitToWords(hexToBigInt(currentPoint_X), 48n, 8n);
const currentPoint_Y_WORDS = splitToWords(hexToBigInt(currentPoint_Y), 48n, 8n);
const currentPoint_WORDS = [currentPoint_X_WORDS, currentPoint_Y_WORDS];

it(`for ${currentPoint.k}.G`, async () => {
await circuit.expectPass({ scalar: splitToWords(BigInt(P384TestCases[i].k), 48n, 8n), point: G_WORDS }, { out: currentPoint_WORDS });
})
await circuit.expectPass(
{ scalar: splitToWords(BigInt(P384TestCases[i].k), 48n, 8n), point: G_WORDS },
{ out: currentPoint_WORDS }
);
});
}
});
})
});
});

0 comments on commit 059036d

Please sign in to comment.