Filter empty wasm hash from snapshot lookups#1905
Open
leighmcculloch wants to merge 6 commits into
Open
Conversation
Native test contracts use the SHA256-of-empty-bytes hash as a synthetic wasm hash. The host requests a ContractCode entry for that hash when registering a native contract, which forces wasteful lookups against custom SnapshotSource implementations for an entry that never exists on any real network. Wrap the snapshot source in new_for_testutils with a FilteringSnapshotSource that short circuits ContractCode lookups for the empty wasm hash and returns None without consulting the inner source. Saved snapshots are intentionally left unchanged so reload still works. Fixes #1635
leighmcculloch
marked this pull request as ready for review
June 16, 2026 04:59
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the Soroban SDK test environment’s snapshot read-through behavior by intercepting SnapshotSource lookups for the synthetic “empty WASM” ContractCode hash used by native test contracts, returning None immediately instead of forwarding the request to potentially remote snapshot sources.
Changes:
- Added a
FilteringSnapshotSourcewrapper in the testutils Env construction path to short-circuitContractCodelookups for the empty WASM hash. - Added a regression test that asserts the empty WASM hash is never requested from a custom
SnapshotSource, while other expected lookups still pass through. - Added a new recorded snapshot output for the new test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| soroban-sdk/src/env.rs | Wraps the configured snapshot source with a filter that suppresses empty-WASM ContractCode lookups. |
| soroban-sdk/src/tests/snapshot_source_empty_wasm_hash.rs | Adds a unit test verifying the empty-WASM lookup is not forwarded to the underlying snapshot source. |
| soroban-sdk/src/tests.rs | Registers the new test module in the crate’s test suite. |
| soroban-sdk/test_snapshots/tests/snapshot_source_empty_wasm_hash/test_empty_wasm_hash_not_requested_from_snapshot_source.1.json | Adds the golden snapshot output associated with the new test. |
Member
Author
|
Solving this problem will become more important once we had capabilities like: Nothing needs changing today to support that, but this filtering snapshot source added in here will probably as part of that issue expand to filter out all natively installed contracts. |
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
Wrap the snapshot source used by the test environment so that read-throughs for the ContractCode entry of the empty WASM hash (the SHA256 of zero bytes that the host uses as the synthetic wasm hash for native test contracts) are short circuited and return None without ever reaching the underlying source.
Why
When registering a native test contract with
Env::register(), the host reads a ContractCode entry for the empty WASM hash, and because the test environment uses recording-footprint storage that read falls through to the configuredSnapshotSource. For customSnapshotSourceimplementations that fetch ledger state from remote or RPC endpoints, this forces a request for an entry that can never exist on any real network, adding latency and consuming rate-limited lookups during test setup for what is purely an internal implementation detail of native test contracts.Known limitations
The empty WASM ContractCode entry is intentionally left in saved ledger snapshots, so
to_ledger_snapshot()output is unchanged. A persisted native contract instance still references that hash, so removing the entry would break reloading the snapshot, and keeping it matches how every other contract carries a corresponding code entry. The fix only suppresses the redundantSnapshotSourcelookup, which is safe because native contracts dispatch through their registered functions rather than the wasm code, so the empty code entry is never executed on reload.Close #1635
Generated by Claude Code