diff --git a/src/zkProgram.ts b/src/zkProgram.ts index befaf1c..3b37e74 100644 --- a/src/zkProgram.ts +++ b/src/zkProgram.ts @@ -1,28 +1,63 @@ +//! Note: Compiling and generating proofs for the existing `emailVerify` circuits is not possible +//! because the total number of rows far exceeds the 2^16 constraint limit of o1js circuits. + import { Field, ZkProgram, Bytes } from 'o1js'; import { Bigint2048 } from 'o1js-rsa'; -import { generateInputs } from './generate-inputs.js'; import { emailVerify } from './email-verify.js'; -import fs from 'fs'; - -const filePath = './eml/email.eml'; -const rawEmail = fs.readFileSync(filePath, 'utf8'); -const inputs = await generateInputs(rawEmail); +class Bytes32 extends Bytes(32) {} class HeadersBytes extends Bytes(1024) {} -class BodyBytes extends Bytes(1536) {} -class Bytes32 extends Bytes(32) {} +class BodyBytes1536 extends Bytes(1536) {} +class BodyBytes1024 extends Bytes(1024) {} let verifyEmailZkProgram = ZkProgram({ name: 'verify-email', methods: { - verifyEmail: { + verifyEmailNoBodyCheck: { privateInputs: [ HeadersBytes.provable, Field, Bigint2048, Bigint2048, - BodyBytes.provable, + BodyBytes1536.provable, + Bytes32.provable, + Field, + Field, + ], + + async method( + paddedHeader: Bytes, + headerHashIndex: Field, + signature: Bigint2048, + publicKey: Bigint2048, + paddedBodyRemainingBytes: Bytes, + precomputedHash: Bytes, + bodyHashIndex: Field, + headerBodyHashIndex: Field + ) { + emailVerify( + paddedHeader, + headerHashIndex, + signature, + publicKey, + 1024, + false, + paddedBodyRemainingBytes, + precomputedHash, + bodyHashIndex, + headerBodyHashIndex + ); + }, + }, + + verifyEmailBodyCheck1024: { + privateInputs: [ + HeadersBytes.provable, + Field, + Bigint2048, + Bigint2048, + BodyBytes1024.provable, Bytes32.provable, Field, Field, @@ -52,31 +87,63 @@ let verifyEmailZkProgram = ZkProgram({ ); }, }, - }, -}); -let { verifyEmail } = await verifyEmailZkProgram.analyzeMethods(); + verifyEmailBodyCheck1536: { + privateInputs: [ + HeadersBytes.provable, + Field, + Bigint2048, + Bigint2048, + BodyBytes1536.provable, + Bytes32.provable, + Field, + Field, + ], -console.log(verifyEmail.summary()); + async method( + paddedHeader: Bytes, + headerHashIndex: Field, + signature: Bigint2048, + publicKey: Bigint2048, + paddedBodyRemainingBytes: Bytes, + precomputedHash: Bytes, + bodyHashIndex: Field, + headerBodyHashIndex: Field + ) { + emailVerify( + paddedHeader, + headerHashIndex, + signature, + publicKey, + 1024, + true, + paddedBodyRemainingBytes, + precomputedHash, + bodyHashIndex, + headerBodyHashIndex + ); + }, + }, + }, +}); -console.time('compile'); -await verifyEmailZkProgram.compile(); -console.timeEnd('compile'); +const { + verifyEmailNoBodyCheck, + verifyEmailBodyCheck1536, + verifyEmailBodyCheck1024, +} = await verifyEmailZkProgram.analyzeMethods(); -console.time('prove'); +console.log( + 'verifyEmailNoBodyCheck summary: ', + verifyEmailNoBodyCheck.summary() +); -let proof = await verifyEmailZkProgram.verifyEmail( - inputs.paddedHeader, - inputs.headerHashIndex, - inputs.signature, - inputs.publicKey, - inputs.paddedBodyRemainingBytes, - inputs.precomputedHash, - inputs.bodyHashIndex, - inputs.headerBodyHashIndex +console.log( + '\nverifyEmailBodyCheck1024 summary: ', + verifyEmailBodyCheck1024.summary() ); -console.timeEnd('prove'); -console.time('verify'); -await verifyEmailZkProgram.verify(proof); -console.timeEnd('verify'); +console.log( + '\nverifyEmailBodyCheck1536 summary: ', + verifyEmailBodyCheck1536.summary() +);