Skip to content

MCarlomagno/zkemail-prover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Account recovery prover

A prover server using snarkjs to generate proofs for emails.

Emails supported:

  • Guardian request.
  • Sign hash.
  • Recovery request.

Prerequisites

In order to generate proofs, you need circom and snarkjs pre-installad to compile the circuit and generate the following artifacts

  • src/artifacts/email_auth.wasm
  • src/artifacts/email_auth.r1cs
  • src/artifacts/email_auth.zkey

Compile the circuit

You can generate the r1cs and wasm files using the following command from root:

circom --r1cs --wasm --c --sym --inspect src/circuits/email_auth.circom 

Then move them to src/artifacts and rename them to email_auth.wasm and email_auth.r1cs.

Generating the zkey file

To generate the zkey file you need a trusted setup using powers of tau files. You can find more information in the snarkjs documentation. Or just download a prepared one here.

⚠️ Warning: The ptau setup should not be used in production.

Then you can generate the zkey file using the following command:

snarkjs zkey new src/artifacts/email_auth.wasm powersOfTau28_hez_final.ptau src/artifacts/email_auth.zkey

Running the Server

To start the development server:

yarn && yarn start

API Endpoint

POST /prove

This endpoint accepts an email file (.eml) as form-data and returns a proof, public signals and calldata.

  • Request Type: multipart/form-data
  • Form Field: email (this field should contain the .eml file)

Example email in fixtures/guardian_request.eml

Example using cURL:

curl -X POST -F "email=@fixtures/guardian_request.eml" -F "accountCode=01eb9b204cc24c3baee11accc37d253a9c53e92b1a2cc07763475c135d575b76" http://localhost:3000/prove

NOTE: this endpoint generates the witness and the proof, expect it to take a few minutes.

Successful Response (200 OK):

{
  "message": "Proof generated",
  "proof": { "pi_a": "...", ... },
  "publicSignals": { ... },
  "proofId": "...",
  "calldata": "..."
}

Verifying the proof

You can verify the proof on chain using the verifyProof function from the contract src/contracts/Verifier.sol.

Sepolia contract:

You can take the calldata response paraenter and pass it to the verifyProof function in the contract.

https://sepolia.etherscan.io/address/0xB1a54F055C5b171bbE5C6b90efe53BF2f1593a03

NOTE: You might need to parse the calldata removing escape characters, see example valid verifyProof input.

Example Valid verifyProof input

_pA: [0x2dfbee1c8d401f6f86452fb3beecc3156a02bde81a7ed36e99e968bf27cfd6cc,0x0489612bb79d130565138d15c017b6495257cfe39573662483b9bb805ef1e016]
_pB: [["0x293c64f89bafea90809d384cf53707199392c3599c2dce1ecfe893004d74c52a","0x131034117cd142727ccf890c5bc0d7b01dea5e48e492c742dafce98dfa5a28d8"],["0x26b4114021430a3306d87d93386f1b05a0b0457d9e8a21cfa8c987c75dc55996","0x1d5178badbd38240488384b6e9b654e64ec473f88766f4e1f0c44f57127d9205"]]
_pC: [0x1ae7234df96e926a94f1cfd3fc5cfa35f9b57eae805b02096b28290655eea4f1,0x2b42f1f7922fe3a7513042f546e022d7dcff9e5b48c01a6c6d433d672da104d3]
_pubSignals: [0x00000000000000000000000000000000000000000000006d6f632e6c69616d67,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0ea9c777dc7110e5a9e89b13f0cfc540e3845ba120b2b6dc24024d61488d4788,0x213720fcb3206a43d9329b51d344ce40e0c7e18edfd6207efd47c35bcb7ee085,0x00000000000000000000000000000000000000000000000000000000671baaec,0x0030783020726f662074736575716572206e6169647261756720747065636341,0x0062624145663044444236324536354332343338336630363531393434383834,0x0000000000000000000000000000000000000000000000004346326432453836,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x0000000000000000000000000000000000000000000000000000000000000000,0x22123ab5ff37964cce250670f894c3432abcce6e19a9bb0b86c311b59d6a36bb,0x0000000000000000000000000000000000000000000000000000000000000001]

About

A Node.js server to generate proofs for emails using the ZKEmail EmailAuth circom circuits

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors