Skip to content

Proptests, wiring smoke checks, storage versioning, and CEI fixes - #805

Open
christabel888 wants to merge 1 commit into
Vatix-Protocol:devfrom
christabel888:fix/assigned-issues-batch
Open

Proptests, wiring smoke checks, storage versioning, and CEI fixes#805
christabel888 wants to merge 1 commit into
Vatix-Protocol:devfrom
christabel888:fix/assigned-issues-batch

Conversation

@christabel888

Copy link
Copy Markdown
Contributor

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's distribute_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. proptest was added as a dev-dependency to the resolution and treasury crates (mirroring the existing pattern in market).

  • Multi-contract testnet smoke beyond get_fee_rate #698 — Multi-contract testnet smoke beyond get_fee_rate: Extended scripts/testnet-smoke.sh to, beyond the existing get_fee_rate liveness 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_VERSION constant and storage::assert_version guard to both the resolution and outcome-token contracts, mirroring the existing market/treasury pattern. 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, and mint/burn/transfer/config setters respectively), so a partial cross-contract upgrade now fails closed with UpgradeRequired instead of silently operating against a stale on-chain layout. Updated scripts/upgrade/version-matrix.json, scripts/upgrade/check-upgrade.sh, and scripts/upgrade/UPGRADE_PLAYBOOK.md to reflect that both contracts moved from wasmHashOnly to storageVersion versioning. Also fixed a pre-existing compile bug in contracts/resolution/src/storage.rs where StorageKey::PendingFactory/PendingMarketContract were referenced by several functions but never declared on the StorageKey enum.

  • 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's deposit_collateral, treasury's withdraw_fees and distribute_fees, and resolution's propose/challenge/deposit_collateral now 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.sh
  • bash scripts/testnet-smoke.sh against a testnet deployment with all four contract IDs configured

Note: this environment could not run cargo test/cargo check end-to-end due to a pre-existing, unrelated dependency resolution issue (an ed25519-dalek/ChaCha20Rng version conflict originating in soroban-env-host's own test utilities when resolving a fresh Cargo.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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants