From 2bcb37c6289286796f70edc79318013c7a25e376 Mon Sep 17 00:00:00 2001 From: poma Date: Tue, 23 Feb 2021 12:13:51 +0300 Subject: [PATCH] add root range check --- circuits/Utils.circom | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/circuits/Utils.circom b/circuits/Utils.circom index 977bd2a..05a2b81 100644 --- a/circuits/Utils.circom +++ b/circuits/Utils.circom @@ -14,21 +14,26 @@ template TreeUpdateArgsHasher(nLeaves) { var bitsPerLeaf = 160 + 256 + 32; component hasher = Sha256(header + nLeaves * bitsPerLeaf); - component bitsOldRoot = Num2Bits(256); - component bitsNewRoot = Num2Bits(256); + component bitsOldRoot = Num2Bits_strict(); + component bitsNewRoot = Num2Bits_strict(); component bitsPathIndices = Num2Bits(32); component bitsInstance[nLeaves]; component bitsHash[nLeaves]; component bitsBlock[nLeaves]; - + bitsOldRoot.in <== oldRoot; bitsNewRoot.in <== newRoot; bitsPathIndices.in <== pathIndices; - for(var i = 0; i < 256; i++) { - hasher.in[i] <== bitsOldRoot.out[255 - i]; + + hasher.in[0] <== 0; + hasher.in[1] <== 0; + for(var i = 0; i < 254; i++) { + hasher.in[i + 2] <== bitsOldRoot.out[253 - i]; } - for(var i = 0; i < 256; i++) { - hasher.in[i + 256] <== bitsNewRoot.out[255 - i]; + hasher.in[256] <== 0; + hasher.in[257] <== 0; + for(var i = 0; i < 254; i++) { + hasher.in[i + 258] <== bitsNewRoot.out[253 - i]; } for(var i = 0; i < 32; i++) { hasher.in[i + 512] <== bitsPathIndices.out[31 - i]; @@ -55,4 +60,4 @@ template TreeUpdateArgsHasher(nLeaves) { b2n.in[i] <== hasher.out[255 - i]; } out <== b2n.out; -} \ No newline at end of file +}