Skip to content

Commit 81afb0b

Browse files
authored
Revert "fix: added missing range checks in ShaBytesDynamic (#579)" (#617)
This reverts commit 0c8c873.
1 parent e814b2f commit 81afb0b

File tree

2 files changed

+0
-33
lines changed

2 files changed

+0
-33
lines changed

circuits/circuits/utils/crypto/hasher/shaBytes/dynamic/sha1Bytes.circom

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ include "@openpassport/zk-email-circuits/utils/array.circom";
66
include "circomlib/circuits/bitify.circom";
77

88
//Adapted from @openpassport/zk-email-circuits/helpers/sha.circom
9-
// Assumption: The value `in_len_padded_bytes * 8` must fit within `ceil(log2(max_num_bytes * 8))` bits.
10-
// This range constraint is assumed (but not enforced) by the underlying `Sha1General` template.
11-
// It must be enforced externally, via a Num2Bits check, to prevent incorrect hash outputs.
129
template Sha1Bytes(max_num_bytes) {
1310
signal input in_padded[max_num_bytes];
1411
signal input in_len_padded_bytes;
@@ -36,9 +33,6 @@ template Sha1Bytes(max_num_bytes) {
3633

3734
//Adapted from @openpassport/zk-email-circuits/helpers/sha256general.circom
3835
//Sha1 template from https://github.com/dmpierre/sha1-circom/blob/fe18319cf72b9f3b83d0cea8f49a1f04482c125b/circuits/sha1.circom
39-
// Assumption: The value of `in_len_padded_bits` must fit within `ceil(log2(maxBitsPadded))` bits.
40-
// This constraint is required to ensure soundness of the LessEqThan comparator.
41-
// It is not enforced here: it must be guaranteed by the "caller", via a Num2Bits check!
4236
template Sha1General(maxBitsPadded) {
4337
assert(maxBitsPadded % 512 == 0);
4438
var maxBitsPaddedBits = log2Ceil(maxBitsPadded);

circuits/circuits/utils/crypto/hasher/shaBytes/shaBytesDynamic.circom

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ include "./dynamic/sha224Bytes.circom";
55
include "@openpassport/zk-email-circuits/lib/sha.circom";
66
include "./dynamic/sha384Bytes.circom";
77
include "./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

Comments
 (0)