Following code seems to work for depth = 0 but fails for both depth = 0 and depth = 1.
template Spend(depth) {
signal input digest;
signal input nullifier;
signal private input nonce;
signal private input sibling[depth];
signal private input direction[depth];
signal spend_coin_path_hash[depth]; // array of hash values for spend coin merkle path
//signal spend_coin_hash[depth];
//signal spend_coin_path_digest; // variable to store the calculated merkle digest
var i; // variable i to track tree depth
// TODO
if (depth=0) {
component comp_spend_coin_hash = Mimc2();
comp_spend_coin_hash.in0 <== nullifier;
comp_spend_coin_hash.in1 <== nonce;
spend_coin_path_hash[0] <== comp_spend_coin_hash.out; //set the initial hash of leaf for the spend coin
// constraint to match on digest
spend_coin_path_hash[0] === digest;
}
if (depth=1) {
component comp2_spend_coin_hash = Mimc2();
component comp3 = SelectiveSwitch();
comp2_spend_coin_hash.in0 <== nullifier;
comp2_spend_coin_hash.in1 <== nonce;
spend_coin_path_hash[0] <== comp_spend_coin_hash.out;
comp3.in0 <== spend_coin_path_hash[0];
comp3.in1 <== sibling[0];
comp3.s <== direction[0];
comp_spend_coin_hash[depth].in0 <== comp3.out0;
comp_spend_coin_hash[depth].in1 <== comp3.out1;
spend_coin_path_hash[depth] <== comp_spend_coin_hash[depth].out;
// constraint to match on digest
spend_coin_path_hash[depth] === digest;
}
}
Get the error message Error: Invalid signal identifier: main.comp2_spend_coin_hash.in0