Skip to content

Commit 3320eb2

Browse files
committed
fix: serialize version in RuntimeEvent for attestation roundtrip
The version field must survive serde serialization because the verify path in AttestationV1 uses RuntimeEvent directly from StackEvidence (serde-encoded). Without serializing version, all deserialized events default to V1, causing RTMR3 mismatch for V2 events. - Change from skip_serializing to always serialize version - Old data without version field still defaults to V1 via #[serde(default)] - Scale encoding still skips version via #[codec(skip)] for binary compat
1 parent 9e761b8 commit 3320eb2

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

cc-eventlog/src/runtime_events.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct RuntimeEvent {
3232
#[serde(with = "base64")]
3333
pub payload: Vec<u8>,
3434
/// Event log version
35-
#[serde(default, skip_serializing)]
35+
#[serde(default)]
3636
#[codec(skip)]
3737
pub version: EventLogVersion,
3838
}
@@ -238,19 +238,19 @@ mod tests {
238238
}
239239

240240
#[test]
241-
fn serialize_omits_version() {
242-
let v1 = RuntimeEvent::new("test".to_string(), vec![1], EventLogVersion::V1);
241+
fn serde_roundtrip_preserves_version() {
243242
let v2 = RuntimeEvent::new("test".to_string(), vec![1], EventLogVersion::V2);
244-
let json_v1 = serde_json::to_string(&v1).unwrap();
245-
let json_v2 = serde_json::to_string(&v2).unwrap();
246-
assert!(
247-
!json_v1.contains("version"),
248-
"version should never be serialized"
249-
);
250-
assert!(
251-
!json_v2.contains("version"),
252-
"version should never be serialized"
253-
);
243+
let json = serde_json::to_string(&v2).unwrap();
244+
assert!(json.contains(r#""version":2"#), "v2 must serialize version");
245+
let decoded: RuntimeEvent = serde_json::from_str(&json).unwrap();
246+
assert_eq!(decoded.version, EventLogVersion::V2);
247+
}
248+
249+
#[test]
250+
fn deserialize_without_version_defaults_to_v1() {
251+
let json = r#"{"event":"test","payload":"AQ=="}"#;
252+
let decoded: RuntimeEvent = serde_json::from_str(json).unwrap();
253+
assert_eq!(decoded.version, EventLogVersion::V1);
254254
}
255255

256256
#[test]

0 commit comments

Comments
 (0)