mirror of
https://github.com/selfxyz/self.git
synced 2026-02-19 02:24:25 -05:00
rename smt_leaf_value for smt_leaf_key
This commit is contained in:
@@ -26,7 +26,7 @@ template VC_AND_DISCLOSE( nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {
|
||||
signal input user_identifier;
|
||||
|
||||
// ofac check
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
signal input selector_ofac;
|
||||
@@ -56,7 +56,7 @@ template VC_AND_DISCLOSE( nLevels,FORBIDDEN_COUNTRIES_LIST_LENGTH) {
|
||||
signal output forbidden_countries_list_packed_disclosed[2] <== ProveCountryIsNotInList(FORBIDDEN_COUNTRIES_LIST_LENGTH)(dg1, forbidden_countries_list);
|
||||
|
||||
// OFAC
|
||||
signal ofacCheckResult <== OFAC_NAME()(dg1,smt_leaf_value,smt_root,smt_siblings);
|
||||
signal ofacCheckResult <== OFAC_NAME()(dg1,smt_leaf_key,smt_root,smt_siblings);
|
||||
signal ofacIntermediaryOutput <== ofacCheckResult * selector_ofac;
|
||||
signal output ofac_result <== ofacIntermediaryOutput;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ template OPENPASSPORT_PROVE(DG_HASH_ALGO, ECONTENT_HASH_ALGO, signatureAlgorithm
|
||||
signal input selector_mode[2];
|
||||
|
||||
// ofac check
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
signal input selector_ofac;
|
||||
@@ -104,7 +104,7 @@ template OPENPASSPORT_PROVE(DG_HASH_ALGO, ECONTENT_HASH_ALGO, signatureAlgorithm
|
||||
}
|
||||
|
||||
// OFAC
|
||||
signal ofacCheckResult <== OFAC_NAME()(dg1,smt_leaf_value,smt_root,smt_siblings);
|
||||
signal ofacCheckResult <== OFAC_NAME()(dg1,smt_leaf_key,smt_root,smt_siblings);
|
||||
signal ofacIntermediaryOutput <== ofacCheckResult * selector_ofac;
|
||||
signal output ofac_result <== ofacIntermediaryOutput;
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ include "@zk-kit/binary-merkle-root.circom/src/binary-merkle-root.circom";
|
||||
include "circomlib/circuits/poseidon.circom";
|
||||
|
||||
/// @title SMTVerify
|
||||
/// @notice Verifies inclusion or non-inclusion of a value in a Sparse Merkle Tree
|
||||
/// @notice Verifies inclusion or non-inclusion of a key in a Sparse Merkle Tree
|
||||
/// @param nLength Maximum depth of the tree
|
||||
/// @input virtualValue The value to verify (user's input value)
|
||||
/// @input value The value stored in the tree at the path
|
||||
/// @input virtualKey The key to verify (user's input key)
|
||||
/// @input key The key stored in the tree at the path
|
||||
/// @input root The root of the Sparse Merkle Tree
|
||||
/// @input siblings Array of sibling nodes
|
||||
/// @input mode Verification mode (0 for non-inclusion, 1 for inclusion)
|
||||
/// @output out 1 if verification succeeds, 0 otherwise
|
||||
template SMTVerify(nLength) {
|
||||
signal input virtualValue;
|
||||
signal input value;
|
||||
signal input virtualKey;
|
||||
signal input key;
|
||||
signal input root;
|
||||
signal input siblings[nLength];
|
||||
signal input mode;
|
||||
@@ -25,7 +25,7 @@ template SMTVerify(nLength) {
|
||||
|
||||
// Calculate path
|
||||
signal path[nLength];
|
||||
signal path_in_bits_reversed[nLength] <== Num2Bits(256)(virtualValue);
|
||||
signal path_in_bits_reversed[nLength] <== Num2Bits(256)(virtualKey);
|
||||
var path_in_bits[nLength];
|
||||
|
||||
for (var i = 0; i < nLength; i++) {
|
||||
@@ -39,8 +39,8 @@ template SMTVerify(nLength) {
|
||||
path <== pathShifter.out;
|
||||
|
||||
// Closest_key to leaf
|
||||
signal leaf <== Poseidon(3)([value, 1, 1]); // compute the leaf from the value
|
||||
signal isClosestZero <== IsEqual()([value,0]); // check if the inital value is 0, in that case the leaf will be 0 too, not Hash(0,1,1);
|
||||
signal leaf <== Poseidon(3)([key, 1, 1]); // compute the leaf from the key
|
||||
signal isClosestZero <== IsEqual()([key,0]); // check if the inital key is 0, in that case the leaf will be 0 too, not Hash(0,1,1);
|
||||
signal leafOrZero <== leaf * (1 - isClosestZero);
|
||||
|
||||
// Verification
|
||||
@@ -48,7 +48,7 @@ template SMTVerify(nLength) {
|
||||
signal computedRootIsValid <== IsEqual()([computedRoot,root]);
|
||||
|
||||
// check is leaf equals virtual leaf
|
||||
signal virtualLeaf <== Poseidon(3)([virtualValue, 1,1]);
|
||||
signal virtualLeaf <== Poseidon(3)([virtualKey, 1,1]);
|
||||
signal areLeafAndVirtualLeafEquals <== IsEqual()([virtualLeaf, leaf]);
|
||||
|
||||
signal isInclusionOrNonInclusionValid <== IsEqual()([mode,areLeafAndVirtualLeafEquals]);
|
||||
|
||||
@@ -7,7 +7,7 @@ template OFAC_NAME() {
|
||||
|
||||
signal input dg1[93];
|
||||
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
|
||||
@@ -22,6 +22,6 @@ template OFAC_NAME() {
|
||||
|
||||
signal name_hash <== Poseidon(3)([poseidon_hasher[0].out, poseidon_hasher[1].out, poseidon_hasher[2].out]);
|
||||
|
||||
signal output ofacCheckResult <== SMTVerify(256)(name_hash, smt_leaf_value, smt_root, smt_siblings, 0);
|
||||
signal output ofacCheckResult <== SMTVerify(256)(name_hash, smt_leaf_key, smt_root, smt_siblings, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ template OFAC_NAME_DOB() {
|
||||
|
||||
signal input dg1[93];
|
||||
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
// Name Hash
|
||||
@@ -30,5 +30,5 @@ template OFAC_NAME_DOB() {
|
||||
// NameDob hash
|
||||
signal name_dob_hash <== Poseidon(2)([pos_dob.out, name_hash]);
|
||||
|
||||
signal output ofacCheckResult <== SMTVerify(256)(name_dob_hash, smt_leaf_value, smt_root, smt_siblings, 0);
|
||||
signal output ofacCheckResult <== SMTVerify(256)(name_dob_hash, smt_leaf_key, smt_root, smt_siblings, 0);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ template OFAC_PASSPORT_NUMBER() {
|
||||
|
||||
signal input dg1[93];
|
||||
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
signal output proofLevel <== 3;
|
||||
@@ -15,5 +15,5 @@ template OFAC_PASSPORT_NUMBER() {
|
||||
for (var i = 0; i < 9; i++) {
|
||||
poseidon_hasher.inputs[i] <== dg1[49 + i];
|
||||
}
|
||||
signal output ofacCheckResult <== SMTVerify(256)(poseidon_hasher.out, smt_leaf_value, smt_root, smt_siblings, 0);
|
||||
signal output ofacCheckResult <== SMTVerify(256)(poseidon_hasher.out, smt_leaf_key, smt_root, smt_siblings, 0);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ include "../../other/smt.circom";
|
||||
|
||||
template ValidateCountry(nLevels) {
|
||||
signal input host_user[6]; // Pair of (user country followed by host's country)
|
||||
signal input smt_leaf_value;
|
||||
signal input smt_leaf_key;
|
||||
signal input smt_root;
|
||||
signal input smt_siblings[256];
|
||||
|
||||
@@ -16,5 +16,5 @@ template ValidateCountry(nLevels) {
|
||||
poseidon_hasher.inputs[i] <== host_user[i];
|
||||
}
|
||||
|
||||
SMTVerify(nLevels)(poseidon_hasher.out, smt_leaf_value, smt_root, smt_siblings, 0);
|
||||
SMTVerify(nLevels)(poseidon_hasher.out, smt_leaf_key, smt_root, smt_siblings, 0);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ describe('OFAC - Passport number match', function () {
|
||||
it('should pass - wrong merkleroot, level 3', async function () {
|
||||
const wrongInputs = {
|
||||
...nonMemSmtInputs,
|
||||
smt_leaf_value: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
smt_leaf_key: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
};
|
||||
let w = await circuit.calculateWitness(wrongInputs);
|
||||
const ofacCheckResult = (await circuit.getOutput(w, ['ofacCheckResult'])).ofacCheckResult;
|
||||
@@ -158,7 +158,7 @@ describe('OFAC - Name and DOB match', function () {
|
||||
it('should pass - wrong merkleroot, level 2', async function () {
|
||||
const wrongInputs = {
|
||||
...nonMemSmtInputs,
|
||||
smt_leaf_value: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
smt_leaf_key: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
};
|
||||
|
||||
let w = await circuit.calculateWitness(wrongInputs);
|
||||
@@ -226,7 +226,7 @@ describe('OFAC - Name match', function () {
|
||||
it('should pass - wrong merkleroot, level 1', async function () {
|
||||
const wrongInputs = {
|
||||
...nonMemSmtInputs,
|
||||
smt_leaf_value: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
smt_leaf_key: BigInt(Math.floor(Math.random() * Math.pow(2, 254))).toString(),
|
||||
};
|
||||
let w = await circuit.calculateWitness(wrongInputs);
|
||||
const ofacCheckResult = (await circuit.getOutput(w, ['ofacCheckResult'])).ofacCheckResult;
|
||||
|
||||
Reference in New Issue
Block a user