stellar-contracts: TTL policy, access-grant index invariants, canonical medical-record hashing, event timestamp validation - #1270
Merged
Conversation
Persistent-storage entries (access/emergency/audit logs, activity streaks, breeding records and their indexes) were never having their TTL extended, so they could be archived/expire out from under the contract even while still logically active. Add a bump_persistent_ttl helper backed by PERSISTENT_TTL_THRESHOLD/PERSISTENT_TTL_EXTEND_TO policy constants and call it after every persistent().set() (and on reads of the access-log record) in the affected modules, plus tests asserting a freshly written persistent entry's TTL is actually extended to the policy's target. Refs DogStark#1154
Grant, revoke, and cleanup (compact_storage) maintain three related keys per pet: AccessGrant, AccessGrantCount, and AccessGrantIndex. Add tests proving the index stays unique/reachable and consistent with the count across multiple grants and a re-grant, that a revoked or expired grant can never authorize access via check_access even before compaction runs, and that compact_storage fully removes stale grant records and index slots while leaving the remaining index contiguous and active grantees authorized. Refs DogStark#1158
Add PetChainContract::get_medical_record_hash / the underlying
canonical_medical_record_preimage encoder, giving off-chain clients a
deterministic, versioned commitment ("petchain:medical-record:v1")
over a record's clinical fields (pet_id, vet_address, diagnosis,
treatment, medications, notes, date) using the fixed field order and
XDR encoding documented on the function. Storage/audit metadata
(id, updated_at, attachment_hashes, deleted_at) is intentionally
excluded so the commitment is stable across non-clinical mutations
like a soft-delete. Tests cover determinism, sensitivity to clinical
content changes, and stability across delete_medical_record.
Refs DogStark#1169
add_vaccination previously accepted an arbitrary caller-supplied administered_at/next_due_date/expires_at with no validation, letting a nonsensical or maliciously far-future timestamp corrupt reminder scheduling and medical history ordering. Reject administered_at that is further in the future than MAX_EVENT_FUTURE_SKEW relative to ledger time, and reject a next_due_date/expires_at (when set) that precedes administered_at or sits beyond MAX_EVENT_HORIZON past it, via the new InvalidTimestamp error. The skew/horizon windows are deliberately generous (decades) so legitimate historical records and existing synthetic test timestamps are unaffected; only clearly corrupt/out-of-domain values are rejected. Tests cover the accepted boundary, the first rejected value past it, and the ordering checks. Refs DogStark#1174
|
@laddyr141-ui 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.
Title
stellar-contracts: TTL policy, access-grant index invariants, canonical medical-record hashing, event timestamp validation
Body
This PR addresses four narrowly-scoped
[stellar-contracts]issues instellar-contracts/src/lib.rs, each as its own commit.Add TTL extension policy for persistent storage (#1154) — Persistent-storage entries (access logs, emergency access/audit logs, activity streaks, breeding records and their indexes) were written via
persistent().set()but never had their TTL extended, so they could be archived/expire out from under the contract even while still logically active. Adds abump_persistent_ttlhelper driven by newPERSISTENT_TTL_THRESHOLD/PERSISTENT_TTL_EXTEND_TOpolicy constants (~30/~60 days), called after every persistent write (and on the access-log read path) in the affected modules. Tests assert a freshly written breeding record's TTL is actually extended to the policy target.Add invariant tests for access-grant indexes (#1158) —
grant_access/revoke_access/compact_storagemaintainAccessGrant,AccessGrantCount, andAccessGrantIndextogether. Adds tests proving the index stays unique/reachable and consistent with the count across multiple grants and a re-grant, that a revoked or expired grant can never authorize access viacheck_access(even before compaction runs), and thatcompact_storagefully removes stale grant records/index slots while leaving the remaining index contiguous and active grantees still authorized.Define canonical medical-record hashing (#1169) — Adds
get_medical_record_hash(and the underlyingcanonical_medical_record_preimageencoder) so off-chain clients can reproduce a deterministic, versioned commitment (petchain:medical-record:v1) over a record's clinical fields —pet_id,vet_address,diagnosis,treatment,medications,notes,date— in a fixed field order using XDR encoding, documented on the function. Storage/audit metadata (id,updated_at,attachment_hashes,deleted_at) is intentionally excluded so the commitment is stable across non-clinical mutations. Tests cover determinism, sensitivity to clinical-content changes, and stability acrossdelete_medical_record.Validate medical event timestamps against ledger time (#1174) —
add_vaccinationpreviously accepted an arbitrary caller-suppliedadministered_at/next_due_date/expires_atwith no validation. Adds a newInvalidTimestamperror and rejectsadministered_atmore thanMAX_EVENT_FUTURE_SKEW(~100 years) past ledger time, plus anext_due_date/expires_at(when set) that precedesadministered_ator sits beyondMAX_EVENT_HORIZON(~50 years) past it. The windows are deliberately generous so legitimate historical records and existing synthetic test timestamps are unaffected — only clearly out-of-domain values are rejected. Tests cover the accepted boundary, the first rejected value past it, and the ordering checks.Notes
InvalidTimestampvariant was added).cargo fmt/clippy/cargo testwere not run in this environment — code was written carefully by hand to match existing conventions in the file, but has not been compiled locally.add_vaccination's inputs against ledger time to prevent corrupted reminder/history ordering; it does not change authorization. The access-grant tests ([stellar-contracts] Add invariant tests for access-grant indexes #1158) confirm revoked/expired grants cannot authorize access, closing a potential stale-authorization gap between revocation and the nextcompact_storagecall. The TTL policy ([stellar-contracts] Add TTL extension policy for persistent storage #1154) only affects storage archival timing, not authorization or fund handling. The hashing scheme ([stellar-contracts] Define canonical medical-record hashing #1169) is a read-only commitment derived from already-stored fields; it introduces no new write path.Closes #1154
Closes #1158
Closes #1169
Closes #1174