add root range check

This commit is contained in:
poma 2021-02-23 12:13:51 +03:00
parent 59f13c3aaa
commit 2bcb37c628
No known key found for this signature in database
GPG Key ID: BA20CB01FE165657

View File

@ -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;
}
}