Skip to content

Commit

Permalink
fix: register ecdsa tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVikasRushi committed Aug 14, 2024
1 parent 96276ab commit 732f6ad
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
88 changes: 44 additions & 44 deletions circuits/tests/register/register_sha1_ecdsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,58 +45,58 @@ describe('Register - SHA1 WITH ECDSA', function () {
);
});

it('should compile and load the circuit', async function () {
expect(circuit).to.not.be.undefined;
});
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(inputs);
await circuit.checkConstraints(w);
it('should calculate the witness with correct inputs', async function () {
const w = await circuit.calculateWitness(inputs);
await circuit.checkConstraints(w);

const nullifier = (await circuit.getOutput(w, ['nullifier'])).nullifier;
console.log('\x1b[34m%s\x1b[0m', 'nullifier', nullifier);
const commitment_circom = (await circuit.getOutput(w, ['commitment'])).commitment;
console.log('\x1b[34m%s\x1b[0m', 'commitment', commitment_circom);
const blinded_dsc_commitment = (await circuit.getOutput(w, ['blinded_dsc_commitment']))
.blinded_dsc_commitment;
console.log('\x1b[34m%s\x1b[0m', 'blinded_dsc_commitment', blinded_dsc_commitment);
const mrz_bytes = packBytes(inputs.mrz);
const leaf = getLeaf({
signatureAlgorithm: passportData.signatureAlgorithm,
publicKeyQ: passportData.pubKey.publicKeyQ,
}).toString();
const commitment_bytes = poseidon6([
inputs.secret[0],
attestation_id,
leaf,
mrz_bytes[0],
mrz_bytes[1],
mrz_bytes[2],
]);
const commitment_js = commitment_bytes.toString();
expect(commitment_circom).to.be.equal(commitment_js);
});
const nullifier = (await circuit.getOutput(w, ['nullifier'])).nullifier;
console.log('\x1b[34m%s\x1b[0m', 'nullifier', nullifier);
const commitment_circom = (await circuit.getOutput(w, ['commitment'])).commitment;
console.log('\x1b[34m%s\x1b[0m', 'commitment', commitment_circom);
const blinded_dsc_commitment = (await circuit.getOutput(w, ['blinded_dsc_commitment']))
.blinded_dsc_commitment;
console.log('\x1b[34m%s\x1b[0m', 'blinded_dsc_commitment', blinded_dsc_commitment);
const mrz_bytes = packBytes(inputs.mrz);
const leaf = getLeaf({
signatureAlgorithm: passportData.signatureAlgorithm,
publicKeyQ: passportData.pubKey.publicKeyQ,
}).toString();
const commitment_bytes = poseidon6([
inputs.secret[0],
attestation_id,
leaf,
mrz_bytes[0],
mrz_bytes[1],
mrz_bytes[2],
]);
const commitment_js = commitment_bytes.toString();
expect(commitment_circom).to.be.equal(commitment_js);
});

it('should fail to calculate witness with invalid econtent', async function () {
try {
const invalidInputs = {
econtent: inputs.econtent.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
...inputs,
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
} catch (error) {
expect(error.message).to.include('Assert Failed');
}
});
it('should fail to calculate witness with invalid econtent', async function () {
try {
const invalidInputs = {
...inputs,
econtent: inputs.econtent.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');
}
});

it('should fail to calculate witness with invalid mrz', async function () {
try {
const invalidInputs = {
...inputs,
mrz: Array(93)
.fill(0)
.map((byte) => BigInt(byte).toString()),
...inputs,
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
Expand All @@ -111,11 +111,11 @@ describe('Register - SHA1 WITH ECDSA', function () {
);
try {
const invalidInputs = {
signature_s: wrong_signature_s,
...inputs,
signature_s: wrong_signature_s,
};
await circuit.calculateWitness(invalidInputs);
// expect.fail('Expected an error but none was thrown.');
expect.fail('Expected an error but none was thrown.');
} catch (error) {
expect(error.message).to.include('Assert Failed');
}
Expand Down
6 changes: 3 additions & 3 deletions circuits/tests/register/register_sha256_ecdsa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('Register - SHA256 WITH ECDSA', function () {
it('should fail to calculate witness with invalid econtent', async function () {
try {
const invalidInputs = {
econtent: inputs.econtent.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
...inputs,
econtent: inputs.econtent.map((byte: string) => String((parseInt(byte, 10) + 1) % 256)),
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
Expand All @@ -94,10 +94,10 @@ describe('Register - SHA256 WITH ECDSA', function () {
it('should fail to calculate witness with invalid mrz', async function () {
try {
const invalidInputs = {
...inputs,
mrz: Array(93)
.fill(0)
.map((byte) => BigInt(byte).toString()),
...inputs,
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
Expand All @@ -112,8 +112,8 @@ describe('Register - SHA256 WITH ECDSA', function () {
);
try {
const invalidInputs = {
signature_s: wrong_signature_s,
...inputs,
signature_s: wrong_signature_s,
};
await circuit.calculateWitness(invalidInputs);
expect.fail('Expected an error but none was thrown.');
Expand Down

0 comments on commit 732f6ad

Please sign in to comment.