Skip to content

fix: reduce storage overhead and fix contract inconsistencies - #1

Open
confima-source wants to merge 15 commits into
mainfrom
fix/storage-overhead-and-contract-inconsistencies
Open

fix: reduce storage overhead and fix contract inconsistencies#1
confima-source wants to merge 15 commits into
mainfrom
fix/storage-overhead-and-contract-inconsistencies

Conversation

@confima-source

Copy link
Copy Markdown
Owner

Summary

Fixes two classes of issues: unnecessary storage/compute overhead and contract behavior inconsistencies.

Storage / Compute Overhead

  • get_deposit_ids O(n) → O(k): replaced the full 0..counter scan with a new VaultKey::ActiveDepositIds key that tracks only live deposit IDs.
  • add_depositor O(n) → O(1): replaced the full list scan with a VaultKey::DepositorMember boolean key for O(1) membership check.
  • Duplicate imports removed: constants now live exclusively in constants.rs.

Contract Inconsistencies

  • Events missing deposit_id: deposit, withdraw, and emergency_withdraw events now include deposit_id in their data payload.
  • cancel_deposit inverted guard: returns new FundsAlreadyUnlocked error (code 13) when now >= unlock_time instead of misusing FundsStillLocked.
  • batch_emergency_withdraw implemented: best-effort batch with BatchTooLarge guard (code 14).
  • Missing event helpers added: withdraw_to, paused, unpaused.

New Error Codes: FundsAlreadyUnlocked (13), BatchTooLarge (14)

Tests Added

  • batch_emergency_withdraw: all succeed, skip missing, non-admin fails, too-large fails
  • get_deposit_ids: active-only tracking after partial withdrawal
  • add_depositor: no duplicate in list for multiple deposits from same address
  • FundsAlreadyUnlocked: cancel after unlock and at exact unlock time

kenedybok3 and others added 15 commits June 23, 2026 16:34
…/docs/issue-278-vault-entry-field-docs

docs: add unit documentation to VaultEntry and LedgerVaultEntry field…
- Storage overhead:
  - get_deposit_ids: replace O(counter) full scan with O(k) ActiveDepositIds key
  - add_depositor: replace O(n) list scan with O(1) DepositorMember key check
  - contract.rs: remove duplicate imports (constants now in constants.rs only)
  - All events now include deposit_id in their data payload

- Contract inconsistencies:
  - deposit/withdraw/emergency_withdraw events: add deposit_id to data
  - cancel_deposit: fix inverted guard — return FundsAlreadyUnlocked (code 13)
    when now >= unlock_time instead of misusing FundsStillLocked
  - batch_emergency_withdraw: implement missing function with BatchTooLarge (code 14) guard
  - withdraw_to, paused, unpaused: add missing event helpers in events.rs

- New error codes:
  - FundsAlreadyUnlocked = 13
  - BatchTooLarge = 14

- Tests:
  - batch_emergency_withdraw: all succeed, skip missing, non-admin fails, too large
  - get_deposit_ids: active-only tracking after partial withdrawal
  - add_depositor: no duplicate added for multiple deposits from same address
  - FundsAlreadyUnlocked: cancel after unlock and at exact unlock time
…time-lock-vault#274, decentralized-time-lock-vault#275, decentralized-time-lock-vault#336

- docs(changelog): document ledger-based deposit timing semantics for
  deposit and deposit_for, including unlock_time validation rules and
  usage examples (decentralized-time-lock-vault#273)
- docs(contributing): add Soroban-specific testing guidance covering
  testutils environment, ledger time manipulation, test conventions,
  and SDK version policy (decentralized-time-lock-vault#274)
- docs(security): add responsible disclosure timeline table and
  four-level severity guidelines (Critical/High/Medium/Low) (decentralized-time-lock-vault#275)
- ci: add test-release job running cargo test --release --features
  testutils to catch optimisation-related regressions; build job now
  depends on test-release (decentralized-time-lock-vault#336)

Closes decentralized-time-lock-vault#273
Closes decentralized-time-lock-vault#274
Closes decentralized-time-lock-vault#275
Closes decentralized-time-lock-vault#336
…t to initialize

- types.rs: replace DepositorList (Vec) with DepositorCount + DepositorAt(u32) +
  DepositorIndex(Address) keys for O(1) add/remove
- storage.rs: rewrite add/remove_depositor using swap-remove; eliminate linear
  scan and growing single-key Vec blob
- contract.rs: cap get_depositors limit at 100 to prevent unbounded page reads;
  add fee_recipient: Option<Address> param to initialize so penalty destination
  is set at deployment time
- test.rs: update all setup helpers for new initialize signature; fix
  test_cancel_deposit_partial_penalty_splits_correctly for real fee_recipient
  routing; add 8 new tests covering limit cap, zero limit, swap-remove
  correctness, cancel removes depositor, fee_recipient via initialize, penalty
  routing, and no-fee-recipient initialisation
…x/issues-340-342-344-346

ci: add Cargo ecosystem to Dependabot with soroban group
…2-code/fix/storage-perf-and-correctness

fix: O(1) depositor index, cap get_depositors limit, add fee_recipien…
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.

5 participants