Skip to content

Verify SHA-256 of contract code matches contract hash when fetching - #2465

Merged
mootz12 merged 3 commits into
mainfrom
verify-hash-of-contract-code
Apr 2, 2026
Merged

Verify SHA-256 of contract code matches contract hash when fetching#2465
mootz12 merged 3 commits into
mainfrom
verify-hash-of-contract-code

Conversation

@leighmcculloch

Copy link
Copy Markdown
Member

What

Add SHA-256 integrity verification to get_remote_wasm_from_hash in utils::rpc. After fetching Wasm bytecode, compute sha256(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

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
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Mar 31, 2026
@leighmcculloch
leighmcculloch marked this pull request as ready for review March 31, 2026 03:39
Copilot AI review requested due to automatic review settings March 31, 2026 03:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) in utils::rpc::get_remote_wasm_from_hash and compare to the requested Hash.
  • Introduce verify_wasm_hash helper to centralize the hash verification and error creation.
  • Add unit tests for matching and mismatched hash scenarios.

Comment thread cmd/soroban-cli/src/utils.rs Outdated
Comment thread cmd/soroban-cli/src/utils.rs Outdated
Comment thread cmd/soroban-cli/src/utils.rs
@leighmcculloch leighmcculloch moved this from Backlog (Not Ready) to Needs Review in DevX Mar 31, 2026

@mootz12 mootz12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG2M.

@leighmcculloch
leighmcculloch added this pull request to the merge queue Apr 2, 2026
@mootz12
mootz12 removed this pull request from the merge queue due to a manual request Apr 2, 2026
@mootz12
mootz12 merged commit cadec3f into main Apr 2, 2026
210 of 211 checks passed
@mootz12
mootz12 deleted the verify-hash-of-contract-code branch April 2, 2026 23:21
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in DevX Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CLI does not verify SHA-256 of WASM bytecode fetched from RPC

3 participants