|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { wasm as wasmTester } from 'circom_tester'; |
| 3 | +import * as path from 'path'; |
| 4 | +import { generateCircuitInputsOfac, NON_OFAC_DUMMY_INPUT, OFAC_DUMMY_INPUT} from "../../../../../common/src/utils/selfrica/generateInputs"; |
| 5 | +import { serializeSmileData } from "../../../../../common/src/utils/selfrica/types"; |
| 6 | +import { SMT } from '@openpassport/zk-kit-smt'; |
| 7 | +import { poseidon2 } from 'poseidon-lite'; |
| 8 | +import nameAndDobjson from '../../../consts/ofac/nameAndDobSelfricaSMT.json'; |
| 9 | +import nameAndYobjson from '../../../consts/ofac/nameAndYobSelfricaSMT.json'; |
| 10 | + |
| 11 | +describe('OFAC - Name and DOB match', async function() { |
| 12 | + this.timeout(10000); |
| 13 | + let circuit; |
| 14 | + let namedob_smt = new SMT(poseidon2, true); |
| 15 | + let proofLevel = 2; |
| 16 | + |
| 17 | + before(async () => { |
| 18 | + circuit = await wasmTester( |
| 19 | + path.join(__dirname, "ofac_name_dob_selfrica.test.circom"), |
| 20 | + { |
| 21 | + include: [ |
| 22 | + 'node_modules', |
| 23 | + './node_modules/@zk-kit/binary-merkle-root.circom/src', |
| 24 | + './node_modules/circomlib/circuits', |
| 25 | + ], |
| 26 | + } |
| 27 | + ); |
| 28 | + |
| 29 | + namedob_smt.import(nameAndDobjson); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should compile and load the circuit', async () => { |
| 33 | + expect(circuit).to.not.be.undefined; |
| 34 | + }); |
| 35 | + |
| 36 | + it('should return 0 if the person is in the ofac list', async () => { |
| 37 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 38 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, namedob_smt, proofLevel); |
| 39 | + const inputs = { |
| 40 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 41 | + ...ofacInputs, |
| 42 | + }; |
| 43 | + |
| 44 | + const witness = await circuit.calculateWitness(inputs); |
| 45 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 46 | + expect(ofacCheckResult).to.equal('0'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return 1 if the person is not in the ofac list', async () => { |
| 50 | + const dummy_smile_input = serializeSmileData(NON_OFAC_DUMMY_INPUT); |
| 51 | + const ofacInputs = generateCircuitInputsOfac(NON_OFAC_DUMMY_INPUT, namedob_smt, proofLevel); |
| 52 | + const inputs = { |
| 53 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 54 | + ...ofacInputs, |
| 55 | + }; |
| 56 | + |
| 57 | + const witness = await circuit.calculateWitness(inputs); |
| 58 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 59 | + expect(ofacCheckResult).to.equal('1'); |
| 60 | + }); |
| 61 | + |
| 62 | + it("should return 0 if the internal computed merkle root is wrong (wrong leaf key)", async () => { |
| 63 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 64 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, namedob_smt, proofLevel); |
| 65 | + const inputs = { |
| 66 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 67 | + smt_leaf_key: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(), |
| 68 | + ...ofacInputs, |
| 69 | + }; |
| 70 | + |
| 71 | + const witness = await circuit.calculateWitness(inputs); |
| 72 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 73 | + expect(ofacCheckResult).to.equal('0'); |
| 74 | + }); |
| 75 | + |
| 76 | + it("should return 0 if the internal computed merkle root is wrong (wrong siblings)", async () => { |
| 77 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 78 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, namedob_smt, proofLevel); |
| 79 | + ofacInputs.smt_siblings[0] = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(); |
| 80 | + const inputs = { |
| 81 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 82 | + ...ofacInputs, |
| 83 | + }; |
| 84 | + |
| 85 | + const witness = await circuit.calculateWitness(inputs); |
| 86 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 87 | + expect(ofacCheckResult).to.equal('0'); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should return 0 if the merkle root is wrong", async () => { |
| 91 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 92 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, namedob_smt, proofLevel); |
| 93 | + const inputs = { |
| 94 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 95 | + smt_root: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(), |
| 96 | + ...ofacInputs, |
| 97 | + }; |
| 98 | + |
| 99 | + const witness = await circuit.calculateWitness(inputs); |
| 100 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 101 | + expect(ofacCheckResult).to.equal('0'); |
| 102 | + }); |
| 103 | +}); |
| 104 | + |
| 105 | +describe("OFAC - Name and YOB match", async function() { |
| 106 | + this.timeout(10000); |
| 107 | + let circuit; |
| 108 | + let nameyob_smt = new SMT(poseidon2, true); |
| 109 | + let proofLevel = 1; |
| 110 | + |
| 111 | + before(async () => { |
| 112 | + circuit = await wasmTester( |
| 113 | + path.join(__dirname, "ofac_name_yob_selfrica.test.circom"), |
| 114 | + { |
| 115 | + include: [ |
| 116 | + 'node_modules', |
| 117 | + './node_modules/@zk-kit/binary-merkle-root.circom/src', |
| 118 | + './node_modules/circomlib/circuits', |
| 119 | + ], |
| 120 | + } |
| 121 | + ); |
| 122 | + |
| 123 | + nameyob_smt.import(nameAndYobjson); |
| 124 | + }); |
| 125 | + |
| 126 | + it('should compile and load the circuit', async () => { |
| 127 | + expect(circuit).to.not.be.undefined; |
| 128 | + }); |
| 129 | + |
| 130 | + it('should return 0 if the person is in the ofac list', async () => { |
| 131 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 132 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, nameyob_smt, proofLevel); |
| 133 | + const inputs = { |
| 134 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 135 | + ...ofacInputs, |
| 136 | + }; |
| 137 | + |
| 138 | + const witness = await circuit.calculateWitness(inputs); |
| 139 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 140 | + expect(ofacCheckResult).to.equal('0'); |
| 141 | + }); |
| 142 | + |
| 143 | + it('should return 1 if the person is not in the ofac list', async () => { |
| 144 | + const dummy_smile_input = serializeSmileData(NON_OFAC_DUMMY_INPUT); |
| 145 | + const ofacInputs = generateCircuitInputsOfac(NON_OFAC_DUMMY_INPUT, nameyob_smt, proofLevel); |
| 146 | + const inputs = { |
| 147 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 148 | + ...ofacInputs, |
| 149 | + }; |
| 150 | + |
| 151 | + const witness = await circuit.calculateWitness(inputs); |
| 152 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 153 | + expect(ofacCheckResult).to.equal('1'); |
| 154 | + }); |
| 155 | + |
| 156 | + it("should return 0 if the internal computed merkle root is wrong (wrong leaf key)", async () => { |
| 157 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 158 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, nameyob_smt, proofLevel); |
| 159 | + const inputs = { |
| 160 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 161 | + smt_leaf_key: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(), |
| 162 | + ...ofacInputs, |
| 163 | + }; |
| 164 | + |
| 165 | + const witness = await circuit.calculateWitness(inputs); |
| 166 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 167 | + expect(ofacCheckResult).to.equal('0'); |
| 168 | + }); |
| 169 | + |
| 170 | + it("should return 0 if the internal computed merkle root is wrong (wrong siblings)", async () => { |
| 171 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 172 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, nameyob_smt, proofLevel); |
| 173 | + ofacInputs.smt_siblings[0] = BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(); |
| 174 | + const inputs = { |
| 175 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 176 | + ...ofacInputs, |
| 177 | + }; |
| 178 | + |
| 179 | + const witness = await circuit.calculateWitness(inputs); |
| 180 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 181 | + expect(ofacCheckResult).to.equal('0'); |
| 182 | + }); |
| 183 | + |
| 184 | + it("should return 0 if the merkle root is wrong", async () => { |
| 185 | + const dummy_smile_input = serializeSmileData(OFAC_DUMMY_INPUT); |
| 186 | + const ofacInputs = generateCircuitInputsOfac(OFAC_DUMMY_INPUT, nameyob_smt, proofLevel); |
| 187 | + const inputs = { |
| 188 | + smile_data: dummy_smile_input.split('').map((x) => x.charCodeAt(0)), |
| 189 | + smt_root: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(), |
| 190 | + ...ofacInputs, |
| 191 | + }; |
| 192 | + |
| 193 | + const witness = await circuit.calculateWitness(inputs); |
| 194 | + const ofacCheckResult = (await circuit.getOutput(witness, ['ofacCheckResult'])).ofacCheckResult; |
| 195 | + expect(ofacCheckResult).to.equal('0'); |
| 196 | + }); |
| 197 | +}); |
0 commit comments