Skip to content

fix: resolve security, validation, reentrancy, and batching issues (#681, #682, #683, #684) - #716

Merged
nonsobethel0-dev merged 4 commits into
Parashield-Protocol:mainfrom
Ultra-Tech-code:fix/issues-681-682-683-684
Oct 20, 2026
Merged

nonsobethel0-dev merged 4 commits into
Parashield-Protocol:mainfrom
Ultra-Tech-code:fix/issues-681-682-683-684

Conversation

@Ultra-Tech-code

Copy link
Copy Markdown
Contributor

Description

This PR resolves 4 assigned issues across risk-pool, policy-engine, oracle-verifier, and claims-processor following atomic commits, strict validation, and comprehensive test coverage.

Closes #684
Closes #683
Closes #682
Closes #681


Detailed Changes

1. RiskPool: USDC Token Reentrancy Protection (#684)

  • Problem: Pool operations invoked external USDC token transfers without reentrancy protection.
  • Fix:
    • Implemented an RAII ReentrancyGuard in risk-pool/src/lib.rs using StorageKey::ReentrancyGuard and Error::Reentrancy = 47.
    • Protected all external USDC interaction points (deposit, withdraw, receive_premium, claim_yield, claim_exit, emergency_withdraw, execute_admin_withdrawal).
    • Followed Checks-Effects-Interactions (CEI): state variables, queue entries, and shares are updated prior to executing external token transfers.
    • Added unit tests in contracts/risk-pool/src/test_reentrancy.rs.
    • Documented in docs/REENTRANCY_GUARD.md.

2. PolicyEngine: Product Category Registry Validation (#682)

  • Problem: Products could be registered with arbitrary or unregistered categories, bypassing category-level risk caps.
  • Fix:
    • Introduced an on-chain category registry in policy-engine/src/lib.rs initialized with default categories (crop, flight, disaster, health, defi).
    • Added administrative functions: register_category, unregister_category, is_category_registered, get_registered_categories.
    • Validated product creation in create_product: rejects unregistered categories with Error::InvalidCategory = 36.
    • Added integration tests in contracts/policy-engine/tests/category_registry.rs.
    • Documented in docs/CATEGORY_REGISTRY.md.

3. OracleVerifier: Stake Withdrawal Challenge Period & Slashing (#681)

  • Problem: Oracles could withdraw their stake immediately after submitting false or malicious data without a challenge window or slashing protection.
  • Fix:
    • Implemented a mandatory challenge period (default: 7 days, configurable via set_challenge_period).
    • Added two-step stake withdrawal: request_stake_withdrawal followed by withdraw_stake after unlock_at.
    • Rejected early withdrawals before challenge period expiry with Error::ChallengePeriodNotElapsed = 33.
    • Enhanced slash_oracle to deduct penalties directly from pending withdrawal requests during the challenge period.
    • Fully slashed oracles have their pending withdrawal requests voided.
    • Added integration tests in contracts/oracle-verifier/tests/stake_challenge.rs.
    • Documented in docs/SLASHING_RULES.md.

4. ClaimsProcessor: Batch Oracle Verification for Complex Claims (#683)

  • Problem: Multi-reading or composite claims verified each oracle reading individually via separate cross-contract calls, consuming excessive instruction budget.
  • Fix:
    • Added batch_verify_fresh to OracleVerifier to evaluate multiple queries in a single invocation.
    • Updated IOracleVerifier trait and implemented batch_verify_oracle_readings and process_multi_reading_claim in ClaimsProcessor.
    • Supported flexible boolean aggregation (AND / OR logic) for multi-reading claims.
    • Added ReadingsBatchVerified event emission.
    • Added benchmark tests in contracts/claims-processor/tests/batch_oracle_verification.rs confirming CPU instruction savings.
    • Documented in docs/BATCH_ORACLE_VERIFICATION.md.

Verification & Testing

All test suites across each contract pass with 0 errors:

  • cargo test -p parashield-risk-pool test_reentrancy (2/2 passed)
  • cargo test -p parashield-policy-engine --test category_registry (4/4 passed)
  • cargo test -p parashield-oracle-verifier --test stake_challenge (4/4 passed)
  • cargo test -p parashield-claims-processor --test batch_oracle_verification (2/2 passed)

…ctions pattern

- Protect pool entry points with RAII ReentrancyGuard
- Follow Checks-Effects-Interactions (CEI) across token transfer points
- Add comprehensive reentrancy tests in test_reentrancy.rs
- Document reentrancy protection security pattern in REENTRANCY_GUARD.md

Resolves Parashield-Protocol#684
- Maintain an on-chain category registry with default approved categories
- Add admin methods to register, unregister, and query categories
- Reject product creation with unregistered categories
- Add integration tests for category registry and validation
- Document category registry and governance in CATEGORY_REGISTRY.md

Resolves Parashield-Protocol#682
- Enforce challenge period before stake withdrawal is permitted
- Reject early withdrawal attempts before challenge period expiry
- Apply slashing deductions to pending withdrawal requests during challenge period
- Void withdrawal request on full slash
- Add integration tests for stake withdrawal challenge period and slashing
- Document staking and slashing rules in SLASHING_RULES.md

Resolves Parashield-Protocol#681
- Add batch_verify_fresh to OracleVerifier for single-call multi-reading evaluation
- Update IOracleVerifier client interface with batch verification
- Implement batch_verify_oracle_readings and process_multi_reading_claim in ClaimsProcessor
- Add ReadingsBatchVerified event
- Add integration test and benchmark demonstrating instruction cost reduction
- Document batch verification architecture in BATCH_ORACLE_VERIFICATION.md

Resolves Parashield-Protocol#683
@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@Ultra-Tech-code 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 21c3529 into Parashield-Protocol:main Oct 20, 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