From 21464a8c7e2d1727fe2d53bd0371bd0d72acc40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20B=C4=99za?= Date: Wed, 18 Sep 2024 14:03:07 +0200 Subject: [PATCH] feat(tee): use hex serialization for RPC responses Following Anton's suggestion, we have switched to hex serialization for API/RPC requests and responses. Previously, we used default JSON serialization for Vec, which resulted in a lengthy comma-separated list of integers. This change standardizes serialization, making it more efficient and reducing the size of the responses. The previous format, with a series of comma-separated integers for pubkey-like fields, looked odd. Then: ``` curl -X POST\ -H "Content-Type: application/json" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "unstable_getTeeProofs", "params": [491882, "Sgx"] }' \ https://mainnet.era.zksync.io {"jsonrpc":"2.0","result":[{"attestation":[3,0,2,0,0,0,0,0,10, ``` Now: ``` $ curl -X POST \ -H "Content-Type: application/json" \ --data '{"jsonrpc": "2.0", "id": 1, "method": "unstable_getTeeProofs", "params": [1, "sgx"] }' \ http://localhost:3050 {"jsonrpc":"2.0","result":[{"l1BatchNumber":1,"teeType":"sgx","pubkey":"0506070809","signature":"0001020304","proof":"0a0b0c0d0e","provedAt":"2024-09-16T11:53:38.253033Z","attestation":"0403020100"}],"id":1} ``` This change needs to be deployed in lockstep with: https://github.com/matter-labs/zksync-era/pull/2887. --- Cargo.lock | 1 + bin/verify-era-proof-attestation/Cargo.toml | 1 + bin/verify-era-proof-attestation/src/proof.rs | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7ed6d55..1010857 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5636,6 +5636,7 @@ dependencies = [ "reqwest 0.12.7", "secp256k1 0.29.1", "serde", + "serde_with 3.9.0", "teepot", "tokio", "tracing", diff --git a/bin/verify-era-proof-attestation/Cargo.toml b/bin/verify-era-proof-attestation/Cargo.toml index b0b8909..acd88a9 100644 --- a/bin/verify-era-proof-attestation/Cargo.toml +++ b/bin/verify-era-proof-attestation/Cargo.toml @@ -16,6 +16,7 @@ jsonrpsee-types.workspace = true reqwest.workspace = true secp256k1.workspace = true serde.workspace = true +serde_with = { workspace = true, features = ["hex"] } teepot.workspace = true tokio.workspace = true tracing.workspace = true diff --git a/bin/verify-era-proof-attestation/src/proof.rs b/bin/verify-era-proof-attestation/src/proof.rs index 6f1fdb7..3cd0ec1 100644 --- a/bin/verify-era-proof-attestation/src/proof.rs +++ b/bin/verify-era-proof-attestation/src/proof.rs @@ -5,6 +5,7 @@ use anyhow::{bail, Result}; use jsonrpsee_types::error::ErrorObject; use reqwest::Client; use serde::{Deserialize, Serialize}; +use serde_with::{hex::Hex, serde_as}; use std::time::Duration; use tokio::sync::watch; use tracing::{error, warn}; @@ -146,14 +147,19 @@ pub struct GetProofsResponse { pub error: Option>, } +#[serde_as] #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Proof { pub l1_batch_number: u32, pub tee_type: String, + #[serde_as(as = "Hex")] pub pubkey: Vec, + #[serde_as(as = "Hex")] pub signature: Vec, + #[serde_as(as = "Hex")] pub proof: Vec, pub proved_at: String, + #[serde_as(as = "Hex")] pub attestation: Vec, }