Skip to content

Commit 5a7d188

Browse files
committed
refactor: rename v2 canonical JSON content field back to payload
Change the v2 canonical JSON from {"content":"<hex>","name":"...","type":134217729} to {"name":"...","payload":"<hex>","type":134217729} `payload` is the more common name in event/messaging protocols (CloudEvents, MQTT, JWT) and — unlike `data` — has no risk of being read as an OPA/Rego root-namespace reference. It also matches the existing `event_payload` field name in `TdxEvent`, so dstack-internal serde/scale shapes and the policy-facing canonical form now speak the same vocabulary. Note: JCS key ordering becomes name < payload < type. On-wire bytes (and therefore v2 digests) change — safe since v2 is not yet released.
1 parent 3e4b533 commit 5a7d188

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

cc-eventlog/src/runtime_events.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl RuntimeEvent {
113113
/// Compute the digest of the event.
114114
///
115115
/// - V1: `SHA(event_type_le || ":" || event_name || ":" || payload)`
116-
/// - V2: `SHA(canonical_json({"name":"...","type":134217729,"content":"hex..."}))`
116+
/// - V2: `SHA(canonical_json({"name":"...","type":134217729,"payload":"hex..."}))`
117117
pub fn digest<H: Hasher>(&self) -> H::Output {
118118
H::hash([self.hash_input().as_slice()])
119119
}
@@ -156,7 +156,7 @@ pub fn canonical_event_json_v2(event: &str, payload: &[u8]) -> String {
156156
let obj = serde_json::json!({
157157
"name": event,
158158
"type": DSTACK_RUNTIME_EVENT_TYPE,
159-
"content": hex::encode(payload),
159+
"payload": hex::encode(payload),
160160
});
161161
serde_jcs::to_string(&obj).or_panic("canonical JSON serialization failed")
162162
}
@@ -207,7 +207,7 @@ mod tests {
207207
let canonical = canonical_event_json_v2(&event.event, &event.payload);
208208
assert_eq!(
209209
canonical,
210-
r#"{"content":"abcd","name":"compose-hash","type":134217729}"#
210+
r#"{"name":"compose-hash","payload":"abcd","type":134217729}"#
211211
);
212212
let digest = event.digest::<Sha384>();
213213
let expected = Sha384::hash([canonical.as_bytes()]);
@@ -268,7 +268,7 @@ mod tests {
268268
// Exact bytewise output — JCS must be deterministic
269269
assert_eq!(
270270
canonical,
271-
r#"{"content":"ff","name":"event\"with\\special\nchars","type":134217729}"#
271+
r#"{"name":"event\"with\\special\nchars","payload":"ff","type":134217729}"#
272272
);
273273
}
274274

@@ -277,17 +277,17 @@ mod tests {
277277
// JCS RFC 8785 requires keys sorted by UTF-16 code unit order.
278278
// For ASCII keys, this is alphabetical.
279279
let canonical = canonical_event_json_v2("test", &[0x01]);
280-
let content_pos = canonical.find(r#""content":"#).unwrap();
281280
let name_pos = canonical.find(r#""name":"#).unwrap();
281+
let payload_pos = canonical.find(r#""payload":"#).unwrap();
282282
let type_pos = canonical.find(r#""type":"#).unwrap();
283-
assert!(content_pos < name_pos);
284-
assert!(name_pos < type_pos);
283+
assert!(name_pos < payload_pos);
284+
assert!(payload_pos < type_pos);
285285
}
286286

287287
#[test]
288288
fn canonical_json_empty_event_and_payload() {
289289
let canonical = canonical_event_json_v2("", &[]);
290-
assert_eq!(canonical, r#"{"content":"","name":"","type":134217729}"#);
290+
assert_eq!(canonical, r#"{"name":"","payload":"","type":134217729}"#);
291291
}
292292

293293
#[test]
@@ -326,11 +326,11 @@ mod tests {
326326
}
327327

328328
#[test]
329-
fn canonical_json_content_lowercase_hex() {
330-
// Content payload must be hex-encoded lowercase for determinism.
329+
fn canonical_json_payload_lowercase_hex() {
330+
// Payload must be hex-encoded lowercase for determinism.
331331
let canonical = canonical_event_json_v2("test", &[0xAB, 0xCD, 0xEF]);
332332
assert!(
333-
canonical.contains(r#""content":"abcdef""#),
333+
canonical.contains(r#""payload":"abcdef""#),
334334
"got: {canonical}"
335335
);
336336
}

cc-eventlog/src/tdx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
///
2020
/// For dstack runtime events (`event_type == DSTACK_RUNTIME_EVENT_TYPE`), the digest is:
2121
/// - V1: `sha384(event_type_le || ":" || event || ":" || payload)`
22-
/// - V2: `sha384(canonical_json({"name":"...","type":134217729,"content":"hex..."}))`
22+
/// - V2: `sha384(canonical_json({"name":"...","type":134217729,"payload":"hex..."}))`
2323
#[derive(Clone, Debug, Serialize, Deserialize, Encode, Decode)]
2424
pub struct TdxEvent {
2525
/// IMR index, starts from 0
@@ -186,7 +186,7 @@ mod tests {
186186
// V2 hash_input is the canonical JSON (version is carried out-of-band)
187187
assert!(input_str.contains(r#""name":"compose-hash""#));
188188
assert!(input_str.contains(r#""type":134217729"#));
189-
assert!(input_str.contains(r#""content":"abcd""#));
189+
assert!(input_str.contains(r#""payload":"abcd""#));
190190
assert!(!input_str.contains(r#""version""#));
191191
// And hashing it reproduces the digest
192192
let actual = Sha384::hash([input.as_slice()]);

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({"name":"...","type":134217729,"content":"hex..."})`
22+
/// `SHA({"name":"...","type":134217729,"payload":"hex..."})`
2323
V2,
2424
}
2525

0 commit comments

Comments
 (0)