Skip to content

Commit f4985b5

Browse files
committed
Fix serialization
1 parent 15c8d13 commit f4985b5

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

aggregation_mode/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/Cargo.lock

Lines changed: 10 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tokio = { version = "1.37.0", features = [
1919
] }
2020
lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "5f8f2cfcc8a1a22f77e8dff2d581f1166eefb80b", features = ["serde"]}
2121
serde = { version = "1.0.201", features = ["derive"] }
22+
serde_bytes = "0.11"
2223
sha3 = { version = "0.10.8" }
2324
url = "2.5.0"
2425
hex = "0.4.3"

crates/sdk/src/common/types.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,28 @@ impl Display for ProvingSystemId {
6565
#[derive(Debug, Serialize, Deserialize, Clone)]
6666
pub struct VerificationData {
6767
pub proving_system: ProvingSystemId,
68+
#[serde(with = "serde_bytes")]
6869
pub proof: Vec<u8>,
70+
#[serde(
71+
default,
72+
skip_serializing_if = "Option::is_none",
73+
deserialize_with = "deserialize_option_bytes",
74+
serialize_with = "serialize_option_bytes"
75+
)]
6976
pub pub_input: Option<Vec<u8>>,
77+
#[serde(
78+
default,
79+
skip_serializing_if = "Option::is_none",
80+
deserialize_with = "deserialize_option_bytes",
81+
serialize_with = "serialize_option_bytes"
82+
)]
7083
pub verification_key: Option<Vec<u8>>,
84+
#[serde(
85+
default,
86+
skip_serializing_if = "Option::is_none",
87+
deserialize_with = "deserialize_option_bytes",
88+
serialize_with = "serialize_option_bytes"
89+
)]
7190
pub vm_program_code: Option<Vec<u8>>,
7291
pub proof_generator_addr: Address,
7392
}
@@ -429,15 +448,13 @@ pub enum SubmitProofResponseMessage {
429448
EthRpcError,
430449
InvalidPaymentServiceAddress(Address, Address),
431450
UnderpricedProof,
432-
ServerBusy,
433451
}
434452

435453
#[derive(Debug, Clone, Serialize, Deserialize)]
436454
pub enum GetNonceResponseMessage {
437455
Nonce(U256),
438456
EthRpcError(String),
439457
InvalidRequest(String),
440-
ServerBusy,
441458
}
442459

443460
#[derive(Debug, Clone)]
@@ -504,6 +521,25 @@ impl Network {
504521
}
505522
}
506523

524+
// Helper functions for serializing Option<Vec<u8>> with serde_bytes
525+
fn serialize_option_bytes<S>(value: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
526+
where
527+
S: serde::Serializer,
528+
{
529+
match value {
530+
Some(bytes) => serde_bytes::serialize(bytes, serializer),
531+
None => serializer.serialize_none(),
532+
}
533+
}
534+
535+
fn deserialize_option_bytes<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
536+
where
537+
D: serde::Deserializer<'de>,
538+
{
539+
let opt: Option<serde_bytes::ByteBuf> = Option::deserialize(deserializer)?;
540+
Ok(opt.map(|buf| buf.into_vec()))
541+
}
542+
507543
#[cfg(test)]
508544
mod tests {
509545
use ethers::signers::LocalWallet;

0 commit comments

Comments
 (0)