-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tee): lowercase enum TEE types (#2798)
## What ❔ We encountered an issue where the staging environment was unable to deserialize `sgx` to `TeeType::Sgx`. Relevant code: - https://github.com/matter-labs/zksync-era/blob/87b02e3ab5c1f61d59dd0f0eefa9ec33a7b55488/core/lib/basic_types/src/tee_types.rs#L7 - https://github.com/matter-labs/teepot/blob/537521f0ee2bd704fb839fe336f43f8aab5887df/bin/tee-key-preexec/src/main.rs#L53 Relevant logs: - https://grafana.matterlabs.dev/goto/Q5ENugeSR?orgId=1 ## Why ❔ To fix a panic in the staging environment. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`.
- Loading branch information
Showing
3 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
use std::fmt; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
use strum::{Display, EnumString}; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, EnumString, Display, Serialize, Deserialize)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "lowercase")] | ||
#[non_exhaustive] | ||
pub enum TeeType { | ||
#[strum(serialize = "sgx")] | ||
Sgx, | ||
} | ||
|
||
impl fmt::Display for TeeType { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
TeeType::Sgx => write!(f, "sgx"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use serde_json; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_serialize_teetype() { | ||
let json_str = "\"sgx\""; | ||
let tee_type: TeeType = serde_json::from_str(json_str).unwrap(); | ||
assert_eq!(tee_type, TeeType::Sgx); | ||
|
||
for json_str in &["\"Sgx\"", "\"SGX\""] { | ||
let result: Result<TeeType, _> = serde_json::from_str(json_str); | ||
assert!(result.is_err()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_deserialize_teetype() { | ||
let tee_type = TeeType::Sgx; | ||
let json_str = serde_json::to_string(&tee_type).unwrap(); | ||
assert_eq!(json_str, "\"sgx\""); | ||
} | ||
|
||
#[test] | ||
fn test_display_teetype() { | ||
assert_eq!(TeeType::Sgx.to_string(), "sgx"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters