-
Notifications
You must be signed in to change notification settings - Fork 37
feat(contract): auto-expire unused launcher image hashes #3564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 26 commits
99f6904
d7c0c65
a8694aa
cb955fb
074a701
c435dc5
9759f11
d329413
13fbc1f
6e3039e
096dfb1
d725003
e80673a
07de77b
2aa024e
c95e32d
e1d8955
04254ac
37c0218
eb593e5
df57fd8
4485904
3fc93c7
883dfad
797407a
6ffd125
1748925
02a05c3
503a627
9cf1bd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,10 @@ const DEFAULT_VERIFIER_TERA_GAS: u64 = 200; | |
| /// Prepaid gas for the `resolve_verification` callback. Carries the bulk of the | ||
| /// post-DCAP work (allowlist match, RTMR3 replay, app-compose validation, store). | ||
| const DEFAULT_RESOLVE_VERIFICATION_TERA_GAS: u64 = 60; | ||
| /// Default TTL after which a launcher image hash unused by any participant is evicted. | ||
| const DEFAULT_LAUNCHER_HASH_UNUSED_TTL_SECONDS: u64 = 14 * 24 * 60 * 60; // 14 days | ||
| /// Prepaid gas for a `clean_expired_launcher_hashes` call. | ||
| const DEFAULT_CLEAN_EXPIRED_LAUNCHER_HASHES_TERA_GAS: u64 = 5; | ||
|
|
||
| /// Config for V2 of the contract. | ||
| #[near(serializers=[borsh, json])] | ||
|
|
@@ -81,6 +85,10 @@ pub(crate) struct Config { | |
| pub(crate) verifier_tera_gas: u64, | ||
| /// Prepaid gas for the `resolve_verification` callback. | ||
| pub(crate) resolve_verification_tera_gas: u64, | ||
| /// TTL after which a launcher image hash unused by any participant is evicted. | ||
| pub(crate) launcher_hash_unused_ttl_seconds: u64, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no test covering enlarging the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point — added |
||
| /// Prepaid gas for a `clean_expired_launcher_hashes` call. | ||
| pub(crate) clean_expired_launcher_hashes_tera_gas: u64, | ||
| } | ||
|
|
||
| impl Default for Config { | ||
|
|
@@ -110,6 +118,23 @@ impl Default for Config { | |
| DEFAULT_REMOVE_NON_PARTICIPANT_TEE_VERIFIER_VOTES_TERA_GAS, | ||
| verifier_tera_gas: DEFAULT_VERIFIER_TERA_GAS, | ||
| resolve_verification_tera_gas: DEFAULT_RESOLVE_VERIFICATION_TERA_GAS, | ||
| launcher_hash_unused_ttl_seconds: DEFAULT_LAUNCHER_HASH_UNUSED_TTL_SECONDS, | ||
| clean_expired_launcher_hashes_tera_gas: DEFAULT_CLEAN_EXPIRED_LAUNCHER_HASHES_TERA_GAS, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Config { | ||
| /// Invariant: a launcher hash backing a still-valid attestation must never expire, | ||
| /// so its unused-TTL must be at least the attestation validity window. | ||
|
SimonRastikian marked this conversation as resolved.
|
||
| pub(crate) fn validate(&self) -> Result<(), &'static str> { | ||
| if self.launcher_hash_unused_ttl_seconds | ||
| < mpc_attestation::attestation::DEFAULT_EXPIRATION_DURATION_SECONDS | ||
| { | ||
| return Err( | ||
| "launcher_hash_unused_ttl_seconds must be >= DEFAULT_EXPIRATION_DURATION_SECONDS", | ||
| ); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
5TGas: this is the budget for the detached,#[private]clean_expired_launcher_hashesself-call spawned fromverify_tee(physical eviction of launcher hashes past their TTL).Measured via a sandbox (near-workspaces) benchmark: the call burns ~3.0 TGas (function-call receipt) / ~3.35 TGas total on a small allowlist. The cost is dominated by contract state load/store + the base function-call charge, not the launcher count (the eviction loop over a handful of operator-curated entries is negligible), so it stays flat as the allowlist changes. That leaves ~40% headroom under 5 TGas.
It's also consistent with the sibling detached-cleanup budgets that do comparable small work (
clean_foreign_chain_data,remove_non_participant_*are all 5), and it's fail-safe: the call is detached, so a shortfall can't failverify_tee, and expiry is already enforced at read time — physical eviction is just GC that retries next round. Tunable viaConfigif a benchmark on production-sized state ever warrants it.