Skip to content

Commit 8cfbe11

Browse files
committed
init
1 parent c18e3ec commit 8cfbe11

22 files changed

Lines changed: 669 additions & 157 deletions

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/contract/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,19 +2086,18 @@ impl MpcContract {
20862086
self.metrics.clone()
20872087
}
20882088

2089-
/// Returns all allowed code hashes in order from most recent to least recent allowed code hashes. The first element is the most recent allowed code hash.
2090-
pub fn allowed_docker_image_hashes(&self) -> Vec<NodeImageHash> {
2089+
/// Returns all allowed code hashes in descending order of their expiry
2090+
/// date. Note that the expiration depends on the contract configuration
2091+
/// (c.f. [`Config::tee_upgrade_deadline_duration_seconds`]).
2092+
pub fn allowed_docker_image_hashes(&self) -> Vec<dtos::AllowedMpcDockerImageHash> {
20912093
let tee_upgrade_deadline_duration =
20922094
Duration::from_secs(self.config.tee_upgrade_deadline_duration_seconds);
20932095

2094-
let mut hashes: Vec<NodeImageHash> = self
2096+
let mut entries = self
20952097
.tee_state
2096-
.get_allowed_mpc_docker_images(tee_upgrade_deadline_duration)
2097-
.into_iter()
2098-
.map(|allowed_image_hash| allowed_image_hash.image_hash)
2099-
.collect();
2100-
hashes.reverse();
2101-
hashes
2098+
.get_allowed_mpc_docker_images(tee_upgrade_deadline_duration);
2099+
entries.reverse();
2100+
entries
21022101
}
21032102

21042103
pub fn allowed_launcher_compose_hashes(&self) -> Vec<LauncherDockerComposeHash> {
@@ -6516,7 +6515,7 @@ mod tests {
65166515
/// 1. Add M1, add L1 → compose: {L1,M1}
65176516
/// 2. Add M2 → compose: {L1,M1}, {L1,M2}
65186517
/// 3. Advance time past M2's deadline so M1 is fully expired
6519-
/// (valid_entries keeps the last expired entry as cutoff, so M1 only
6518+
/// (allowed_images keeps the last expired entry as cutoff, so M1 only
65206519
/// drops when M2's grace period also passes)
65216520
/// 4. Stored compose hashes persist — still {L1,M1}, {L1,M2}
65226521
/// 5. Add L2 → paired only with valid M2, not expired M1

crates/contract/src/primitives/time.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::time::Duration;
22

3+
use near_sdk::env;
4+
35
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
46
pub(crate) struct Timestamp {
57
duration_since_unix_epoch: Duration,
@@ -22,6 +24,17 @@ impl Timestamp {
2224
duration_since_unix_epoch: new_time_stamp,
2325
})
2426
}
27+
28+
pub(crate) fn add_or_panic(self, duration: Duration) -> Self {
29+
let Some(res) = self.checked_add(duration) else {
30+
env::panic_str("overflowed adding duration to timestamp")
31+
};
32+
res
33+
}
34+
35+
pub(crate) fn as_secs(self) -> u64 {
36+
self.duration_since_unix_epoch.as_secs()
37+
}
2538
}
2639

2740
impl borsh::BorshSerialize for Timestamp {

crates/contract/src/snapshots/mpc_contract__tests__mpc_contract_borsh_schema_has_not_changed.snap

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ BorshSchemaContainer {
6868
],
6969
),
7070
},
71-
"AllowedDockerImageHashes": Struct {
72-
fields: NamedFields(
73-
[
74-
(
75-
"allowed_tee_proposals",
76-
"Vec<AllowedMpcDockerImage>",
77-
),
78-
],
79-
),
80-
},
8171
"AllowedLauncherImage": Struct {
8272
fields: NamedFields(
8373
[
@@ -112,20 +102,6 @@ BorshSchemaContainer {
112102
],
113103
),
114104
},
115-
"AllowedMpcDockerImage": Struct {
116-
fields: NamedFields(
117-
[
118-
(
119-
"image_hash",
120-
"DockerImageHash",
121-
),
122-
(
123-
"added",
124-
"Timestamp",
125-
),
126-
],
127-
),
128-
},
129105
"AttemptId": Struct {
130106
fields: UnnamedFields(
131107
[
@@ -1130,6 +1106,16 @@ BorshSchemaContainer {
11301106
],
11311107
),
11321108
},
1109+
"StoredDockerImageHashes": Struct {
1110+
fields: NamedFields(
1111+
[
1112+
(
1113+
"allowed_tee_proposals",
1114+
"Vec<WhitelistedMpcDockerImageHash>",
1115+
),
1116+
],
1117+
),
1118+
},
11331119
"String": Sequence {
11341120
length_width: 4,
11351121
length_range: 0..=4294967295,
@@ -1150,7 +1136,7 @@ BorshSchemaContainer {
11501136
[
11511137
(
11521138
"allowed_docker_image_hashes",
1153-
"AllowedDockerImageHashes",
1139+
"StoredDockerImageHashes",
11541140
),
11551141
(
11561142
"allowed_launcher_images",
@@ -1244,11 +1230,6 @@ BorshSchemaContainer {
12441230
length_range: 0..=4294967295,
12451231
elements: "AllowedLauncherImage",
12461232
},
1247-
"Vec<AllowedMpcDockerImage>": Sequence {
1248-
length_width: 4,
1249-
length_range: 0..=4294967295,
1250-
elements: "AllowedMpcDockerImage",
1251-
},
12521233
"Vec<ContractExpectedMeasurements>": Sequence {
12531234
length_width: 4,
12541235
length_range: 0..=4294967295,
@@ -1269,6 +1250,11 @@ BorshSchemaContainer {
12691250
length_range: 0..=4294967295,
12701251
elements: "LauncherDockerComposeHash",
12711252
},
1253+
"Vec<WhitelistedMpcDockerImageHash>": Sequence {
1254+
length_width: 4,
1255+
length_range: 0..=4294967295,
1256+
elements: "WhitelistedMpcDockerImageHash",
1257+
},
12721258
"Vec<u8>": Sequence {
12731259
length_width: 4,
12741260
length_range: 0..=4294967295,
@@ -1302,6 +1288,20 @@ BorshSchemaContainer {
13021288
],
13031289
),
13041290
},
1291+
"WhitelistedMpcDockerImageHash": Struct {
1292+
fields: NamedFields(
1293+
[
1294+
(
1295+
"image_hash",
1296+
"DockerImageHash",
1297+
),
1298+
(
1299+
"added",
1300+
"Timestamp",
1301+
),
1302+
],
1303+
),
1304+
},
13051305
"[u8; 32]": Sequence {
13061306
length_width: 0,
13071307
length_range: 32..=32,

0 commit comments

Comments
 (0)