Skip to content

Test/remit split schedule id sequencing#412

Open
Agbasimere wants to merge 7 commits intoRemitwise-Org:mainfrom
Agbasimere:test/remit-split-schedule-id-sequencing
Open

Test/remit split schedule id sequencing#412
Agbasimere wants to merge 7 commits intoRemitwise-Org:mainfrom
Agbasimere:test/remit-split-schedule-id-sequencing

Conversation

@Agbasimere
Copy link
Copy Markdown

Closes: #250

Description

This PR implements replay-safe schedule ID sequencing for the RemittanceSplit contract. It ensures that every remittance schedule is assigned a strictly monotonic, unique identifier, preventing ID collisions even across high-volume creation and modification cycles.

Key Changes

  • Monotonic ID Counter: Implemented a synchronized NEXT_RSCH storage counter to generate unique IDs.
  • Safe Arithmetic: Integrated checked_add to prevent u32 overflow vulnerabilities, returning RemittanceSplitError::Overflow if the limit is reached.
  • Collision Protection: Added an explicit storage-level check (contains_key) before assignment as a "defense-in-depth" measure for ID uniqueness.
  • NatSpec Documentation: Added formal documentation to the creation logic in remittance_split/src/lib.rs defining the security invariants.
  • Security Updates: Updated remittance_split/README.md to document the schedule ID sequencing as a core platform invariant.

Verification & Testing

Unit & Stress Tests

Added a suite of validation tests in remittance_split/tests/stress_test_large_amounts.rs:

  • test_schedule_id_sequencing_monotonicity: Verifies steady incrementing (1, 2, 3...) for 100+ operations.
  • test_schedule_id_uniqueness_across_operations: Confirms IDs remain unique and locked during modification and cancellation.
  • test_high_volume_schedule_creation_no_collisions: Bulk-creates 500 schedules and verifies 100% uniqueness via key mapping.

Security Invariants

  • Monotonicity: IDs only increase, ensuring the history cannot be "rolled back" or replayed under an old ID.
  • Uniqueness: IDs are never reused, even after a schedule is cancelled.

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.

Add replay-safe schedule id sequencing checks

1 participant