sha256 hash returns incorrect result if input's `(byteLength & 63) == 63`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- cryptography, testing-qa
Research direction
Start by reproducing the failure with the 191-byte and 575-byte cases in test/unit/index.test.ts, then run yarn test and compare sha256.digest output with the expected SHA-256 values shown here. Done means both regression cases, including inputs where byteLength % 64 == 63, produce the expected hexadecimal digests.
Written by the indexing model from the issue text.
Description
The hash function returns incorrect result for any inputs where byteLength % 64 == 63. To reproduce create a test case where byte length % 64 == 63 and compare it against another implementation of sha256.
example test one:
it("hex bytes of 191 byte length", function () {
const inputStr = "1".repeat(382);
const input = Buffer.from(inputStr, "hex");
expect(input.length).to.be.equal(191);
const output = Buffer.from(sha256.digest(input)).toString("hex");
expect(output).to.be.equal("b8ffd888fe6ffff63cb0193ad93b0fee6bda8ea913e4e75424af7914f55d3411");
});
example one output running yarn test
AssertionError: expected 'de66d39d769de0b512fe724191d53339a3efc…' to equal 'b8ffd888fe6ffff63cb0193ad93b0fee6bda8…'
+ expected - actual
-de66d39d769de0b512fe724191d53339a3efc491875c25795a2c20bb7c03ad32
+b8ffd888fe6ffff63cb0193ad93b0fee6bda8ea913e4e75424af7914f55d3411
example two
it("hex bytes of 676 byte length", function () {
const inputStr = "1".repeat(1150);
const input = Buffer.from(inputStr, "hex");
expect(input.length).to.be.equal(575);
const output = Buffer.from(sha256.digest(input)).toString("hex");
expect(output).to.be.equal("fc6b0073005a8ce2b4bf9a9c482bb2b1707bc1dab06c0185752104157edb62c6");
});
example two output running yarn test
digest function
hex bytes of 575 byte length:
AssertionError: expected '758a6d0187dfd01483d6a7e742bdda25a2f47…' to equal 'fc6b0073005a8ce2b4bf9a9c482bb2b1707bc…'
+ expected - actual
-758a6d0187dfd01483d6a7e742bdda25a2f47ef804fed45423484b27a6717243
+fc6b0073005a8ce2b4bf9a9c482bb2b1707bc1dab06c0185752104157edb62c6
at Context.<anonymous> (test/unit/index.test.ts:22:28)
at processImmediate (node:internal/timers:478:21)
I am still working through why this behavior occurs - I believe this could be an edge case in the math that is not handled correctly, any assistance on this would be greatly appreciated.
- Dominant language
- TypeScript
- Stars
- 62
- Forks
- 27
- Avg merge
- 19h 2m
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ChainSafe/ssz
-
BitList deserialization with reuseBytes: true mutates the input bufferPossibly taken @GiHoon1123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
SSZ Union Deserialization Vulnerable to Trailing Data for Certain VariantsPossibly taken @shadowzzed claimed this 44 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 58/100
-
Container SSZ deserialize on short/empty inputs throws RangeErrorPossibly taken @GiHoon1123 claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Similar issues
-
area:agent-view area:tui bug platform:macos
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
anthropics/claude-code#104558 ·
Maintainers usually reply within 1 day
-
updater
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
UniversityOfHelsinkiCS/oodikone#5141 ·
-
maintanance
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
inmanta/web-console#7606 ·
Maintainers usually reply within 1 day
-
bug skills
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
equinor/fusion-framework#5846 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100