update tests

This commit is contained in:
seshanthS
2025-01-15 00:45:02 +05:30
parent 25db59fb19
commit 83460e5dca
2 changed files with 55 additions and 2 deletions

View File

@@ -8,7 +8,7 @@
"test-dsc": "yarn ts-mocha --max-old-space-size=8192 'tests/dsc.test.ts' --exit",
"test-prove": "yarn ts-mocha --max-old-space-size=40960 'tests/prove.test.ts' --exit",
"test-rsa": "yarn ts-mocha --max-old-space-size=8192 'tests/utils/rsaPkcs1v1_5.test.ts' --exit",
"test-rsa-pss": "yarn ts-mocha --max-old-space-size=8192 'tests/utils/rsapss.test.ts' --exit",
"test:rsa-pss": "yarn ts-mocha --max-old-space-size=8192 'tests/utils/rsapss.test.ts' --exit",
"install-circuits": "cd ../common && yarn && cd ../circuits && yarn",
"format": "prettier --write .",
"lint": "prettier --check ."

View File

@@ -3,6 +3,7 @@ import { describe, it } from 'mocha';
import path from 'path';
import { SignatureAlgorithm } from '../../../common/src/utils/types';
import { generateMockRsaPssInputs } from './generateMockInputsRsaPss';
import { expect } from 'chai';
describe('VerifyRsapss Circuit Test', function () {
this.timeout(0);
@@ -22,7 +23,7 @@ describe('VerifyRsapss Circuit Test', function () {
];
rsaAlgorithms.forEach((algorithm) => {
it(`should verify RSA signature using the circuit for ${algorithm}`, async function () {
it(`should verify RSA-PSS signature using the circuit for ${algorithm}`, async function () {
this.timeout(0);
// Generate inputs using the utility function
const { signature, modulus, message, saltLength } = generateMockRsaPssInputs(algorithm);
@@ -50,5 +51,57 @@ describe('VerifyRsapss Circuit Test', function () {
// Check constraints
await circuit.checkConstraints(witness);
});
it("Should fail to verify RSA-PSS signature with invalid signature", async function () {
const { signature, modulus, message, saltLength } = generateMockRsaPssInputs(algorithm);
const invalidSignature = signature.map((byte: string) => String((parseInt(byte) + 1) % 256));
const circuit = await wasmTester(
path.join(
__dirname,
`../../circuits/tests/utils/rsapss/test_${algorithm}_${saltLength}.circom`
),
{
include: ['node_modules', './node_modules/@zk-kit/binary-merkle-root.circom/src'],
}
);
try {
await circuit.calculateWitness({
signature: invalidSignature,
modulus,
message,
});
} catch (error) {
expect(error.message).to.include('Assert Failed');
}
})
it("Should fail to verify RSA-PSS signature with invalid message", async function () {
const { signature, modulus, message, saltLength } = generateMockRsaPssInputs(algorithm);
const invalidMessage = message.map((byte: number) => String((byte + 1) % 256));
const circuit = await wasmTester(
path.join(
__dirname,
`../../circuits/tests/utils/rsapss/test_${algorithm}_${saltLength}.circom`
),
{
include: ['node_modules', './node_modules/@zk-kit/binary-merkle-root.circom/src'],
}
);
try {
await circuit.calculateWitness({
signature,
modulus,
message: invalidMessage,
});
} catch (error) {
expect(error.message).to.include('Assert Failed');
}
})
});
});