diff --git a/crates/rust-client/src/rpc/domain/limits.rs b/crates/rust-client/src/rpc/domain/limits.rs index f9f22a5c75..5d3be0b79b 100644 --- a/crates/rust-client/src/rpc/domain/limits.rs +++ b/crates/rust-client/src/rpc/domain/limits.rs @@ -1,6 +1,7 @@ // RPC LIMITS // ================================================================================================ +use alloc::format; use core::convert::TryFrom; use miden_tx::utils::serde::{ @@ -88,6 +89,14 @@ fn get_param( field_name: param, }, )?; + if *limit == 0 { + return Err(RpcConversionError::InvalidField(format!( + "{}.{} must be greater than zero", + endpoint.proto_name(), + param + ))); + } + Ok(*limit) } @@ -106,6 +115,8 @@ impl TryFrom for RpcLimits { #[cfg(test)] mod tests { + use alloc::string::String; + use super::*; #[test] @@ -122,4 +133,38 @@ mod tests { assert_eq!(original, deserialized); } + + #[test] + fn rejects_zero_limits_from_rpc_response() { + let mut proto = proto::RpcLimits::default(); + + proto.endpoints.insert( + RpcEndpoint::GetNotesById.proto_name().into(), + proto::EndpointLimits { + parameters: [(String::from("note_id"), 0)].into(), + }, + ); + proto.endpoints.insert( + RpcEndpoint::SyncNullifiers.proto_name().into(), + proto::EndpointLimits { + parameters: [(String::from("nullifier_prefix"), 1000)].into(), + }, + ); + proto.endpoints.insert( + RpcEndpoint::SyncTransactions.proto_name().into(), + proto::EndpointLimits { + parameters: [(String::from("account_id"), 1000)].into(), + }, + ); + proto.endpoints.insert( + RpcEndpoint::SyncNotes.proto_name().into(), + proto::EndpointLimits { + parameters: [(String::from("note_tag"), 1000)].into(), + }, + ); + + let err = RpcLimits::try_from(proto).expect_err("zero limit should be rejected"); + + assert!(matches!(err, RpcConversionError::InvalidField(_)), "got {err:?}"); + } }