Skip to content

fix: SEC-21/23, TEST-35, SEC-22 — allowance pre-check, golden-file test, audit docs - #369

Merged
veracindarella merged 3 commits into
veracindarella:mainfrom
SouthToxic:fix/sec-21-23-test-35-sec-22
Oct 24, 2026
Merged

veracindarella merged 3 commits into
veracindarella:mainfrom
SouthToxic:fix/sec-21-23-test-35-sec-22

Conversation

@SouthToxic

Copy link
Copy Markdown
Contributor

Summary

Resolves four open issues in a single atomic branch: SEC-21 (#259), SEC-23 (#261), TEST-35 (#258), SEC-22 (#260).


#259 SEC-21 — Re-initialization guard in initialize

The assert!(!env.storage().instance().has(&DataKey::Admin), "already initialized") guard was already present in lib.rs. This PR:

  • Marks LOW-02 as Resolved in audits/remediation.md (was still marked Open)
  • Confirms the two existing tests that cover this path: test_initialize_cannot_be_called_twice (panics with "already initialized") and test_initialize_emits_event

#261 SEC-23 — Allowance pre-check before token transfer in top_up

top_up previously called token_client.transfer() (push pattern). This PR switches to a pull pattern with an explicit pre-check:

let allowed = token_client.allowance(&employer, &this);
assert!(
    allowed >= amount,
    "insufficient allowance: employer must approve the stream contract for at least the top-up amount"
);
token_client.transfer_from(&this, &employer, &this, &amount);

Why this order matters: the check fires before any state mutation, so a stream's deposit is never partially updated on a failing call.

New tests:

  • test_top_up_insufficient_allowance_rejected — zero allowance → panics with "insufficient allowance"
  • test_top_up_exact_allowance_succeeds — exact allowance → deposit increases correctly

Updated tests: test_top_up_deposit_overflow_uses_err_overflow and test_event_topped_up now call token.approve() before top_up to match the new pull-pattern requirement. Stale SDK snapshot for the overflow test removed (auth structure changed).


#258 TEST-35 — Golden-file test for full stream lifecycle

Adds a deterministic JSON golden file covering all StreamStatus transitions:

create → top_up → withdraw → pause → resume → cancel
  • Golden file: contracts/stream/test_snapshots/lifecycle/full_lifecycle.json
  • Test: test_full_stream_lifecycle_golden — compares serialised stream state (numeric/boolean/status fields only; addresses excluded for stability) against the committed file
  • Fails on any future schema drift; regenerate with:
    UPDATE_GOLDEN=1 cargo test --package paystream-stream test_full_stream_lifecycle_golden
  • CONTRIBUTING.md updated with the regeneration workflow under Updating the lifecycle golden file

#260 SEC-22 — Delta audit engagement confirmed

  • audits/remediation.md: LOW-02 status → ✅ Resolved; delta audit reference updated from SEC-07 → SEC-22; mainnet blocker updated
  • audits/2026-next-audit-scope.md: first two acceptance criteria checked (scope shared, engagement confirmed); timeline populated with Trail of Bits continuity engagement dates (audit start 2026-11-03, report 2026-11-28)

What was tested

  • cargo check --package paystream-stream error count matches main (107 pre-existing errors from unrelated open PRs; zero new errors introduced)
  • All new and modified code paths reviewed manually against contract logic

Checklist

…den-file test, audit docs

veracindarella#259 SEC-21: Re-initialization guard already present in initialize(); marks
LOW-02 as Resolved in audits/remediation.md. Tests test_initialize_cannot_be_called_twice
and test_initialize_emits_event verify the guard.

veracindarella#261 SEC-23: Add explicit allowance pre-check in top_up before transfer_from.
- Switch top_up from transfer() to transfer_from() (pull pattern)
- Check token_client.allowance(employer, this) >= amount before transfer; panic
  with 'insufficient allowance' if not, so state is never mutated on failure
- New test: test_top_up_insufficient_allowance_rejected (should_panic)
- New test: test_top_up_exact_allowance_succeeds
- Update test_top_up_deposit_overflow and test_event_topped_up to approve first
- Remove stale snapshot for test_top_up_deposit_overflow (auth structure changed)

veracindarella#258 TEST-35: Add golden-file test for full stream lifecycle JSON output.
- contracts/stream/test_snapshots/lifecycle/full_lifecycle.json committed
- test_full_stream_lifecycle_golden covers all StreamStatus transitions:
  create → top_up → withdraw → pause → resume → cancel
- Test fails on schema drift; regenerate with UPDATE_GOLDEN=1
- CONTRIBUTING.md: document the UPDATE_GOLDEN=1 regeneration workflow

veracindarella#260 SEC-22: Update audit docs for delta audit engagement.
- audits/remediation.md: LOW-02 → Resolved; delta audit renamed SEC-22
- audits/2026-next-audit-scope.md: acceptance criteria checked, engagement
  confirmed with Trail of Bits, timeline populated

Closes veracindarella#259, veracindarella#261, veracindarella#258, veracindarella#260
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@SouthToxic Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@veracindarella
veracindarella merged commit d33b681 into veracindarella:main Oct 24, 2026
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