tests: storage-economics formula + conservation property tests#456
Merged
Merged
Conversation
Add property invariants for the storage emission weights and reward split, mirroring the modeling `test_storage.py` oracle: - storage_economics_invariants_over_random_sizes: over 12 random file sizes — ω_f/k_f strictly positive; rank_f increments by exactly 1 per creation; inactive creates leave Ω unchanged; each activation strictly increases Ω and increments |F|; distribute_storage_rewards conserves (Σ allocations ≤ pool, each positive). Self-relative (captures starting Ω/|F|). - storage_omega_f_decreases_with_rank_at_equal_size: equal size + higher rank ⇒ strictly smaller ω_f (ω_f = log10(s)/log10(1+rank)). Wired as a fresh-runtime `test_file_storage_storage_properties` so it isn't polluted by the smoke test's state. Design decision: asserts structural invariants (positivity, monotonicity, Σ≤pool) via comparisons, not re-derived exact ω_f/k_f values — robust to fixed-point rounding; exact values stay covered by the smoke test and the Python oracle. Test-only.
This was referenced Jun 3, 2026
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.
Stacked on #441. Adds property invariants for the storage emission weights (ω_f, k_f), the Ω accumulator, and reward distribution — mirroring the modeling
test_storage.pyoracle.Tests
storage_economics_invariants_over_random_sizes— over 12 random file sizes: ω_f/k_f strictly positive;rank_fincrements by exactly 1 per creation; inactive creates leave Ω unchanged; each activation strictly increases Ω and increments |F|;distribute_storage_rewardsconserves (Σ allocations ≤ pool, each positive).storage_omega_f_decreases_with_rank_at_equal_size— equal size + higher rank ⇒ strictly smaller ω_f (ω_f = log10(s)/log10(1+rank)).Design decisions
#[testlib::test](test_file_storage_storage_properties) so the property fns aren't polluted bystorage_economics_smoke's state; the fns are also self-relative (capture starting Ω/|F|).Test-only; no contract change.
Note
Low Risk
Test-only changes to indexer contract tests; no production or contract logic is modified.
Overview
Adds local-only indexer contract coverage for filestorage storage economics via a dedicated
test_file_storage_storage_propertiesentry point, separate from the existing smoke test so runtime state stays clean.New property checks exercise the native contract through create/join/activate flows: over many random file sizes they assert ω_f and k_f stay positive, rank_f steps by one per agreement, inactive creates leave Ω unchanged, each activation strictly raises Ω and |F|, and
distribute_storage_rewardsreturns only positive allocations with total paid ≤ the pool. A second case pins that equal s_bytes with higher rank_f yields strictly smaller ω_f (rank penalty in the weight formula).Assertions are structural (monotonicity, conservation, ordering) rather than re-deriving exact fixed-point weights, aligning with the Python modeling oracle without duplicating rounding logic in Rust.
Reviewed by Cursor Bugbot for commit e7678e2. Bugbot is set up for automated code reviews on this repo. Configure here.
Merge order: #456 and #452 both modify
core/indexer/tests/contracts/file_storage_tests/native_filestorage_contract.rs. Merge impl PR #452 before this test PR; rebase this on top afterward.