Skip to content

Feat: invoice prioritization, creator fee tiers, invoice metadata & confidential payment tracking (#918, #919, #920, #921) - #984

Open
kossyomma-beep wants to merge 4 commits into
Stellar-split:mainfrom
kossyomma-beep:feat/918-919-920-921-priority-fee-tiers-metadata-confidential
Open

kossyomma-beep wants to merge 4 commits into
Stellar-split:mainfrom
kossyomma-beep:feat/918-919-920-921-priority-fee-tiers-metadata-confidential

Conversation

@kossyomma-beep

Copy link
Copy Markdown

Summary

Adds four new contract features, each in its own module under contracts/split/src/ with a separate #[contractimpl] block. Changes to lib.rs are
limited to module registration, and new events are added to events.rs.

#918 — Invoice prioritization (priority.rs)

  • PriorityTier (Low / Normal / High / Critical) derived from a 0–1000 score, with resource-allocation weights (1/2/4/8)
  • InvoicePriority record per invoice; per-tier queues kept sorted by score (desc), then invoice id (asc)
  • Validation: score range, open invoice status, creator/co-creator or admin auth; Critical tier is admin-only
  • Entry points: set_invoice_priority, clear_invoice_priority, get_invoice_priority, sort_invoices_by_priority, get_next_priority_invoice,
    get_priority_queue, prune_priority_queue, tier lookup/weight helpers

#919 — Fee tier system for creators (creator_fee_tiers.rs)

  • Versioned CreatorFeeTierConfig of up to 10 CreatorFeeTiers (zero-based start, ascending thresholds, non-increasing fees, 10% cap)
  • Binary-search tier lookup on the creator's existing lifetime volume
  • calc_creator_fee returns gross / fee / net at the tier rate; falls back to the platform fee when no tiers are configured
  • Tier tracking via sync_creator_fee_tier (emits an event on tier change); single-tier rate updates and clearing

#920 — Invoice metadata storage (invoice_metadata.rs)

  • MetadataEntry key-value store per invoice with per-key versioning, author and timestamp
  • Validation: keys 1–32 chars [a-z0-9_.-], values ≤ 256 bytes, ≤ 20 entries per invoice; creator/co-creator writes only
  • Per-key storage plus an index, so single-key reads/writes touch one ledger entry
  • Set / batch set / remove / clear / permanent lock; get, get entry, has, list keys, get all

#921 — Confidential payment tracking (confidential_tracking.rs)

  • Amounts are masked as Pedersen commitments over BLS12-381 G1 (reusing the contract's pinned generators); no plaintext amount is stored or emitted
  • Zero-knowledge proof of knowledge of the opening (Fiat–Shamir Schnorr/Okamoto), bound to invoice and payer to prevent replay
  • Homomorphic aggregate commitment lets the creator prove the invoice total without revealing individual amounts
  • Encrypted amounts stored as bounded opaque ciphertext with a SHA-256 integrity digest
  • Hash-chained per-invoice audit trail with full-chain verification
  • Queries: record / opening re-verification, summary, payer list, paged audit trail

Events

pri_set, pri_clr, cfee_cfg, cfee_chg, meta_set, meta_del, meta_lck, ctrk_rec, ctrk_ver

Tests

Unit tests are included in each new module (tier boundaries, sorting, tier lookup and validation, metadata validation, ZK proof verification and tamper
detection, homomorphic aggregation, audit chain integrity).

Notes

Closes #918
Closes #919
Closes #920
Closes #921

- Add PriorityTier (Low/Normal/High/Critical) derived from a 0-1000 score
- Add InvoicePriority record with per-invoice storage
- Keep per-tier queues sorted by score desc, then invoice id asc
- Validate score range, invoice status and caller authorization
  (Critical tier restricted to admins)
- Add sort_invoices_by_priority, get_next_priority_invoice,
  get_priority_queue, prune_priority_queue and tier weight lookup
- Emit pri_set / pri_clr events
- Add CreatorFeeTier table with versioned CreatorFeeTierConfig
- Validate tiers: zero-based start, ascending volume thresholds,
  non-increasing fee rates, bounded tier count and max fee
- Binary-search tier lookup on lifetime creator volume
- Add calc_creator_fee quote (gross, fee, net) at the tier rate
- Track creator tier changes via sync_creator_fee_tier
- Allow single-tier rate updates and clearing the table
- Emit cfee_cfg / cfee_chg events
- Add MetadataEntry with per-key versioning, author and timestamp
- Store each entry under its own key with an insertion-ordered index
- Validate key charset/length, value size and per-invoice entry limit
- Restrict writes to creator/co-creators on non-cancelled invoices
- Add single and batch set, remove, clear and permanent lock
- Add get, get entry, has, list keys and get-all access methods
- Emit meta_set / meta_del / meta_lck events
- Add ConfidentialRecord storing only a Pedersen commitment over
  BLS12-381 G1, never the plaintext amount
- Verify a Fiat-Shamir proof of knowledge of the commitment opening,
  bound to invoice id and payer to prevent replay
- Maintain a homomorphic aggregate commitment so the creator can prove
  the invoice total without revealing individual amounts
- Store encrypted amounts as bounded opaque ciphertext with a SHA-256
  integrity digest
- Add a per-invoice hash-chained audit trail with chain verification
- Add record/opening re-verification, summary, payer list and paged
  audit trail queries
- Emit ctrk_rec / ctrk_ver events without amount data
@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@kossyomma-beep 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

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.

Implement confidential payment tracking Add invoice metadata storage Implement fee tier system for creators Add invoice prioritization

1 participant