Skip to content

Commit

Permalink
fix(tee): lowercase enum TEE types (#2798)
Browse files Browse the repository at this point in the history
## 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
pbeza authored Sep 5, 2024
1 parent 6e057eb commit 0f2f9bd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
46 changes: 43 additions & 3 deletions core/lib/basic_types/src/tee_types.rs
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");
}
}
2 changes: 1 addition & 1 deletion core/lib/prover_interface/tests/job_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ fn test_tee_proof_request_serialization() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_result = serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_str).unwrap();
let tee_proof_expected = SubmitTeeProofRequest(Box::new(L1BatchTeeProofForL1 {
Expand Down
4 changes: 2 additions & 2 deletions core/node/proof_data_handler/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn request_tee_proof_inputs() {
},
L1BatchCommitmentMode::Rollup,
);
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "Sgx" })).unwrap());
let req_body = Body::from(serde_json::to_vec(&json!({ "tee_type": "sgx" })).unwrap());
let response = app
.oneshot(
Request::builder()
Expand Down Expand Up @@ -134,7 +134,7 @@ async fn submit_tee_proof() {
"signature": [ 0, 1, 2, 3, 4 ],
"pubkey": [ 5, 6, 7, 8, 9 ],
"proof": [ 10, 11, 12, 13, 14 ],
"tee_type": "Sgx"
"tee_type": "sgx"
}"#;
let tee_proof_request =
serde_json::from_str::<SubmitTeeProofRequest>(tee_proof_request_str).unwrap();
Expand Down

0 comments on commit 0f2f9bd

Please sign in to comment.