Skip to content

Commit 32dc854

Browse files
authored
Add max input POD check to MainPodBuilder (#440)
1 parent 42f979c commit 32dc854

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

examples/main_pod_points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
148148

149149
// Build a pod to prove the statement `over_9000("Alice")`
150150
let mut builder = MainPodBuilder::new(&params, vd_set);
151-
builder.add_pod(pod_alice_lvl_1_points);
152-
builder.add_pod(pod_alice_lvl_2_points);
151+
builder.add_pod(pod_alice_lvl_1_points)?;
152+
builder.add_pod(pod_alice_lvl_2_points)?;
153153
let st_points_total = builder.priv_op(Operation::sum_of(3512 + 5771, 3512, 5771))?;
154154
let st_gt_9000 = builder.priv_op(Operation::gt(3512 + 5771, 9000))?;
155155
let _st_over_9000 = builder.pub_op(Operation::custom(

src/examples/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl EthDosHelper {
166166
int_attestation: &SignedDict, // int signs dst
167167
) -> Result<MainPodBuilder> {
168168
let mut pod = MainPodBuilder::new(&self.params, &self.vd_set);
169-
pod.add_pod(eth_dos_src_to_int_pod.clone());
169+
pod.add_pod(eth_dos_src_to_int_pod.clone())?;
170170

171171
let eth_dos_int_to_dst = eth_dos_src_to_int_pod
172172
.pod

src/frontend/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub enum InnerError {
3535
PodlangParse(String),
3636
#[error("POD Request validation error: {0}")]
3737
PodRequestValidation(String),
38+
#[error("Too many input PODs provided: {0} were provided, but the maximum is {1}")]
39+
TooManyInputPods(usize, usize),
3840
#[error("Too many public statements provided: {0} were provided, but the maximum is {1}")]
3941
TooManyPublicStatements(usize, usize),
4042
#[error("Too many statements provided: {0} were provided, but the maximum is {1}")]
@@ -108,6 +110,9 @@ impl Error {
108110
pub(crate) fn pod_request_validation(e: String) -> Self {
109111
new!(PodRequestValidation(e))
110112
}
113+
pub(crate) fn too_many_input_pods(found: usize, max: usize) -> Self {
114+
new!(TooManyInputPods(found, max))
115+
}
111116
pub(crate) fn too_many_public_statements(found: usize, max: usize) -> Self {
112117
new!(TooManyPublicStatements(found, max))
113118
}

src/frontend/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,15 @@ impl MainPodBuilder {
164164
dict_contains: Vec::new(),
165165
}
166166
}
167-
pub fn add_pod(&mut self, pod: MainPod) {
167+
pub fn add_pod(&mut self, pod: MainPod) -> Result<()> {
168168
self.input_pods.push(pod);
169+
match self.input_pods.len() > self.params.max_input_pods {
170+
true => Err(Error::too_many_input_pods(
171+
self.input_pods.len(),
172+
self.params.max_input_pods,
173+
)),
174+
_ => Ok(()),
175+
}
169176
}
170177
pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> {
171178
// TODO: Do error handling instead of panic

0 commit comments

Comments
 (0)