Skip to content

Commit

Permalink
clean rsapss tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Jul 14, 2024
1 parent 37e66c4 commit 71fc5ba
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 303 deletions.
152 changes: 0 additions & 152 deletions circuits/test/RSSSSAPSS_2048.test.ts

This file was deleted.

151 changes: 0 additions & 151 deletions circuits/test/RSSSSAPSS_2057.test.ts

This file was deleted.

File renamed without changes.
66 changes: 66 additions & 0 deletions circuits/tests/rsassapss/rsassapss_2048.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe } from 'mocha';
import { assert, expect } from 'chai';
import path from 'path';
const wasm_tester = require('circom_tester').wasm;
import { poseidon1 } from 'poseidon-lite';
import { generateCircuitInputsRegister } from '../../../common/src/utils/generateInputs';
import { mockPassportData_sha256_rsapss_65537 } from '../../../common/src/constants/mockPassportData';

describe('Proof of Passport - Circuits - RSASSAPSS - 2048', function () {
this.timeout(0);
let inputs: any;
let circuit: any;
let circuit_inputs: any;
let attestation_id: string;
const n_dsc = 64;
const k_dsc = 32;


let passportData = mockPassportData_sha256_rsapss_65537;

before(async () => {
circuit = await wasm_tester(
path.join(__dirname, '../../circuits/tests/rsassapss/rsassapss_2048.circom'),
{
include: [
'node_modules',
'node_modules/@zk-email/circuits/helpers/sha.circom',
'./node_modules/circomlib/circuits',
],
}
);

const secret = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString();
const attestation_name = 'E-PASSPORT';
attestation_id = poseidon1([BigInt(Buffer.from(attestation_name).readUIntBE(0, 6))]).toString();
inputs = generateCircuitInputsRegister(secret, secret, attestation_id, passportData, n_dsc, k_dsc);
circuit_inputs = {
signature: inputs.signature,
pubkey: inputs.dsc_modulus,
eContentBytes: inputs.signed_attributes,
};
});

it('should compile and load the circuit', async function () {
expect(circuit).to.not.be.undefined;
});

it('should calculate the witness with correct inputs', async function () {
const w = await circuit.calculateWitness(circuit_inputs);
await circuit.checkConstraints(w);
});

it('should fail to calculate witness with invalid signature', async function () {
try {
const invalidInputs = {
pubkey: inputs.dsc_modulus,
eContentBytes: inputs.signed_attributes,
signature: inputs.signature.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
} catch (error) {
expect(error.message).to.include('Assert Failed');
}
});
});
Loading

0 comments on commit 71fc5ba

Please sign in to comment.