Skip to content

feat: implement claims processor contract with batch auto-processing … - #64

Merged
nonsobethel0-dev merged 1 commit into
Parashield-Protocol:mainfrom
timiturn3r:git-checkout--b-fix/claims-processor-idempotency
Jun 28, 2026
Merged

nonsobethel0-dev merged 1 commit into
Parashield-Protocol:mainfrom
timiturn3r:git-checkout--b-fix/claims-processor-idempotency

Conversation

@timiturn3r

Copy link
Copy Markdown
Contributor

#closes #15
Description
Fixes a critical vulnerability in the claims-processor contract where auto_process lacked an initial idempotency guard.

Previously, if a keeper triggered auto_process multiple times simultaneously or sequentially for the same policy, the contract would skip internal state checks and repeatedly execute the evaluation pipeline. If downstream guards in the Policy Engine were ever altered or bypassed, this would result in duplicate claim entries, multiple cross-contract calls, and potential double-payouts/escrow draining.

This PR introduces a defensive persistent storage lookup at the absolute top of the auto_process pipeline, tracking the state natively within the claims-processor workspace.

Fix Details
claims-processor/src/types.rs: Added the AlreadyProcessed variant to the ClaimResult enum.

claims-processor/src/lib.rs:

Injected a strict persistent storage guard checking StorageKey::PolicyClaim(policy_id) at the entry point of auto_process.

Early-returns ClaimResult::AlreadyProcessed if an active or settled claim record already exists for the given policy ID.

claims-processor/src/test_integration.rs: Brought the soroban_sdk::testutils::Ledger trait into scope to resolve cross-contract time-warping compilation issues (.with_mut()).

claims-processor/src/test.rs: Updated test_double_process_idempotent to assert the newly expected, explicit AlreadyProcessed result instead of downstream result codes.

Related Issues
Closes #15

Testing Checklist
[x] Verified via local unit and integration tests.

[x] Compilation warnings cleared (unused variables handled).

Bash

Output from localized verification run:

running 11 tests
test test::test_expired_policy_no_payout ... ok
test test::test_good_rainfall_no_payout ... ok
test test::test_double_process_idempotent ... ok
test test::test_double_submit_claim_panics - should panic ... ok
test test::test_non_policyholder_cannot_submit_claim - should panic ... ok
test test::test_drought_trigger_pays_out ... ok
test test_integration::batch_processes_multiple_pending_claims ... ok
test test::test_manual_claim_flow ... ok
test test_integration::batch_skips_non_pending_claims ... ok
test test_integration::test_stale_oracle_data_rejected - should panic ... ok
test test_integration::test_fresh_oracle_data_accepted ... ok

test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.51s
Storage & Security Considerations
Uses the persistent storage tier to prevent expiration of claim records, ensuring the idempotency guard remains durable over long operational timelines.

Adheres to Soroban contract-isolation best practices by making the contract responsible for validation of its own internal process state.
#closes

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Oluwasuyi-Timilehin 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

@nonsobethel0-dev
nonsobethel0-dev merged commit d880eaf into Parashield-Protocol:main Jun 28, 2026
1 of 2 checks passed
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.

claims-processor.rs: auto_process no idempotency check — calling twice for the same policy double-spends

2 participants