Skip to content

Commit

Permalink
fix(SH2-02): add constraint for bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenportkey committed Sep 10, 2024
1 parent 0a9b2db commit 2d95d94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 6 additions & 0 deletions circuits/helpers/sha256.circom
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pragma circom 2.1.5;

include "circomlib/circuits/bitify.circom";
include "./misc.circom";
include "./utils.circom";
include "./sha256general.circom";
include "./sha256partial.circom";
Expand Down Expand Up @@ -71,6 +72,7 @@ template Sha256PadBytes(max_bytes) {
signal input in_bytes;
signal output padded_text[max_bytes];
signal output padded_len;
assert(in_bytes > 0);

// in_bytes + 1 bytes + 8 bytes length < max_bytes
assert(in_bytes + 9 < max_bytes);
Expand All @@ -87,5 +89,9 @@ template Sha256PadBytes(max_bytes) {
padded_text[i] <-- i < in_bytes ? in[i] : (i == in_bytes ? (1 << 7) : ((i < padded_len && i >= padded_len - 8) ? len2bytes.out[(i % 64 - 56)]: 0)); // Add the 1 on the end and text length
}

signal enabled[max_bytes] <== LTBitVector(max_bytes)(in_bytes);
for (var i = 0; i < max_bytes; i++) {
AssertEqualIfEnabled()(enabled[i], [padded_text[i], in[i]]);
}
SHA2PadVerifier(max_bytes)(padded_text, padded_len, in_bytes);
}
2 changes: 0 additions & 2 deletions tests/helpers/sha256.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe("SHA256", () => {
"0",
"hello world",
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0",
"",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZab", // length 54 = 64 - 10
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabc", // length 55 = 64 - 9
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd", // length 56 = 64 - 8
Expand Down Expand Up @@ -84,7 +83,6 @@ describe("SHA256", () => {
"0",
"hello world",
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0",
"",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZab", // length 54 = 64 - 10
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabc", // length 55 = 64 - 9
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcd", // length 56 = 64 - 8
Expand Down

0 comments on commit 2d95d94

Please sign in to comment.