feat: Protocol 25/26 — checked arithmetic, TTL extension, invoice fingerprint#30
Merged
Conversation
…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
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
Integrates three Stellar protocol upgrades into the Sharpy contract.
Protocol 26 — CAP-82: Checked 256-bit Arithmetic
Replaces all
as u128casts in split calculations withchecked_mul/checked_div/checked_subchains. Prevents silent overflow on large invoices and makes arithmetic failures explicit with descriptive panic messages.Affected paths:
_release()— Percentage, Tiered, and proportional split calculationsget_invoice_stats()— completion_bps calculationProtocol 26 — CAP-78: Limited TTL Extension
Documents the
extend_ttlpattern insave_invoiceper CAP-78 semantics (only bumps if current TTL < min_ttl). Adds a publicbump_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