-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathconfig.rs
More file actions
144 lines (139 loc) · 8.1 KB
/
Copy pathconfig.rs
File metadata and controls
144 lines (139 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use near_sdk::near;
// --- Timeouts & Deadlines ---
/// Default for `key_event_timeout_blocks`.
const DEFAULT_KEY_EVENT_TIMEOUT_BLOCKS: u64 = 30;
/// Maximum time after which TEE MPC nodes must be upgraded to the latest version
const DEFAULT_TEE_UPGRADE_DEADLINE_DURATION_SECONDS: u64 = 7 * 24 * 60 * 60; // 7 Days
// --- Gas Defaults (in TeraGas) ---
/// Amount of gas to deposit when creating an internal upgrade transaction promise.
/// Note this deposit must be less than 300, as the total gas usage including the
/// initial call itself to vote for the update can not exceed 300 Tgas.
const DEFAULT_CONTRACT_UPGRADE_DEPOSIT_TERA_GAS: u64 = 50;
/// Gas required for a sign request
const DEFAULT_SIGN_CALL_GAS_ATTACHMENT_REQUIREMENT_TERA_GAS: u64 = 15;
/// Gas required for a CKD request
const DEFAULT_CKD_CALL_GAS_ATTACHMENT_REQUIREMENT_TERA_GAS: u64 = 15;
/// Prepaid gas for a `return_signature_and_clean_state_on_success` call
const DEFAULT_RETURN_SIGNATURE_AND_CLEAN_STATE_ON_SUCCESS_CALL_TERA_GAS: u64 = 7;
/// Prepaid gas for a `return_ck_and_clean_state_on_success` call
const DEFAULT_RETURN_CK_AND_CLEAN_STATE_ON_SUCCESS_CALL_TERA_GAS: u64 = 7;
/// Prepaid gas for a `fail_on_timeout` call
const DEFAULT_FAIL_ON_TIMEOUT_TERA_GAS: u64 = 2;
/// Prepaid gas for a `fail_attestation_submission` call
const DEFAULT_FAIL_ATTESTATION_SUBMISSION_TERA_GAS: u64 = 2;
/// Fee, in milliNEAR, for one attestation-storage grant. Covers the worst-case
/// stored entry plus the grant-counter row it creates, with headroom for layout
/// growth; see `docs/design/operator-prepaid-attestation-storage.md`.
const DEFAULT_ATTESTATION_STORAGE_FEE_MILLINEAR: u64 = 20;
/// Prepaid gas for a `clean_tee_status` call
const DEFAULT_CLEAN_TEE_STATUS_TERA_GAS: u64 = 10;
/// Prepaid gas for the reshare-time `clean_invalid_attestations` promise.
const DEFAULT_CLEAN_INVALID_ATTESTATIONS_TERA_GAS: u64 = 10;
/// Prepaid gas for a `cleanup_orphaned_node_migrations` call
/// TODO(#1164): benchmark
const DEFAULT_CLEANUP_ORPHANED_NODE_MIGRATIONS_TERA_GAS: u64 = 4;
/// Prepaid gas for a `remove_non_participant_update_votes` call
const DEFAULT_REMOVE_NON_PARTICIPANT_UPDATE_VOTES_TERA_GAS: u64 = 5;
/// Prepaid gas for a `clean_foreign_chain_data` call
const DEFAULT_CLEAN_FOREIGN_CHAIN_DATA_TERA_GAS: u64 = 5;
/// Prepaid gas for a `remove_non_participant_tee_verifier_votes` call
const DEFAULT_REMOVE_NON_PARTICIPANT_TEE_VERIFIER_VOTES_TERA_GAS: u64 = 5;
/// Gas attached to the cross-contract `verify_quote` call on the TEE verifier.
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.
pub(crate) const DEFAULT_LAUNCHER_HASH_UNUSED_TTL_SECONDS: u64 = 14 * 24 * 60 * 60; // 14 days
/// Config for V2 of the contract.
#[near(serializers=[borsh, json])]
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct Config {
/// If a key event attempt has not successfully completed within this many blocks,
/// it is considered failed.
pub(crate) key_event_timeout_blocks: u64,
/// The grace period duration for expiry of old mpc image hashes once a new one is added.
pub(crate) tee_upgrade_deadline_duration_seconds: u64,
/// Amount of gas to deposit for contract and config updates.
pub(crate) contract_upgrade_deposit_tera_gas: u64,
/// Gas required for a sign request.
pub(crate) sign_call_gas_attachment_requirement_tera_gas: u64,
/// Gas required for a CKD request.
pub(crate) ckd_call_gas_attachment_requirement_tera_gas: u64,
/// Prepaid gas for a `return_signature_and_clean_state_on_success` call.
pub(crate) return_signature_and_clean_state_on_success_call_tera_gas: u64,
/// Prepaid gas for a `return_ck_and_clean_state_on_success` call.
pub(crate) return_ck_and_clean_state_on_success_call_tera_gas: u64,
/// Prepaid gas for a `fail_on_timeout` call.
pub(crate) fail_on_timeout_tera_gas: u64,
/// Prepaid gas for a `fail_attestation_submission` call.
pub(crate) fail_attestation_submission_tera_gas: u64,
/// Prepaid gas for a `clean_tee_status` call.
pub(crate) clean_tee_status_tera_gas: u64,
/// Prepaid gas for the reshare-time `clean_invalid_attestations` promise.
pub(crate) clean_invalid_attestations_tera_gas: u64,
/// Prepaid gas for a `cleanup_orphaned_node_migrations` call.
pub(crate) cleanup_orphaned_node_migrations_tera_gas: u64,
/// Prepaid gas for a `remove_non_participant_update_votes` call.
pub(crate) remove_non_participant_update_votes_tera_gas: u64,
/// Prepaid gas for a `clean_foreign_chain_data` call.
pub(crate) clean_foreign_chain_data_tera_gas: u64,
/// Prepaid gas for a `remove_non_participant_tee_verifier_votes` call.
pub(crate) remove_non_participant_tee_verifier_votes_tera_gas: u64,
/// Gas attached to the cross-contract `verify_quote` call on the verifier.
pub(crate) verifier_tera_gas: u64,
/// Prepaid gas for the `resolve_verification` callback.
pub(crate) resolve_verification_tera_gas: u64,
/// Fee, in milliNEAR, charged for one attestation-storage grant.
pub(crate) attestation_storage_fee_millinear: u64,
/// TTL after which a launcher image hash unused by any participant is evicted.
/// Applied when an entry's expiry is next stamped (vote-in, re-vote, or a refresh on
/// use), not retroactively — changing it does not re-date existing entries.
pub(crate) launcher_hash_unused_ttl_seconds: u64,
}
impl Default for Config {
fn default() -> Self {
Self {
key_event_timeout_blocks: DEFAULT_KEY_EVENT_TIMEOUT_BLOCKS,
tee_upgrade_deadline_duration_seconds: DEFAULT_TEE_UPGRADE_DEADLINE_DURATION_SECONDS,
contract_upgrade_deposit_tera_gas: DEFAULT_CONTRACT_UPGRADE_DEPOSIT_TERA_GAS,
sign_call_gas_attachment_requirement_tera_gas:
DEFAULT_SIGN_CALL_GAS_ATTACHMENT_REQUIREMENT_TERA_GAS,
ckd_call_gas_attachment_requirement_tera_gas:
DEFAULT_CKD_CALL_GAS_ATTACHMENT_REQUIREMENT_TERA_GAS,
return_signature_and_clean_state_on_success_call_tera_gas:
DEFAULT_RETURN_SIGNATURE_AND_CLEAN_STATE_ON_SUCCESS_CALL_TERA_GAS,
return_ck_and_clean_state_on_success_call_tera_gas:
DEFAULT_RETURN_CK_AND_CLEAN_STATE_ON_SUCCESS_CALL_TERA_GAS,
fail_on_timeout_tera_gas: DEFAULT_FAIL_ON_TIMEOUT_TERA_GAS,
fail_attestation_submission_tera_gas: DEFAULT_FAIL_ATTESTATION_SUBMISSION_TERA_GAS,
clean_tee_status_tera_gas: DEFAULT_CLEAN_TEE_STATUS_TERA_GAS,
clean_invalid_attestations_tera_gas: DEFAULT_CLEAN_INVALID_ATTESTATIONS_TERA_GAS,
cleanup_orphaned_node_migrations_tera_gas:
DEFAULT_CLEANUP_ORPHANED_NODE_MIGRATIONS_TERA_GAS,
remove_non_participant_update_votes_tera_gas:
DEFAULT_REMOVE_NON_PARTICIPANT_UPDATE_VOTES_TERA_GAS,
clean_foreign_chain_data_tera_gas: DEFAULT_CLEAN_FOREIGN_CHAIN_DATA_TERA_GAS,
remove_non_participant_tee_verifier_votes_tera_gas:
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,
attestation_storage_fee_millinear: DEFAULT_ATTESTATION_STORAGE_FEE_MILLINEAR,
launcher_hash_unused_ttl_seconds: DEFAULT_LAUNCHER_HASH_UNUSED_TTL_SECONDS,
}
}
}
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.
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(())
}
}