Skip to content

feat: Protocol 25/26 — checked arithmetic, TTL extension, invoice fingerprint#30

Merged
MarcusDavidG merged 3 commits into
mainfrom
feat/p26-checked-arithmetic
Jul 15, 2026
Merged

feat: Protocol 25/26 — checked arithmetic, TTL extension, invoice fingerprint#30
MarcusDavidG merged 3 commits into
mainfrom
feat/p26-checked-arithmetic

Conversation

@MarcusDavidG

Copy link
Copy Markdown
Contributor

Summary

Integrates three Stellar protocol upgrades into the Sharpy contract.

Protocol 26 — CAP-82: Checked 256-bit Arithmetic

Replaces all as u128 casts in split calculations with checked_mul / checked_div / checked_sub chains. Prevents silent overflow on large invoices and makes arithmetic failures explicit with descriptive panic messages.

Affected paths:

  • _release() — Percentage, Tiered, and proportional split calculations
  • get_invoice_stats() — completion_bps calculation

Protocol 26 — CAP-78: Limited TTL Extension

Documents the extend_ttl pattern in save_invoice per CAP-78 semantics (only bumps if current TTL < min_ttl). Adds a public bump_invoice_ttl(invoice_id) function so anyone can prevent archival of long-lived or recurring invoices without re-saving.

Protocol 25 — CAP-75 / Crypto Host Functions

Adds get_invoice_fingerprint(invoice_id) -> BytesN<32> using the SHA-256 crypto host function. Returns a deterministic content hash committing to invoice_id, deadline, recipient count, and total amount. Useful for off-chain verification and tamper-evident receipts.

Tests

  • 24/24 passing
  • test_bump_invoice_ttl_succeeds
  • test_invoice_fingerprint_is_deterministic
  • test_invoice_stats_checked_arithmetic

…t calculations

Protocol 26 CAP-82 introduces checked 256-bit integer arithmetic host functions.
Apply the same safety principle to i128 split math:

- Percentage splits: funded.checked_mul(bps).checked_div(10_000)
- Tiered splits: same checked chain
- Proportional splits: amount.checked_mul(funded).checked_div(total)
- Remainder: funded.checked_sub(distributed)
- get_invoice_stats completion_bps: funded.checked_mul(10_000).checked_div(total)

Prevents silent overflow on large invoice amounts and makes arithmetic
failures explicit with descriptive panic messages.
…tegy

Protocol 26 CAP-78 introduces host functions for limited TTL extensions,
allowing contracts to extend their own storage lifetime efficiently.

- save_invoice now documents the CAP-78 approach (min/max TTL pattern)
- Add public bump_invoice_ttl(invoice_id) — anyone can call this to
  prevent archival of long-lived or recurring invoices
- Verifies invoice exists before bumping (prevents wasted fees on missing entries)
- Test: test_bump_invoice_ttl_succeeds
…tion

Protocol 25 (X-Ray) and Protocol 26 expose crypto host functions including
SHA-256 for deterministic content hashing.

- get_invoice_fingerprint(invoice_id) returns BytesN<32>
- Commits to: invoice_id, deadline, recipient_count, total_amount
- Deterministic — same invoice always produces same hash
- Tamper-evident — any change to invoice terms changes the hash
- Useful for off-chain verification, receipts, and audit trails
- Test: test_invoice_fingerprint_is_deterministic
@MarcusDavidG
MarcusDavidG merged commit 662dc1a into main Jul 15, 2026
1 check failed
@MarcusDavidG
MarcusDavidG deleted the feat/p26-checked-arithmetic branch July 15, 2026 03:05
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