Verify SHA-256 of contract code matches contract hash when fetching - #2465
Merged
Conversation
After fetching WASM bytes via get_remote_wasm_from_hash, compute sha256(returned_bytes) and compare it to the requested hash. Return an error if they don't match, preventing a compromised RPC provider from serving forged WASM. Extract verify_wasm_hash helper for testability and add tests for both matching and mismatched hashes. Closes #2463
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an integrity check when fetching contract WASM from an RPC server by verifying the downloaded bytecode’s SHA-256 matches the requested contract hash, reducing the risk of caching/using incorrect bytes.
Changes:
- Compute
sha256(downloaded_wasm)inutils::rpc::get_remote_wasm_from_hashand compare to the requestedHash. - Introduce
verify_wasm_hashhelper to centralize the hash verification and error creation. - Add unit tests for matching and mismatched hash scenarios.
leighmcculloch
enabled auto-merge
March 31, 2026 08:04
leighmcculloch
added this pull request to the merge queue
Apr 2, 2026
mootz12
removed this pull request from the merge queue due to a manual request
Apr 2, 2026
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.
What
Add SHA-256 integrity verification to
get_remote_wasm_from_hashinutils::rpc. After fetching Wasm bytecode, computesha256(returned_bytes)and compare it to the requested hash. Return a clear error with both the expected and computed hashes if they don't match. Add unit tests for matching and mismatched hashes.Why
The CLI fetched WASM bytecode from RPC servers without verifying the returned bytes matched the requested hash. While most data is trusted from the connected RPC, it's good defensive approach if the CLI verifies the contract code because it gets cached against the hash for future use locally.
Close #2463