Proptests, wiring smoke checks, storage versioning, and CEI fixes - #805
Open
christabel888 wants to merge 1 commit into
Open
Proptests, wiring smoke checks, storage versioning, and CEI fixes#805christabel888 wants to merge 1 commit into
christabel888 wants to merge 1 commit into
Conversation
Closes Vatix-Protocol#699, Vatix-Protocol#698, Vatix-Protocol#696, Vatix-Protocol#695. - Vatix-Protocol#699: Add proptest coverage for resolution's split_bond forfeited-bond accounting and treasury's distribute_fees payout invariants (sum conservation, no over/under-distribution, no panics on dust/edge amounts). Adds `proptest` as a dev-dependency to both crates. - Vatix-Protocol#698: Extend scripts/testnet-smoke.sh beyond get_fee_rate to also verify cross-contract wiring across all four contracts (market <-> outcome-token, market <-> resolution, treasury -> market), soft-skipping per-pairing when either side's contract ID isn't configured. - Vatix-Protocol#696: Add a STORAGE_VERSION constant + assert_version guard to the resolution and outcome-token contracts, mirroring the existing market/treasury pattern, gating every state-mutating entry point (finalize, propose, challenge, mint, burn, transfer, etc.) so a partial cross-contract upgrade fails closed with UpgradeRequired instead of silently operating on a stale layout. Updates version-matrix.json, check-upgrade.sh, and UPGRADE_PLAYBOOK.md accordingly. Also fixes a pre-existing compile bug in resolution/src/storage.rs where StorageKey::PendingFactory/PendingMarketContract were referenced but never declared on the enum. - Vatix-Protocol#695: Extend docs/reentrancy-cei-audit.md to cover the deposit path, treasury, resolution, and outcome-token contracts. Fixes the external-call-before-state-write CEI violations found along the way: market's deposit_collateral, treasury's withdraw_fees and distribute_fees, and resolution's propose/challenge/deposit_collateral now persist state before making their external token transfers. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wxp7wTANcFYARsQrFN9ZmE
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.
Closes #699
Closes #698
Closes #696
Closes #695
Summary
This PR bundles fixes for four assigned issues:
Proptest bond split and distribute_fees invariants #699 — Proptest bond split and distribute_fees invariants: Added proptest-based property tests for resolution's
split_bond(bond forfeiture/reward/burn/treasury split) and treasury'sdistribute_fees(stakeholder payout). Both cover sum-conservation ("no over/under-distribution"), no-panic behavior on dust/edge-case amounts, and proportionality against the documented bps splits.proptestwas added as a dev-dependency to theresolutionandtreasurycrates (mirroring the existing pattern inmarket).Multi-contract testnet smoke beyond get_fee_rate #698 — Multi-contract testnet smoke beyond get_fee_rate: Extended
scripts/testnet-smoke.shto, beyond the existingget_fee_rateliveness check, also verify basic cross-contract wiring: market's registered outcome-token/resolution addresses, resolution's and outcome-token's registered market address, and treasury's authorization of the configured market. Each pairing soft-skips independently (with a clear log line) when either side's contract ID isn't configured, so a partially-deployed environment still gets useful signal.Add STORAGE_VERSION to resolution and outcome-token #696 — Add STORAGE_VERSION to resolution and outcome-token: Added a
STORAGE_VERSIONconstant andstorage::assert_versionguard to both theresolutionandoutcome-tokencontracts, mirroring the existingmarket/treasurypattern. The guard now runs at the top of every state-mutating entry point on both contracts (finalize,propose,challenge,appeal,arbitrate_uphold_proposer,void_market, the address-rotation calls, andmint/burn/transfer/config setters respectively), so a partial cross-contract upgrade now fails closed withUpgradeRequiredinstead of silently operating against a stale on-chain layout. Updatedscripts/upgrade/version-matrix.json,scripts/upgrade/check-upgrade.sh, andscripts/upgrade/UPGRADE_PLAYBOOK.mdto reflect that both contracts moved fromwasmHashOnlytostorageVersionversioning. Also fixed a pre-existing compile bug incontracts/resolution/src/storage.rswhereStorageKey::PendingFactory/PendingMarketContractwere referenced by several functions but never declared on theStorageKeyenum.Complete CEI/reentrancy audit for deposit, treasury, resolution, outcome-token #695 — Complete CEI/reentrancy audit for deposit, treasury, resolution, outcome-token: Extended
docs/reentrancy-cei-audit.md(previously only covering withdraw+settle) to document the Checks-Effects-Interactions ordering for every external token call in the deposit path, treasury, resolution, and outcome-token. Found and fixed several genuine external-call-before-state-write violations along the way: market'sdeposit_collateral, treasury'swithdraw_feesanddistribute_fees, and resolution'spropose/challenge/deposit_collateralnow persist their state changes before making the corresponding external token transfer.Test plan
cargo test --workspace(not run in this environment — see note below)bash scripts/upgrade/check-upgrade.shbash scripts/testnet-smoke.shagainst a testnet deployment with all four contract IDs configuredNote: this environment could not run
cargo test/cargo checkend-to-end due to a pre-existing, unrelated dependency resolution issue (aned25519-dalek/ChaCha20Rngversion conflict originating insoroban-env-host's own test utilities when resolving a freshCargo.lock) — it reproduces before any change in this PR and is unrelated to the files touched here. All changes were reviewed by hand for structural/syntactic correctness against the existing patterns in each crate.