Repository navigation
Feat: security audit framework, partial payment tracking, velocity limits & split rules engine (#892, #911, #912, #913) - #985
Open
Barbie-Dev wants to merge 4 commits into
Conversation
- Add security_audit module with auditor registry, contract-level and invoice-level security checks, persisted audit reports with severity weighted risk scores, and a bounded security event log - Emit sec_adtr, sec_aud and sec_evt events - Expose admin/auditor entry points on SplitContract - Add tests covering audits, auditor permissions and log bounds
- Add payment_tracking module with per-recipient due/paid tracking - Add milestone state machine (Pending -> Reached -> Settled) with in-order settlement - Store per-recipient paid flags as a u64 bitmask alongside the tracker - Validate everything before writing so updates are atomic - Emit pt_init, pt_pay and pt_mile events - Add tests for tracking, milestones, paid flags and atomicity
- Add velocity module with VelocityConfig (max payments, max amount, window, cooldown) and per-payer VelocityState - Admin-configurable default limits with per-payer overrides - Enforce limits in the payment path; no-op when unconfigured - Handle edge cases: zero/negative amounts, overflow, window reset, invalid configs - Expose config, state, check and reset entry points with tests
- Add split_rules module with SplitRuleDef (recipient, priority, criteria, amount), RuleCriteria and RuleAmount types - Evaluate rules per recipient by priority against funded amount, payment count and timestamp, with Fixed, Percentage and Remainder amounts and overflow/over-allocation checks - Validate index range, duplicate priorities, amounts, thresholds, single remainder recipient and unconditional percentage sum - Persist rules per invoice with set/clear/get/evaluate/preview entry points and srules event - Add tests covering evaluation, validation and persistence
|
@Barbie-Dev 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements four features in the
splitcontract. Each one lives in its own module with events, contract entry points and tests, and each issue is aseparate commit.
#892: Contract security audit framework (
security_audit.rs)add_security_auditor,remove_security_auditor,get_security_auditors)total, split-rule and ratio lengths are consistent
run_security_audit,run_invoice_security_audit,get_security_audit,get_security_audit_count)log_security_event,get_security_events)sec_adtr,sec_aud,sec_evt#911: Partial invoice payment tracking (
payment_tracking.rs)PaymentTracker,RecipientPaymentState)Pending → Reached → Settled; milestones are reached automatically and settled strictly in orderu64bitmask (get_recipient_paid_flags,is_recipient_paid)init_payment_tracking,record_partial_payment,settle_payment_milestone,get_payment_trackerpt_init,pt_pay,pt_mile#912: Payment velocity limits (
velocity.rs)VelocityConfig: max payments per window, max amount per window, window length, cooldown between paymentsVelocityStatestored per payer; resets when the window elapsesset_velocity_config,set_payer_velocity_override)_pay); does nothing unless limits are configured, so existing behaviour is unchangedget_payer_velocity_config,get_payer_velocity_state,check_payer_velocity,reset_payer_velocityvel_cfg#913: Split rules engine (
split_rules.rs)SplitRuleDef: target recipient, priority, condition, amountRuleCriteria):Always,FundedAtLeast,FundedBelow,PayerCountAtLeast,AfterTimestamp,BeforeTimestampRuleAmount):Fixed,Percentage(bps),RemainderRemaindergets what is left; fails if the total would exceedthe funded amount
non-negative thresholds, at most one remainder recipient, unconditional percentages ≤ 100%
set_invoice_split_rules,clear_invoice_split_rules,get_invoice_split_rules,evaluate_invoice_split_rules,srulesTests
Unit and integration tests for every feature were added to
contracts/split/src/test.rs(test_892_*,test_911_*,test_912_*,test_913_*).Closes #892
Closes #911
Closes #912
Closes #913