Skip to content

certora: prove a market is not read before it is created#1076

Open
claude[bot] wants to merge 14 commits into
mainfrom
certora/market-not-read-before-created
Open

certora: prove a market is not read before it is created#1076
claude[bot] wants to merge 14 commits into
mainfrom
certora/market-not-read-before-created

Conversation

@claude

@claude claude Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Requested by Mathis GD · Slack thread

Adds a Certora rule proving that no code path reads a market or position field before that market is created (its tickSpacing is still zero). This covers the "show that a market is not read before it is created" item in the verification wishlist (#109).

Interesting find:

  • updatePositionView and isHealthy technically break that rule (would have been better if they reverted). But we show that they return always the same thing (and something that makes sense).

Add a Certora rule showing that no code path reads a non-empty market or
position field before the market is created (its tickSpacing is still zero).

A persistent ghost is flipped by Sload hooks on every non-sentinel market
state and position field, gated on the market being uncreated and the loaded
value being non-zero. A parametric non-view rule asserts the ghost stays
false across every entry point, filtering out the raw storage getters that
legitimately read a field without requiring the market to exist.
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
claude added 3 commits July 24, 2026 06:23
…otCreatedMarket invariants

Drop the val != 0 guard from every Sload hook so a read of an uncreated
market's field is flagged regardless of value (previously near-vacuous,
since uncreated fields are all zero). Assume the NotCreatedMarket
empty-if-not-created invariants via requireInvariant to exclude
unreachable prover states, and drop the redundant view-getter selector
exclusions (already covered by !f.isView). Restrict the conf to the read
rule so the assumed invariants are not re-verified here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XBDthGpRnNF7tdNvCPhCXB
Inline the now-short filtered clause on the rule signature to satisfy the
Certora CVL formatter (format CI check).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XBDthGpRnNF7tdNvCPhCXB
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
…the read rule; clarify hook comment per review
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated

@MathisGD MathisGD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread certora/specs/MarketNotReadBeforeCreated.spec
claude added 3 commits July 24, 2026 09:56
…ed markets

Exclude the two computed views from marketNotReadBeforeCreated (they read
position fields before any createdness check) and instead prove their
uncreated-market behavior is benign: updatePositionView returns (0,0,0) and
isHealthy returns true. Redeclare only the required empty-if-not-created
invariants (proven in NotCreatedMarket.conf) as requireInvariant hypotheses.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XBDthGpRnNF7tdNvCPhCXB
Deduplicate by relocating updatePositionViewIsZeroIfMarketNotCreated and
marketIsHealthyIfNotCreated into NotCreatedMarket.spec, reusing its in-file
'empty if not created' invariants instead of redeclaring them. Remove the
isHealthy/mulDivDown/mulDivUp NONDET summaries there so the rules prove against
the real functions. Strip the now-unused scaffolding (redeclared invariants,
helpers, envfree getters) from MarketNotReadBeforeCreated.spec, keeping only
marketNotReadBeforeCreated, and narrow its conf rule list accordingly.
Comment thread certora/specs/NotCreatedMarket.spec Outdated
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
Comment thread certora/specs/NotCreatedMarket.spec Outdated
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
Comment thread certora/specs/MarketNotReadBeforeCreated.spec Outdated
Co-authored-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
Signed-off-by: MathisGD <74971347+MathisGD@users.noreply.github.com>
@MathisGD MathisGD self-assigned this Jul 24, 2026
@MathisGD
MathisGD marked this pull request as ready for review July 24, 2026 13:23
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