test(ethexe-runtime-common): PayloadLookup::force_stored violates 'Zero payload stored directly' invariant (auto-tester) 6938735d5395#5526
Draft
grishasobol wants to merge 1 commit into
Conversation
…ro payload stored directly' invariant (auto-tester) 6938735d5395 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
PayloadLookup::force_stored()called on aDirect(Payload::new())(the canonical empty payload) writes the empty payload to storage and converts the variant toStored(hash). This contradicts the documented type-level invariant onPayloadLookupatethexe/runtime/common/src/state.rs:62:Scenario:
zero_valueHash:
6938735d5395Unit:
ethexe-runtime-commonObserved
After
PayloadLookup::empty().force_stored(&storage)the variant becomesStored(_)whilePayloadLookup::empty()initially returnedDirect(Payload::new()). Reproduces 3/3 deterministically.Rubric items satisfied
ethexe/runtime/common/src/state.rs:62states verbatim:/// Zero payload should always be stored directly.Calling the publicforce_storedmethod on an empty payload moves the value fromDirecttoStored, violating the invariant.Root cause
The method does not check
payload.is_empty()before writing. The type's own invariant requires empty payloads to remain in theDirectvariant; the method has no early-return for that case.Suggested fix
Add an early return for empty payloads (no storage write, no variant change):
Or weaken the doc comment to "Zero payload is stored directly by default, unless explicitly forced via
force_stored." — then update callers to never invoke it on empty payloads.Practical reachability
Any caller that uses
force_storedon a payload it didn't pre-validate as non-empty will silently violate the invariant. The variant is observable viaPayloadLookup::is_empty()(returnsfalsefor the brokenStoredempty) and via SCALE codec — downstream code that pattern-matches onDirect/Storedmay take a different branch than expected.Test source
Generated by
/gear-dev:tester(auto-tester). This is a draft PR — requires human review before merge.