From 32dc85471da6b814ff7ebd84a8a11dcb06908a90 Mon Sep 17 00:00:00 2001 From: Ahmad Afuni Date: Mon, 8 Dec 2025 23:23:51 +1000 Subject: [PATCH] Add max input POD check to MainPodBuilder (#440) --- examples/main_pod_points.rs | 4 ++-- src/examples/mod.rs | 2 +- src/frontend/error.rs | 5 +++++ src/frontend/mod.rs | 9 ++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/main_pod_points.rs b/examples/main_pod_points.rs index dc9bbe7..7c877e3 100644 --- a/examples/main_pod_points.rs +++ b/examples/main_pod_points.rs @@ -148,8 +148,8 @@ fn main() -> Result<(), Box> { // Build a pod to prove the statement `over_9000("Alice")` let mut builder = MainPodBuilder::new(¶ms, vd_set); - builder.add_pod(pod_alice_lvl_1_points); - builder.add_pod(pod_alice_lvl_2_points); + builder.add_pod(pod_alice_lvl_1_points)?; + builder.add_pod(pod_alice_lvl_2_points)?; let st_points_total = builder.priv_op(Operation::sum_of(3512 + 5771, 3512, 5771))?; let st_gt_9000 = builder.priv_op(Operation::gt(3512 + 5771, 9000))?; let _st_over_9000 = builder.pub_op(Operation::custom( diff --git a/src/examples/mod.rs b/src/examples/mod.rs index 7c225cf..b5b2604 100644 --- a/src/examples/mod.rs +++ b/src/examples/mod.rs @@ -166,7 +166,7 @@ impl EthDosHelper { int_attestation: &SignedDict, // int signs dst ) -> Result { let mut pod = MainPodBuilder::new(&self.params, &self.vd_set); - pod.add_pod(eth_dos_src_to_int_pod.clone()); + pod.add_pod(eth_dos_src_to_int_pod.clone())?; let eth_dos_int_to_dst = eth_dos_src_to_int_pod .pod diff --git a/src/frontend/error.rs b/src/frontend/error.rs index 691eb36..aab6eb3 100644 --- a/src/frontend/error.rs +++ b/src/frontend/error.rs @@ -35,6 +35,8 @@ pub enum InnerError { PodlangParse(String), #[error("POD Request validation error: {0}")] PodRequestValidation(String), + #[error("Too many input PODs provided: {0} were provided, but the maximum is {1}")] + TooManyInputPods(usize, usize), #[error("Too many public statements provided: {0} were provided, but the maximum is {1}")] TooManyPublicStatements(usize, usize), #[error("Too many statements provided: {0} were provided, but the maximum is {1}")] @@ -108,6 +110,9 @@ impl Error { pub(crate) fn pod_request_validation(e: String) -> Self { new!(PodRequestValidation(e)) } + pub(crate) fn too_many_input_pods(found: usize, max: usize) -> Self { + new!(TooManyInputPods(found, max)) + } pub(crate) fn too_many_public_statements(found: usize, max: usize) -> Self { new!(TooManyPublicStatements(found, max)) } diff --git a/src/frontend/mod.rs b/src/frontend/mod.rs index f564598..2b1c070 100644 --- a/src/frontend/mod.rs +++ b/src/frontend/mod.rs @@ -164,8 +164,15 @@ impl MainPodBuilder { dict_contains: Vec::new(), } } - pub fn add_pod(&mut self, pod: MainPod) { + pub fn add_pod(&mut self, pod: MainPod) -> Result<()> { self.input_pods.push(pod); + match self.input_pods.len() > self.params.max_input_pods { + true => Err(Error::too_many_input_pods( + self.input_pods.len(), + self.params.max_input_pods, + )), + _ => Ok(()), + } } pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> { // TODO: Do error handling instead of panic