Skip to content

Commit

Permalink
feat(circom): fully constraint is_valid_merkle_branch_out
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-nikolov96 committed Jun 28, 2023
1 parent c558e88 commit f5ce88b
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma circom 2.1.5;
include "hash_two.circom";
include "../../../node_modules/circomlib/circuits/comparators.circom";
include "utils/arrays.circom";
include "utils/numerical.circom";

template IsValidMerkleBranchOut(N) {
signal input branch[N][256];
Expand All @@ -14,12 +15,22 @@ template IsValidMerkleBranchOut(N) {

component hashers[N];
component isZero[N];
component pow[N];
component divisionBy[N];

for(var i = 0; i < N; i++) {
hashers[i] = HashTwo();
isZero[i] = IsZero();

isZero[i].in <-- (index \ (2**i)) % 2;
pow[i] = Pow(256);
pow[i].base <== 2;
pow[i].power <== i;

divisionBy[i] = DivisionBy();
divisionBy[i].dividend <== pow[i].out;
divisionBy[i].divisor <== 2;

isZero[i].in <== divisionBy[i].remainder;

var current[256];

Expand Down

0 comments on commit f5ce88b

Please sign in to comment.