Skip to content

Filter empty wasm hash from snapshot lookups#1905

Open
leighmcculloch wants to merge 6 commits into
mainfrom
filter-empty-wasm-hash-snapshot
Open

Filter empty wasm hash from snapshot lookups#1905
leighmcculloch wants to merge 6 commits into
mainfrom
filter-empty-wasm-hash-snapshot

Conversation

@leighmcculloch

Copy link
Copy Markdown
Member

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 configured SnapshotSource. For custom SnapshotSource implementations 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 redundant SnapshotSource lookup, 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

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
leighmcculloch marked this pull request as ready for review June 16, 2026 04:59
Copilot AI review requested due to automatic review settings June 16, 2026 04:59

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

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 FilteringSnapshotSource wrapper in the testutils Env construction path to short-circuit ContractCode lookups 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.

Comment thread soroban-sdk/src/env.rs Outdated
Comment thread soroban-sdk/src/env.rs Outdated
@leighmcculloch

leighmcculloch commented Jul 23, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty WASM hash leaks to SnapshotSource and test snapshot files

3 participants