diff --git a/CHANGE.md b/CHANGE.md deleted file mode 100644 index 9c9eb83..0000000 --- a/CHANGE.md +++ /dev/null @@ -1,9 +0,0 @@ -# SplitStream Core — Explanation of Changes - -This document explains, in plain prose, what was changed in `SplitStream-Labs/splitstream-core` after the repository was rejected from the Stellar Wave program (Drips Wave), and why. The rejection was relayed to us internally as the instruction to "rebase this project fully on Soroban," so the first thing we did was verify that premise rather than act on it. The repository at the rejected baseline commit (`226fa4e`) was already a native Soroban project: it compiled against `soroban-sdk` 28.0.0, targeted `wasm32v1-none`, used `#[contract]`, `#[contractimpl]`, `#[contracttype]` and `#[contracterror]`, moved value through the SEP-41 `token::TokenClient`, and used Soroban's instance/persistent storage split with explicit `extend_ttl` management. There is no EVM contract, no second chain, and no porting layer to migrate away from, so no chain migration was possible or performed. We therefore treated the rejection as a code-quality and credibility problem and spent the effort on the risks that actually exist for a Soroban contract holding funds — correctness and solvency defects, plus a repository whose documentation did not match its own dependency versions. If the original rejection rested on a different, more specific concern, the changes below are substantive either way: four real defects were found and fixed, each with a regression test that fails against the rejected revision. - -The most serious defect was that `execute_sweep` moved an admin-requested amount without any awareness of the contract's outstanding obligations, so the admin could drain pull-payment balances already credited to contributors and unvested amounts already owned under vesting schedules; the 72-hour timelock only delayed that drain, and affected contributors would later fail at the token transfer on `withdraw` or `claim_vested` with no on-chain recovery path. The vault now maintains an explicit liability ledger in instance storage — `CreditedTotal`, the sum of all outstanding contributor balances, and `VestingReserved`, the outstanding `sum(total - claimed)` vesting liability — updated transactionally alongside the per-account writes they track via `storage::add_balance`, `storage::take_balance` and `storage::adjust_vesting_reserved`, so the two cannot drift apart. `execute_sweep` now computes free funds as `balance(vault) - (CreditedTotal + VestingReserved)` and rejects anything larger with the new `InsufficientFreeFunds` (error 18), and three new read-only views (`get_total_credited`, `get_vesting_reserved`, `get_available_funds`) expose the same position. Second, `claim_vested` subtracted `schedule.claimed` from the vested amount with plain arithmetic while `create_vesting` preserved `claimed` across re-creation, so an admin could re-create a schedule with a smaller total than had already been paid, underflowing the subtraction; because the release profile sets `overflow-checks = true`, the wasm panicked and trapped, leaving the contributor's position permanently unclaimable with no explaining error. `create_vesting` now rejects `total < existing_claimed` with `InvalidAmount` (error 12), `claim_vested` uses `saturating_sub` so an already-corrupt schedule degrades to "nothing to claim" instead of trapping, and `claimed` is updated with `checked_add`. Third, `Admin`, `Oracle` and `Token` live in instance storage, yet only seven admin-gated functions bumped the instance TTL at the baseline and none of the intended-usage paths did — `deposit`, `post_cycle_root`, `credit_claim`, `withdraw`, `distribute_fixed`, `admin_distribute_fixed` and `claim_vested` — meaning a vault used exactly as designed would never refresh its TTL and would eventually become unreachable at every entry point, including read-only views. Every state-changing entry point now bumps it, and the docs state that as a rule rather than a per-function inventory. Fourth, `credit_claim` verified the Merkle proof and credited whatever amount it committed to without comparing the running total against `CycleInfo::total_amount`, so a compromised or buggy oracle could post a root summing above the total that maintainers reviewed during the challenge window; a new persistent counter `CycleClaimedTotal(cycle_id)` now caps cumulative claims and rejects over-payment with `CycleTotalExceeded` (error 19) before any state is written. Two smaller fixes round this out: `initialize` now checks whether it has already run before calling `require_auth`, so a second call reports `AlreadyInitialized` instead of an auth trap (the only intentional change to an existing function's observable behaviour, and it touches no successful path), and `withdraw` now uses a single `storage::take_balance` helper that zeroes the balance and decrements `CreditedTotal` together, keeping the checks-effects ordering and the liability bookkeeping as one operation. - -All of this is verified rather than asserted, from a clean checkout with Rust stable and `stellar-cli` 28.1.0. The suite went from 36 tests at the rejected baseline to 44 passing tests, adding four example-based tests that each fail on the old code — `credited_balances_are_reserved_against_sweeps`, `vesting_liability_is_reserved_against_sweeps`, `claims_are_capped_at_the_posted_cycle_total`, and `vesting_recreate_below_claimed_is_rejected`, the last including the `total == claimed` boundary that must remain legal — plus four deterministic, dependency-free property tests in `contracts/vault/src/property_test.rs`, driven by a seeded xorshift64 PRNG whose seed is printed on failure. Those property tests walk 48 random manifests of 1–32 leaves to confirm every leaf verifies, a one-unit amount change fails, every single-sibling substitution fails, and proofs never transfer between contributors; and they walk 24 random `(total, duration, start)` vesting schedules through random ledgers to confirm claims equal `floor(total * elapsed / duration)` exactly, are monotonic, never exceed `total`, keep the stored liability equal to `total - claimed`, and preserve the solvency identity `balance(vault) == available + credited + vesting_reserved` at every step, including at random re-creations. `cargo fmt --all -- --check` and `cargo clippy --all-targets -- -D warnings` both exit clean, and `stellar contract build` produces a 22,606-byte `splitstream_vault.wasm`. The hardened contract is not a screenshot: it is deployed and initialized on Testnet at `CB456KGXH4233BHW5BUEJMN6OJ4ZMWMPP3OXJU5HVQ2T2F7A7XHWLTAT`, both transactions are confirmed on-ledger, and a post-deploy smoke test of `deposit(10_000_000)` returned `get_available_funds` of `10_000_000` with both liabilities zero and no fixed shares. The exported surface is now 22 functions, up from 19, the additions being the three read-only views. - -The remaining work was bringing the repository's claims in line with its behaviour and being explicit about limits. The rejected revision declared three different SDK versions — `Cargo.toml` and `Cargo.lock` built `soroban-sdk` 28.0.0 while the README badge, Quick Start and the `rust-toolchain.toml` comment said 27.0.6, and CI pinned `stellar-cli` 27.1.0 — which matters because SDK 28 will not emit a contract artifact from an older CLI, so a reader following the README was in a configuration the code had never been tested in; CI and all docs now pin SDK 28.0.0 with CLI 28.1.0, confirmed by building. `README.md`, `docs/contract-reference.md`, `docs/for-maintainers.md`, `docs/protocol-mechanics.md`, `docs/developer-guide.md`, `docs/SUMMARY.md`, `docs-hub/architecture.md`, `docs-hub/index.md`, `SECURITY.md`, `CONTRIBUTING.md` and `CHANGELOG.md` were corrected rather than appended to: the function count moved from 19 to 22 with rows for the new views, the error table from 17 to 19, the storage layout now lists `CreditedTotal`, `VestingReserved` and `CycleClaimedTotal`, the "sweep is not balance-aware" and "`total_amount` is never summed against claims" notes were replaced with the enforcement that now exists, and `SECURITY.md` gained invariants 7–11 covering liability tracking, the sweep cap, the per-cycle over-payment cap, TTL liveness and the tightened vesting invariant. Compatibility was preserved deliberately: no function was removed, no signature changed, no error discriminant renumbered (18 and 19 are appended, 1–17 keep their codes), event topics and payloads are unchanged, the Merkle leaf format (`sha256(xdr(contributor) ++ xdr(amount))`, sorted-pair hashing) is unchanged so `splitstream-actions` manifests still verify, storage keys were only added, and the new views are additive. We would rather state the limitations than have them found in review: the new Testnet deployment uses freshly generated, Testnet-only keys funded from Friendbot and does not touch production keys; the previous address `CCC2LP2LOYZOLA2JW4C4K7JMR3TRJZIKHDSQYSFJ3R3MCDJLVBT3PZOC` still holds pre-fix bytecode and is superseded rather than mutated, with the deployment record in `docs/developer-guide.md`; the contract remains unaudited and this pass reduces specific risk without substituting for external review; vesting solvency is tracked and made visible, not escrowed, so deposits remain the maintainer's responsibility; and `Unauthorized` (error 3) stays declared but unused because error discriminants are frozen. Finally, to leave the repository immediately actionable for the next Wave, six scoped issues were opened with the `Stellar Wave` label — #30 read-only config and cycle views, #31 `cargo fmt` enforcement plus a dependency advisory audit in CI, #32 a reproducible Testnet deploy-and-initialize script, #33 a committed contract-spec snapshot asserting ABI stability, #34 randomised operation-sequence tests for the solvency invariants, and #35 a cross-repo golden fixture for the frozen Merkle leaf format — while the five pre-existing issues (#1–#5) were deliberately left untouched.