From eeb4570e4b0733b51e122c08deb2e1df894f8cd2 Mon Sep 17 00:00:00 2001 From: Best-Web Date: Sat, 18 Jul 2026 19:35:31 +0000 Subject: [PATCH] fix: resolve BatchTooLarge/AllowlistExpired discriminant conflict Both branches claimed discriminant 19. Resolved by: - Keeping AllowlistExpired = 19 (from main) - Assigning BatchTooLarge = 20 (from feat/batch-too-large-guard) - Adding max_batch_size: u32 field to Config (0 = unlimited) - Initializing max_batch_size: 0 in initialize() - Adding batch size guard in batch_create_packages --- app/onchain/contracts/aid_escrow/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/onchain/contracts/aid_escrow/src/lib.rs b/app/onchain/contracts/aid_escrow/src/lib.rs index 846bf863..c3b12cd5 100644 --- a/app/onchain/contracts/aid_escrow/src/lib.rs +++ b/app/onchain/contracts/aid_escrow/src/lib.rs @@ -74,6 +74,9 @@ pub struct Config { pub min_amount: i128, pub max_expires_in: u64, pub allowed_tokens: Vec
, + /// Maximum number of packages allowed in a single batch_create_packages call. + /// 0 means unlimited. + pub max_batch_size: u32, } #[contracttype] @@ -108,6 +111,9 @@ pub enum Error { TokenTransferFailed = 18, // Merkle allowlist root has expired (merkle_root_expires_at <= now) AllowlistExpired = 19, + /// Batch request exceeds the configured per-call ceiling. + /// Carries (requested, max). + BatchTooLarge = 20, } // --- Contract Events (indexer-friendly; stable topics & payloads) --- @@ -235,6 +241,7 @@ impl AidEscrow { min_amount: 1, max_expires_in: 0, allowed_tokens: Vec::new(&env), + max_batch_size: 0, }; env.storage().instance().set(&KEY_CONFIG, &config); Ok(()) @@ -642,6 +649,11 @@ impl AidEscrow { return Err(Error::MismatchedArrays); } + // Guard against oversized batches + if config.max_batch_size > 0 && recipients.len() > config.max_batch_size { + return Err(Error::BatchTooLarge); + } + if !config.allowed_tokens.is_empty() && !config.allowed_tokens.contains(token.clone()) { return Err(Error::InvalidState); }