Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

[New Circuit] KV Membership circuit #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Da-Colon
Copy link

@Da-Colon Da-Colon commented Aug 29, 2023

Summary

This pull request introduces a new zk-SNARK circuit called KVMembership that serves multiple purposes such as nullifier check, Merkle proof verification, and statement value validation. The circuit is implemented in Circom and leverages multiple components from circomlib as well as custom components like EfficientECDSA and Poseidon. Unit tests have been added to ensure the prove and verify functions of the circuit work as expected.

Features

  • Nullifier Check: Ensures that hashed private inputs match the given public inputs.
  • Merkle Proof Verification: Validates Merkle proofs against a given root and verifies the integrity of source values and addresses.
  • Statement Value Validation: Checks the validity of claim values in relation to source values.

Dependencies

  • Circom 2.1.2
  • Node.js (use NVM for version management)

Installation and Testing

Pre-requisites

  • Make sure you have the base circom installed as its missing the README instructions. circom

Installation

  1. Switch to the appropriate Node.js version by running the following command:

    nvm use
    
  2. Follow the README instructions for setting up the environment and dependencies.

Testing

Run the test suite with the following command:

yarn test

const pubKey = ec.keyFromPrivate(privKey.toString("hex")).getPublic();

const hashPubKey = poseidon.hash([pubKey.x.toString("hex"), pubKey.y.toString("hex")]);
const hashSecret = poseidon.hash([secret, BigInt(0)]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could maybe leave a comment here or in the circuit about why padding is necessary

Comment on lines 9 to 12
const SECP256K1_N = new BN(
"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
16
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? just curiousity, i see it used down below, assuming something related to the curve math

Comment on lines 96 to 101
let serialized = new Uint8Array(
32 + 1 + this.msgHash.byteLength + circuitPubInput.byteLength
);

serialized.set(bigIntToBytes(this.r, 32), 0);
serialized.set(bigIntToBytes(this.rV, 1), 32);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could potentially make vars like:

const rLength = 32;
const rVLength = 1;

let serialized = new Uint8Array(
      rLength + rVLength + this.msgHash.byteLength + circuitPubInput.byteLength
    );

    serialized.set(bigIntToBytes(this.r, rLength), 0);
    serialized.set(bigIntToBytes(this.rV, rVLength), rLength);
...

Just to make it clear what each padding is for (but this is extremely minor)

name: string;
version: string;
chainId: number;
// verifyingContract: PrefixedHex;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this get added later?

Comment on lines 28 to 30
"snarkjs": "^0.5.0",
"ethers": "5",
"snarkjs": "^0.5.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Da-Colon -- snarkjs is included twice here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants