Skip to content

Harden share-token TTL and archival runbook#445

Draft
carrion256 wants to merge 2 commits into
audit/share-token-admin-immutablefrom
audit/share-token-ttl-and-archival
Draft

Harden share-token TTL and archival runbook#445
carrion256 wants to merge 2 commits into
audit/share-token-admin-immutablefrom
audit/share-token-ttl-and-archival

Conversation

@carrion256

@carrion256 carrion256 commented May 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes/triages the share-token TTL and archival follow-up findings:

  • A-096 / Nexus 1423b989-f1cf-4827-bc37-6d76d00018f8 — document the Soroban archival restore story for the share token.
  • A-098 / Nexus 8e84564c-0b32-40b9-8bc8-227b2ca23395 — refresh instance TTL from all SEP-41 read-only methods.
  • A-100 / Nexus 1122e421-af18-43d0-9062-bb44dbe948cc — document/prove why admin extend_ttl remains instance-only while holder balances/allowances keep per-entry semantics.

This is stacked on the consolidated share-token PR branch audit/share-token-admin-immutable.

Changes

  • Add extend_instance_ttl(e) to SEP-41 read-only methods: total_supply, balance, allowance, decimals, name, symbol.
  • Add README runbook language for proactive share-token TTL maintenance and archived-instance recovery: restore via Stellar/Soroban archival restore first, then call extend_ttl from the configured admin.
  • Record A-100 as an intentional design boundary rather than adding an unbounded holder/allowance index:
    • upstream stellar-tokens refreshes touched persistent holder balances on balance reads/writes;
    • allowances are temporary storage entries bounded by the caller-selected live_until_ledger.
  • Add regression coverage for the read-only TTL surface and the admin extend_ttl balance/allowance semantics.

Verification

  • RUSTUP_TOOLCHAIN=1.89.0 cargo fmt --all --check
  • RUSTUP_TOOLCHAIN=1.89.0 CARGO_TARGET_DIR=/data/tmp/contracts-share-token-ttl-archival/target cargo test -p templar-soroban-share-token read_only_entrypoints_cover_share_token_ttl_maintenance_surface -- --nocapture
  • RUSTUP_TOOLCHAIN=1.89.0 CARGO_TARGET_DIR=/data/tmp/contracts-share-token-ttl-archival/target cargo test -p templar-soroban-share-token admin_extend_ttl_preserves_holder_balances_and_allowance_expiry_semantics -- --nocapture
  • RUSTUP_TOOLCHAIN=1.89.0 CARGO_TARGET_DIR=/data/tmp/contracts-share-token-ttl-archival/target cargo test -p templar-soroban-share-token -- --nocapture — 22 passed
  • git diff --check
  • Post-commit Soroban size-budget-check — passed at 93961 bytes

Tracker

Updated local tracker rows and cluster notes:

  • contracts-audit-findings-index.md
  • contracts-audit-clusters/storage-versioning-ttl.audit.md
  • contracts-audit-clusters/share-token-admin.audit.md

This change is Reviewable

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7cec756e-d0d5-47d1-8350-9809fbdde64f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR introduces time-to-live (TTL) management for the Soroban share-token contract. Read-only token methods now extend the contract instance TTL before returning values. An admin-only extend_ttl entrypoint enables proactive TTL maintenance. Tests verify correct behavior and allowance expiry semantics.

Changes

Share-Token TTL Extension and Allowance Expiry

Layer / File(s) Summary
TTL and archival recovery documentation
contract/vault/soroban/README.md
New section explains how share-token instance TTL is refreshed across public entrypoints, the admin extend_ttl keeper path and archival restore prerequisite, and TTL behavior for per-holder balances (refreshed only when touched) and allowances (bounded by live_until_ledger, not extended by keeper).
TTL extension in read-only token methods
contract/vault/soroban/share-token/src/lib.rs
extend_instance_ttl(e) calls are inserted in total_supply, balance, allowance, decimals, name, and symbol methods before delegating to underlying Base implementations.
TTL and allowance expiry test coverage
contract/vault/soroban/share-token/src/tests.rs
Two new tests verify read-only token surfaces return correct values after minting and approving, and verify admin extend_ttl behavior preserves balances while respecting allowance expiry when ledger time advances.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • royalf00l
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Harden share-token TTL and archival runbook' directly reflects the main changes: adding TTL maintenance capabilities and archival recovery documentation for the share-token contract.
Description check ✅ Passed The description is comprehensive and clearly related to the changeset, detailing the audit findings addressed, specific code changes made, testing performed, and tracking updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch audit/share-token-ttl-and-archival

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • LINEAR integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands and usage tips.

@carrion256 carrion256 force-pushed the audit/share-token-admin-immutable branch from 3c5d098 to f8dedf6 Compare May 18, 2026 14:43
@carrion256 carrion256 force-pushed the audit/share-token-ttl-and-archival branch from e189e24 to 396f310 Compare May 18, 2026 14:43
@carrion256

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@carrion256

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contract/vault/soroban/share-token/src/tests.rs`:
- Around line 470-525: The test
read_only_entrypoints_cover_share_token_ttl_maintenance_surface currently only
asserts token values and must also verify TTL movement: read and store the
contract instance TTL for token before calling the read-only entrypoint(s) (use
env to query the instance TTL), invoke the read-only extend_instance_ttl
entrypoint via env.invoke_contract (Symbol::new(&env, "extend_instance_ttl") or
the specific read-only method you want to exercise), then read the instance TTL
again and assert it has advanced/been refreshed; update the test to perform this
before/after TTL assertion using the existing token variable and the test
function read_only_entrypoints_cover_share_token_ttl_maintenance_surface.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 44083f83-a1fa-4e04-b033-e728e8dbc679

📥 Commits

Reviewing files that changed from the base of the PR and between f8dedf6 and 396f310.

📒 Files selected for processing (3)
  • contract/vault/soroban/README.md
  • contract/vault/soroban/share-token/src/lib.rs
  • contract/vault/soroban/share-token/src/tests.rs

Comment on lines +470 to +525
#[test]
fn read_only_entrypoints_cover_share_token_ttl_maintenance_surface() {
let (env, _admin, vault, token) = setup();
let user = Address::generate(&env);
let spender = Address::generate(&env);

env.as_contract(&vault, || {
VaultCaller::mint(env.clone(), token.clone(), user.clone(), 1000);
VaultCaller::approve(
env.clone(),
token.clone(),
user.clone(),
spender.clone(),
250,
300,
);
});

let supply: i128 = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "total_supply"),
().into_val(&env),
);
let balance: i128 = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "balance"),
(&user,).into_val(&env),
);
let allowance: i128 = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "allowance"),
(&user, &spender).into_val(&env),
);
let name: String = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "name"),
().into_val(&env),
);
let symbol: String = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "symbol"),
().into_val(&env),
);
let decimals: u32 = env.invoke_contract(
&token,
&soroban_sdk::Symbol::new(&env, "decimals"),
().into_val(&env),
);

assert_eq!(supply, 1000);
assert_eq!(balance, 1000);
assert_eq!(allowance, 250);
assert_eq!(name, String::from_str(&env, "Templar Share"));
assert_eq!(symbol, String::from_str(&env, "tvSHARE"));
assert_eq!(decimals, 7);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

TTL regression test is value-only and does not prove TTL refresh.

On Line 471, this test name states TTL maintenance coverage, but it only asserts token values. It would still pass even if the read-only extend_instance_ttl calls were removed. Please add an assertion that verifies observable instance-TTL movement before/after at least one of these read-only calls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contract/vault/soroban/share-token/src/tests.rs` around lines 470 - 525, The
test read_only_entrypoints_cover_share_token_ttl_maintenance_surface currently
only asserts token values and must also verify TTL movement: read and store the
contract instance TTL for token before calling the read-only entrypoint(s) (use
env to query the instance TTL), invoke the read-only extend_instance_ttl
entrypoint via env.invoke_contract (Symbol::new(&env, "extend_instance_ttl") or
the specific read-only method you want to exercise), then read the instance TTL
again and assert it has advanced/been refreshed; update the test to perform this
before/after TTL assertion using the existing token variable and the test
function read_only_entrypoints_cover_share_token_ttl_maintenance_surface.

@carrion256 carrion256 force-pushed the audit/share-token-admin-immutable branch from 467fdf8 to 8470b7f Compare May 19, 2026 08:28
…xus 1423b989-f1cf-4827-bc37-6d76d00018f8 Nexus 8e84564c-0b32-40b9-8bc8-227b2ca23395 Nexus 1122e421-af18-43d0-9062-bb44dbe948cc)

Trace: e189e24
@carrion256 carrion256 force-pushed the audit/share-token-ttl-and-archival branch from 396f310 to 8b96576 Compare May 19, 2026 08:36
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