Skip to content

fix(settlement): enforce MAX_SETTLEMENT_DELAY_LEDGER on governance-de… - #591

Open
Chigybillionz wants to merge 2 commits into
Betta-Pay:mainfrom
Chigybillionz:fix/governance-delay-cap
Open

fix(settlement): enforce MAX_SETTLEMENT_DELAY_LEDGER on governance-de…#591
Chigybillionz wants to merge 2 commits into
Betta-Pay:mainfrom
Chigybillionz:fix/governance-delay-cap

Conversation

@Chigybillionz

Copy link
Copy Markdown
Contributor
Close #578 

### Summary of the issue
`set_settlement_rule` and `set_default_rule` enforce the delay cap `MAX_SETTLEMENT_DELAY_LEDGER` (100,000 ledgers), but the governance-sourced rule conversion path in `read_governance_fee_rule` bypassed this check. This created a delay cap bypass and divergent enforcement behavior across settlement rule resolution paths.
---
### Root cause
In `settlement_contract/src/storage.rs`, `read_governance_fee_rule` converted the governance contract's `FeeConfig` into a `SettlementRule` without performing a boundary check on `rule.settlement_delay_ledger` against `MAX_SETTLEMENT_DELAY_LEDGER`.
---
### Solution implemented
Enforced the `MAX_SETTLEMENT_DELAY_LEDGER` delay cap directly on the governance-derived rule conversion in `read_governance_fee_rule`. If the converted rule's `settlement_delay_ledger` exceeds `MAX_SETTLEMENT_DELAY_LEDGER`, the contract panics with `SettlementError::InvalidSettlementDelay`.

### Key changes made
- **`settlement_contract/src/storage.rs`**: Imported `MAX_SETTLEMENT_DELAY_LEDGER` and added `rule.settlement_delay_ledger > MAX_SETTLEMENT_DELAY_LEDGER` validation check in `read_governance_fee_rule`.
- **`settlement_contract/src/tests/admin_tests.rs`**: Implemented `MockGovernanceWithFee` and added the `governance_derived_rule_conversion_applies_delay_cap` unit test verifying delay cap enforcement for governance-derived rule resolution.
---
### Any trade-offs or considerations
No trade-offs. The validation ensures uniform constraint enforcement across all settlement rule resolution paths without breaking existing governance integrations.

### Testing steps (how to verify the fix)
1. Run `cargo test --workspace` to execute all contract unit tests across the workspace.
2. Verify `governance_derived_rule_conversion_applies_delay_cap` passes.
---
_Please kindly review this task. If there are any corrections, improvements, adjustments, or merge conflicts that you notice regarding my implementation, I'd really appreciate your feedback. I'd also love to hear your overall review of my work on this branch.Thank you!_

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.

1 participant