Repository navigation
test: pin that padMemory rewinds the pointer and makes measurement order immaterial - #194
Conversation
…der immaterial No test failed if padMemory stopped padding or stopped rewinding the free memory pointer. The new test checks the pointer is back where it started after padMemory, and that the linear and walk exports of a store with every list occupied, the most any test in the file allocates after one pad, each cost the same measured first after a pad as measured second. Closes #193 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe gas-claim suite adds a test that verifies ChangesMemory padding gas-claim validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Other · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to No concrete merge-blocking risk remains in this test-only change. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #193
Problem
padMemoryintest/src/lib/LibMemoryKV.gasClaims.t.solexpands memory past what the measurements allocate, then rewinds the free memory pointer. No test failed if it stopped doing either one. P1 (it never rewinds) and P3 (it pads nothing) both survived the gasClaims file.Fix
Adds
testPadMemoryRewindsThePointerAndMeasurementOrderChangesNeither, which checks what the pad's NatSpec promises:padMemoryequals the pointer before it.These two exports are the largest allocation any test in the file makes after one pad: 62 words (0x7c0 bytes).
testAnEmptyListCostsTheExportNothingandtestExportGasSavingFallsAsListsFillallocate the same amount at 15 lists.testExportGasIsTheSameForEveryListallocates 61 words, and the insert tests allocate less.Why this is correct
Before the second pad, memory is already expanded through everything the first pair touched. If the first pair paid for any memory expansion, the second pair pays less for the same allocation, so the gas differs. The cause does not matter: no pad, a pad too small, or a pad left below the allocations because the pointer was never rewound all show up the same way. The check therefore does not rely on the pad being the right size. It fails whenever the pad does not cover the largest allocation, including a pad of size 0. A check against the pad's own size would pass with that size set to 0. Both measurements come from the same build, and the test contains no absolute gas figures.
msizewould read memory expansion directly. solc rejects it while the Yul optimizer is on (error 6553), so the test measures gas instead.QA
testPadMemoryRewindsThePointerAndMeasurementOrderChangesNeither. It passes on the realpadMemoryand fails on each brokenpadMemorybelow (mutation-probe at 49b6a9e, with the suite set to this test alone and a baseline ofgreen (1 passed)). On main, P1 and P3 survive the whole gasClaims file (the [A23] [LOW] Tests hand-roll free-pointer, cheatcode and approx-assert primitives the dependencies provide #126 probe cited in the issue).setFreePointer(pointer);→(pointer);(never rewinds) → KILLED bytestPadMemoryRewindsThePointerAndMeasurementOrderChangesNeithernew bytes(0x1000)→new bytes(0)(pads nothing) → KILLED bytestPadMemoryRewindsThePointerAndMeasurementOrderChangesNeithernew bytes(0x1000)→new bytes(0x780)(one word short of the 0x7c0-byte allocation) → KILLED bytestPadMemoryRewindsThePointerAndMeasurementOrderChangesNeithernew bytes(0x1000)→new bytes(0x7a0)(the pad reaches exactly 0x7c0) → SURVIVED, as expected. Together with P4, this puts the test's boundary at the largest allocation.padMemoryis the reference for the rewind. For each export, the reference is the same export measured second after a pad, when the first pair has already expanded memory over the same region, so it pays no expansion. Neither reference depends on the pad size.🤖 Generated with Claude Code
Summary by CodeRabbit