Implementation of batch ECDSA signatures in circom for the P-256 curve for the Nova proof system using Nova-Scotia.
These circuits are not audited, and this is not intended to be used as a library for production-grade applications.
This repository provides proof-of-concept implementations of ECDSA operations on the P-256 curve in circom using Nova-Scotia. These implementations are for demonstration purposes only.
circuits
: Contains the signature aggregation circuit which is in accordance with Nova-Scotia's syntax. TheECDSAVerifyNoPubkeyCheck(n,k)
function is imported from circom-ecdsa-p256 submodule.scripts
: ContainsgenerateSampleSignature.ts
which generatesp256
signatures, converts the bigint values to6
43-bit
register arrays and dumps it intosrc/data/batch.json
.src
: Includes themain.rs
file to generate & verify proofs using Nova proof system
Due to P256 curve having no cycles, and the nature of Ethereum precompiles, we use BigInt arithmetic from the original circom-ecdsa implementation instead of the efficient circom-ecdsa to take advantage of Nova's BN254/grumpkin
cycle.
Make sure you have the following dependencies pre-installed
- Run
git submodule update --init --recursive
- Run
yarn
at the top level to install npm dependencies - Run
yarn
inside ofcircuits/circom-ecdsa-p256
to install npm dependencies for thecircom-ecdsa-p256
library. - Run
yarn
inside ofcircuits/circom-ecdsa-p256/circuits/circom-pairing
to install npm dependencies for thecircom-pairing
library.
- Compile the circuits and generate the relevant
r1cs
&wasm
files
circom circuits/batch_ecdsa.circom --r1cs --sym --wasm
- Move the
batch_ecdsa.r1cs
file from the root tosrc/data/
mv batch_ecdsa.r1cs src/data
- Move the
batch_ecdsa.wasm
file frombatch_ecdsa_js
tosrc/data
mv batch_ecdsa_js/batch_ecdsa.wasm src/data/
- Make sure you've generated the signatures using the script. The signatures are populated in
src/data/batch.json
ts-node scripts/generateSampleSignature.ts
- Now to generate & verify a recursive proof, simply do
cargo run
The signature aggregator circuit is implemented in circuits/batch_ecdsa.circom
.
- The circuit takes in a public input
step_in
, auxillary inputsignatures
and outputstep_out
in accordance with Nova-Scotia's syntax.
signal input step_in[m];
signal input signatures[N_SIGS][m];
signal output step_out[m];
- The 256-bits input is chunked and represented as
k
n
-bits values wherek
is6
andn
is43
. TheECDSAVerifyNoPubkeyCheck(n,k)
circuit takes in four inputs -r
,s
,msghash
,pubkey[2]
of which all the inputs are43
-bit arrays. - Since Nova-Scotia (and Nova) does not support folding in 2D arrays, the inputs are represented as 1D arrays of length
5*k
=5*6
=30
. - The
step_in
&signatures
are then trandformed into 2D arrays to input values in theECDSAVerifyNoPubkeyCheck(n,k)
circuit
All benchmarks were run on an
verify 10 | verify 100 | verify 300 | verify | |
---|---|---|---|---|
Constraints | ? | ? | ? | ? |
Loading r1cs | ? | ? | ? | ? |
Public parameter generation | ? | ? | ? | ? |
Proving time | ? | ? | ? | ? |
Proof verification time | ? | ? | ? | ? |
- The circuit uses circom-ecdsa-p256 as submodule.
- The inspiration for this project is taken from nova-browser-ecdsa