Skip to content

Commit 270aaf8

Browse files
committed
fix: address copilot review on v1 digest encoding and v2 fallback
- pin v1 digest event_type encoding to little-endian (to_le_bytes) so the on-wire format is platform-independent. x86 (dstack's only target) produces identical bytes, so existing RTMR3 values and verifiers are unaffected. the 2024 spec called out to_ne_bytes explicitly, but a stable wire format should not depend on the host platform. - fix the EventLogVersion::V2 doc comment in dstack-types: it listed event_type 134217730 (0x08000002), but v1 and v2 share the same event_type 134217729 (0x08000001). the version is distinguished by the EventLogVersion field / json version key, not event_type. - replace canonical_event_json_v2's .unwrap_or_default() with .or_panic(). silently returning "" on serialization failure would produce sha384("") as the digest, which is both wrong and hard to debug. the input is a well-formed json!{} literal so serialization cannot actually fail; or_panic makes that invariant explicit without tripping the expect_used clippy lint.
1 parent 374f3d3 commit 270aaf8

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

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.

cc-eventlog/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dstack-types.workspace = true
1717
ez-hash.workspace = true
1818
fs-err.workspace = true
1919
hex.workspace = true
20+
or-panic.workspace = true
2021
scale.workspace = true
2122
serde.workspace = true
2223
serde-human-bytes.workspace = true

cc-eventlog/src/runtime_events.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use anyhow::{Context, Result};
66
use dstack_types::EventLogVersion;
77
use fs_err as fs;
8+
use or_panic::ResultOrPanic;
89
use scale::{Decode, Encode};
910
use serde::{Deserialize, Serialize};
1011
use serde_human_bytes::base64;
@@ -128,7 +129,7 @@ impl RuntimeEvent {
128129
match self.version {
129130
EventLogVersion::V1 => {
130131
let mut buf = Vec::with_capacity(4 + 1 + self.event.len() + 1 + self.payload.len());
131-
buf.extend_from_slice(&DSTACK_RUNTIME_EVENT_TYPE.to_ne_bytes());
132+
buf.extend_from_slice(&DSTACK_RUNTIME_EVENT_TYPE.to_le_bytes());
132133
buf.push(b':');
133134
buf.extend_from_slice(self.event.as_bytes());
134135
buf.push(b':');
@@ -158,7 +159,7 @@ pub fn canonical_event_json_v2(event: &str, payload: &[u8]) -> String {
158159
"payload": hex::encode(payload),
159160
"version": 2,
160161
});
161-
serde_jcs::to_string(&obj).unwrap_or_default()
162+
serde_jcs::to_string(&obj).or_panic("canonical JSON serialization failed")
162163
}
163164

164165
/// Replay event logs
@@ -188,7 +189,7 @@ mod tests {
188189
);
189190
let digest = event.digest::<Sha384>();
190191
let expected = Sha384::hash([
191-
&DSTACK_RUNTIME_EVENT_TYPE.to_ne_bytes()[..],
192+
&DSTACK_RUNTIME_EVENT_TYPE.to_le_bytes()[..],
192193
b":",
193194
b"app-id",
194195
b":",

dstack-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum EventLogVersion {
1919
#[default]
2020
V1,
2121
/// JSON canonical digest (JCS RFC 8785):
22-
/// `SHA({"event":"...","event_type":134217730,"payload":"hex..."})`
22+
/// `SHA({"event":"...","event_type":134217729,"payload":"hex...","version":2})`
2323
V2,
2424
}
2525

0 commit comments

Comments
 (0)