@@ -5,7 +5,6 @@ include "./dynamic/sha224Bytes.circom";
55include " @openpassport/zk-email-circuits/lib/sha.circom" ;
66include " ./dynamic/sha384Bytes.circom" ;
77include " ./dynamic/sha512Bytes.circom" ;
8- include " circomlib/circuits/bitify.circom" ; // needed for Num2Bits
98
109// / @title ShaBytesDynamic
1110// / @notice Computes the hash of an input message using a specified hash length and padded input
@@ -27,38 +26,12 @@ template ShaBytesDynamic(hashLen, max_num_bytes) {
2726 hash_bits <== Sha384Bytes(max_num_bytes)(in_padded, in_len_padded_bytes);
2827 }
2928 if (hashLen == 256 ) {
30-
31- // Range check for the padded input length (in_len_padded_bytes).
32- // This check enforces that `in_len_padded_bytes * 8` can be represented using
33- // `ceil(log2(max_num_bytes * 8))` bits, which is a requirement assumed by the
34- // underlying SHA templates. Without this check, out-of-range values could
35- // silently bypass internal constraints, leading to incorrect hash outputs.
36- // For more information, see:
37- // https://github.com/zkemail/zk-email-verify/blob/b193cf0c760456b837b2bbcf7b2c72d5bb3f43c3/packages/circuits/lib/sha.circom#L87
38- var maxBitsPadded = max_num_bytes * 8 ;
39- var maxBitsPaddedBits = ceil (log2(maxBitsPadded));
40- component rangeCheck = Num2Bits(maxBitsPaddedBits);
41- rangeCheck.in <== in_len_padded_bytes * 8 ;
42-
4329 hash_bits <== Sha256Bytes(max_num_bytes)(in_padded, in_len_padded_bytes);
4430 }
4531 if (hashLen == 224 ) {
4632 hash_bits <== Sha224Bytes(max_num_bytes)(in_padded, in_len_padded_bytes);
4733 }
4834 if (hashLen == 160 ) {
49-
50- // Range check for the padded input length (in_len_padded_bytes).
51- // This check enforces that `in_len_padded_bytes * 8` can be represented using
52- // `ceil(log2(max_num_bytes * 8))` bits, which is a requirement assumed by the
53- // underlying SHA templates. Without this check, out-of-range values could
54- // silently bypass internal constraints, leading to incorrect hash outputs.
55- // For more information, see:
56- // https://github.com/selfxyz/self/pull/579#issuecomment-2922842294
57- var maxBitsPadded = max_num_bytes * 8 ;
58- var maxBitsPaddedBits = ceil (log2(maxBitsPadded));
59- component rangeCheck = Num2Bits(maxBitsPaddedBits);
60- rangeCheck.in <== in_len_padded_bytes * 8 ;
61-
6235 hash_bits <== Sha1Bytes(max_num_bytes)(in_padded, in_len_padded_bytes);
6336 }
6437
0 commit comments