diff --git a/circuits/circuits/utils/passport/disclose/proveCountryIsNotInList.circom b/circuits/circuits/utils/passport/disclose/proveCountryIsNotInList.circom index 0d1a3b056..184b79030 100644 --- a/circuits/circuits/utils/passport/disclose/proveCountryIsNotInList.circom +++ b/circuits/circuits/utils/passport/disclose/proveCountryIsNotInList.circom @@ -14,11 +14,10 @@ template ProveCountryIsNotInList(MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH) { signal input forbidden_countries_list[MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH * 3]; signal equality_results[MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH][4]; - for (var i = 0; i < MAX_FORBIDDEN_COUNTRIES_LIST_LENGTH; i++) { - equality_results[i][0] <== IsEqual()([dg1[7], forbidden_countries_list[i ]]); - equality_results[i][1] <== IsEqual()([dg1[8], forbidden_countries_list[i + 1]]); - equality_results[i][2] <== IsEqual()([dg1[9], forbidden_countries_list[i + 2]]); + equality_results[i][0] <== IsEqual()([dg1[7], forbidden_countries_list[i * 3]]); + equality_results[i][1] <== IsEqual()([dg1[8], forbidden_countries_list[i * 3 + 1]]); + equality_results[i][2] <== IsEqual()([dg1[9], forbidden_countries_list[i * 3 + 2]]); equality_results[i][3] <== equality_results[i][0] * equality_results[i][1]; 0 === equality_results[i][3] * equality_results[i][2]; } diff --git a/circuits/package.json b/circuits/package.json index 919f72fe1..f30d8ad8e 100644 --- a/circuits/package.json +++ b/circuits/package.json @@ -15,6 +15,7 @@ "test-custom-hasher": "yarn ts-mocha --max-old-space-size=8192 'tests/other_circuits/custom_hasher.test.ts' --exit", "test-is-valid": "yarn ts-mocha --max-old-space-size=8192 'tests/other_circuits/is_valid.test.ts' --exit", "test-is-older-than": "yarn ts-mocha --max-old-space-size=8192 'tests/other_circuits/is_older_than.test.ts' --exit", + "test-not-in-list": "yarn ts-mocha --max-old-space-size=8192 'tests/other_circuits/prove_country_is_not_in_list.test.ts' --exit", "build-all": "bash scripts/build/build_register_circuits.sh && bash scripts/build/build_dsc_circuits.sh && bash scripts/build/build_disclose_circuits.sh", "build-register": "bash scripts/build/build_register_circuits.sh", "build-dsc": "bash scripts/build/build_dsc_circuits.sh", @@ -69,4 +70,4 @@ "ts-mocha": "^10.0.0", "ts-node": "^10.9.2" } -} +} \ No newline at end of file diff --git a/circuits/tests/other_circuits/prove_country_is_not_in_list.test.ts b/circuits/tests/other_circuits/prove_country_is_not_in_list.test.ts index a265e15da..bdd5ac9e1 100644 --- a/circuits/tests/other_circuits/prove_country_is_not_in_list.test.ts +++ b/circuits/tests/other_circuits/prove_country_is_not_in_list.test.ts @@ -56,8 +56,21 @@ describe('ProveCountryIsNotInList', function () { }); it('should faild - country FRA is in the list', async () => { - const forbiddenCountriesList = ['FRA', 'DZA']; try { + const forbiddenCountriesList = ['DZA', 'FRA']; + const inputs = { + dg1: formatInput(dg1), + forbidden_countries_list: formatInput(formatCountriesList(forbiddenCountriesList)), + }; + const witness = await circuit.calculateWitness(inputs); + } catch (error) { + expect(error.message).to.include('Assert Failed'); + } + }); + + it('should faild - country FRA is in the list', async () => { + try { + const forbiddenCountriesList = ['XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'FRA']; const inputs = { dg1: formatInput(dg1), forbidden_countries_list: formatInput(formatCountriesList(forbiddenCountriesList)), @@ -68,5 +81,14 @@ describe('ProveCountryIsNotInList', function () { expect(error.message).to.include('Assert Failed'); } }); + + it('should succeed - XRA and AXX are in the list, not FRA', async () => { + const forbiddenCountriesList = ['XFR', 'AXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XXX', 'XFR', 'AXX', 'XXX']; + const inputs = { + dg1: formatInput(dg1), + forbidden_countries_list: formatInput(formatCountriesList(forbiddenCountriesList)), + }; + const witness = await circuit.calculateWitness(inputs); + }); }); });