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 904f6dc
Showing 1 changed file with 17 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,27 @@ template IsValidMerkleBranchOut(N) {

component hashers[N];
component isZero[N];
component pow[N];
component divisionByTwo[N];
component divisionByPow[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;

divisionByPow[i] = DivisionBy();
divisionByPow[i].dividend <== index;
divisionByPow[i].divisor <== pow[i].out;

divisionByTwo[i] = DivisionBy();
divisionByTwo[i].dividend <== divisionByPow[i].quotient;
divisionByTwo[i].divisor <== 2;

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

var current[256];

Expand Down

0 comments on commit 904f6dc

Please sign in to comment.