Skip to content

Commit

Permalink
chore(noir_js): remove unnecessary input validation in JS (noir-lang#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored and Sakapoi committed Oct 19, 2023
1 parent 5b9fb20 commit e1150e8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 64 deletions.
55 changes: 0 additions & 55 deletions tooling/noir_js/src/input_validation.ts

This file was deleted.

7 changes: 1 addition & 6 deletions tooling/noir_js/src/witness_generation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { abiEncode } from '@noir-lang/noirc_abi';
import { validateInputs } from './input_validation.js';
import { base64Decode } from './base64_decode.js';
import { executeCircuit } from '@noir-lang/acvm_js';
import { witnessMapToUint8Array } from './serialize.js';

// Generates the witnesses needed to feed into the chosen proving system
export async function generateWitness(compiledProgram, inputs): Promise<Uint8Array> {
// Validate inputs
const { isValid, error } = validateInputs(inputs, compiledProgram.abi);
if (!isValid) {
throw new Error(error?.toString());
}
// Throws on ABI encoding error
const witnessMap = abiEncode(compiledProgram.abi, inputs, null);

// Execute the circuit to generate the rest of the witnesses and serialize
Expand Down
6 changes: 5 additions & 1 deletion tooling/noir_js/test/node/cjs.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ describe('input validation', () => {
chai.expect.fail('Expected generatedWitness to throw, due to x not being convertible to a uint64');
} catch (error) {
const knownError = error;
chai.expect(knownError.message).to.equal('Input for x is the wrong type, expected uint64, got "foo"');
chai
.expect(knownError.message)
.to.equal(
'Expected witness values to be integers, provided value causes `invalid digit found in string` error',
);
}
});
});
6 changes: 4 additions & 2 deletions tooling/noir_js/test/node/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ it('generates witnesses successfully', async () => {
x: '2',
y: '3',
};
const _solvedWitness = await generateWitness(assert_lt_json, inputs);
expect(() => generateWitness(assert_lt_json, inputs)).to.not.throw;
});

it('string input and number input are the same', async () => {
Expand Down Expand Up @@ -66,7 +66,9 @@ describe('input validation', () => {
expect.fail('Expected generatedWitness to throw, due to x not being convertible to a uint64');
} catch (error) {
const knownError = error as Error;
expect(knownError.message).to.equal('Input for x is the wrong type, expected uint64, got "foo"');
expect(knownError.message).to.equal(
'Expected witness values to be integers, provided value causes `invalid digit found in string` error',
);
}
});
});

0 comments on commit e1150e8

Please sign in to comment.