Add max input POD check to MainPodBuilder (#440)

This commit is contained in:
Ahmad Afuni 2025-12-08 23:23:51 +10:00 committed by GitHub
parent 42f979c408
commit 32dc85471d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions

View file

@ -148,8 +148,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Build a pod to prove the statement `over_9000("Alice")` // Build a pod to prove the statement `over_9000("Alice")`
let mut builder = MainPodBuilder::new(&params, vd_set); let mut builder = MainPodBuilder::new(&params, vd_set);
builder.add_pod(pod_alice_lvl_1_points); builder.add_pod(pod_alice_lvl_1_points)?;
builder.add_pod(pod_alice_lvl_2_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_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_gt_9000 = builder.priv_op(Operation::gt(3512 + 5771, 9000))?;
let _st_over_9000 = builder.pub_op(Operation::custom( let _st_over_9000 = builder.pub_op(Operation::custom(

View file

@ -166,7 +166,7 @@ impl EthDosHelper {
int_attestation: &SignedDict, // int signs dst int_attestation: &SignedDict, // int signs dst
) -> Result<MainPodBuilder> { ) -> Result<MainPodBuilder> {
let mut pod = MainPodBuilder::new(&self.params, &self.vd_set); 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 let eth_dos_int_to_dst = eth_dos_src_to_int_pod
.pod .pod

View file

@ -35,6 +35,8 @@ pub enum InnerError {
PodlangParse(String), PodlangParse(String),
#[error("POD Request validation error: {0}")] #[error("POD Request validation error: {0}")]
PodRequestValidation(String), 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}")] #[error("Too many public statements provided: {0} were provided, but the maximum is {1}")]
TooManyPublicStatements(usize, usize), TooManyPublicStatements(usize, usize),
#[error("Too many statements provided: {0} were provided, but the maximum is {1}")] #[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 { pub(crate) fn pod_request_validation(e: String) -> Self {
new!(PodRequestValidation(e)) 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 { pub(crate) fn too_many_public_statements(found: usize, max: usize) -> Self {
new!(TooManyPublicStatements(found, max)) new!(TooManyPublicStatements(found, max))
} }

View file

@ -164,8 +164,15 @@ impl MainPodBuilder {
dict_contains: Vec::new(), 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); 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<()> { pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> {
// TODO: Do error handling instead of panic // TODO: Do error handling instead of panic