Skip to content

Conversation

@MathieuDutSik
Copy link
Contributor

@MathieuDutSik MathieuDutSik commented Sep 10, 2025

Motivation

For the purpose of testing if a contract exists in EVM, we introduce the functionality of testing if a contract
has empty storage.

Proposal

The following is done:

  • The functionality is added to the BaseRuntime.
  • It uses the TotalStorageSize in the execution_state_actor.rs.
  • It uses the view.total_size() of the KeyValueStoreView.
  • The functionality is provided to the Wasm smart contracts.

Several points have to be noted:

  • The Wasm smart contracts are persistent. Only at the end with the self.state.save().await does their state become observable. This point is exemplified in the example test.
  • So, if a contract is writing its state only at the fn finalize step, then we cannot see that its state is non-trivial only at the next block.
  • The designed use case for this feature is EVM smart contracts. Fortunately, for those contracts, we are writing the state directly to the storage and we are not waiting for fn finalize. So, that is fine here.

Test Plan

The CI.

For testing the has_empty_storage, we implemented separately some end-to-end tests.
They have not been put in the PR, since you need two contracts:

  • one that gets instantiated
  • and one that does the has_empty_storage.

Release Plan

This does not appear to be TestNet breaking.

Links

The test is implemented in test_has_empty_state

@MathieuDutSik MathieuDutSik marked this pull request as ready for review September 10, 2025 12:25
@MathieuDutSik MathieuDutSik force-pushed the has_non_trivial_storage branch 2 times, most recently from 2c0b666 to c836461 Compare September 17, 2025 06:01
@MathieuDutSik MathieuDutSik changed the title Implement a function has_non_trivial_storage in BaseRuntime. Implement a function has_trivial_storage in BaseRuntime. Sep 18, 2025
@MathieuDutSik MathieuDutSik marked this pull request as draft September 24, 2025 11:16
@MathieuDutSik MathieuDutSik force-pushed the has_non_trivial_storage branch from e7893a5 to 34c8d40 Compare November 4, 2025 10:07
@MathieuDutSik MathieuDutSik force-pushed the has_non_trivial_storage branch from 34c8d40 to 04872d0 Compare November 4, 2025 14:16
@MathieuDutSik MathieuDutSik marked this pull request as ready for review November 5, 2025 19:31
@MathieuDutSik MathieuDutSik changed the title Implement a function has_trivial_storage in BaseRuntime. Implement a function has_empty_storage in BaseRuntime. Nov 6, 2025
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.

2 participants