perf(crypto): build zero-memory allocation SHA2-256 Yul precompile caller - #758
Merged
mijinummi merged 1 commit intoAug 20, 2026
Conversation
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a zero-memory-allocation SHA2-256 precompile caller in Yul assembly, as described in issue #749.
Closes #749
Changes
1.
contracts/crypto/YulSHA256.sol[NEW]Implements a
YulSHA256Solidity library with ahash(bytes calldata data) internal view returns (bytes32)function:.offsetand.lengthdirectly in inline Yul assembly — no intermediate Solidity-level allocation.mload(0x40)) usingcalldatacopy, using it as a temporary scratch buffer without bumping the free memory pointer — ensuring zero memory expansion.0x02viastaticcall.0x00.mload(0x00).This avoids the memory allocation overhead of the high-level
sha256(bytes)built-in, which copies calldata into a new memory buffer before triggering the precompile.2.
test/crypto/YulSHA256.test.ts[NEW]Vitest-based unit tests covering:
cryptoSHA256 output.0x+ 64 hex chars).3.
test/crypto/YulMerkleVerifier.test.ts[FIX]Updated the
keccak256test helper to useethers.keccak256instead ofcrypto.createHash('keccak256'), which is unsupported in standard environments and was causing 8 test failures.4.
tsconfig.json[FIX]Merged duplicate
"include"keys in the root tsconfig that were causing aTSCONFIG_ERRORon compilation.Acceptance Criteria
Test Results