Skip to content

fix(factory): cap create_pools_batch length at MAX_BATCH_SIZE - #595

Merged
ritaifeoluwa merged 3 commits into
SmartDropLabs:mainfrom
DeFiVC:fix/create-pool-validation-528-531
Oct 21, 2026
Merged

ritaifeoluwa merged 3 commits into
SmartDropLabs:mainfrom
DeFiVC:fix/create-pool-validation-528-531

Conversation

@DeFiVC

@DeFiVC DeFiVC commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #528, Closes #529, Closes #530, Closes #531

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Summary

create_pools_batch accepted an unbounded number of entries, each of which deploys a full farming-pool WASM instance. A large batch exhausts the transaction's resource budget and traps with an opaque host error rather than a typed failure. This PR caps the batch at MAX_BATCH_SIZE (10) and rejects oversized batches with a new BatchTooLarge error before any pool is deployed.

Motivation / Context

Closes #528, Closes #529, Closes #530, Closes #531 — each batch entry triggers a WASM deploy inside create_pool_inner, so an unbounded batch is a resource-exhaustion vector. The guard runs before the deployment loop, so a caller gets a deterministic FactoryError::BatchTooLarge instead of a non-deterministic budget trap.

Changes

  • soroban/contracts/factory/src/lib.rs — added MAX_BATCH_SIZE = 10 constant and a length check at the top of create_pools_batch that returns FactoryError::BatchTooLarge before any pool is created.
  • soroban/contracts/factory/src/types.rs — added BatchTooLarge = 20 to FactoryError.
  • soroban/contracts/factory/src/test.rs — added 2 regression tests: one rejects a batch of MAX_BATCH_SIZE + 1 with BatchTooLarge and zero pools created; one accepts a batch of exactly MAX_BATCH_SIZE and registers all pools.
  • Applied cargo fmt across the factory crate to resolve pre-existing formatting drift (required by CI's cargo fmt --check gate).

Testing

  • cargo check -p factory --lib passes cleanly.
  • cargo fmt -p factory -- --check passes after formatting fixes.
  • cargo clippy -p factory --lib compiles without warnings.
  • Note: cargo test -p factory --lib cannot run in the current environment — the farming-pool WASM (136 KB) exceeds Soroban's 128 KB contract-code limit, so setup() fails with Budget, ExceededLimit on every test that uploads it. This is pre-existing on main (upstream CI run 39517565845 also fails). The new tests follow the exact same patterns as the existing batch tests and will pass once the WASM size is addressed.

Tradeoffs

  • MAX_BATCH_SIZE = 10 is conservative but sufficient for legitimate batch-creation use cases while capping per-transaction resource usage. The value is a named constant and trivially adjustable.
  • The check runs before the deployment loop (not inside it) so an oversized batch fails fast with zero side effects.

Out of scope

  • Fixing the farming-pool WASM size overflow (136 KB > 128 KB Soroban limit) — separate infrastructure concern affecting all factory tests.
  • The broken tests/create_pool_*_validation.rs stub files from PR Create pool parameter validation tests #553 (todo!() helpers) — pre-existing and unrelated.

Each batch entry deploys a full farming-pool WASM instance inside
create_pool_inner, so an unbounded batch can exhaust the transaction's
resource budget and trap with an opaque host error rather than a typed
failure. Add MAX_BATCH_SIZE (10) and reject oversized batches with a
new BatchTooLarge error before any pool is deployed (SmartDropLabs#528-SmartDropLabs#531).
Verify that a batch exceeding MAX_BATCH_SIZE is rejected with
BatchTooLarge and that a batch of exactly MAX_BATCH_SIZE succeeds.
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@DeFiVC Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@netlify

netlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for sdcontracts ready!

Name Link
🔨 Latest commit 0298dbb
🔍 Latest deploy log https://app.netlify.com/projects/sdcontracts/deploys/6ad85709d023b6beba16d40a
😎 Deploy Preview https://deploy-preview-595--sdcontracts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ritaifeoluwa
ritaifeoluwa merged commit da2d614 into SmartDropLabs:main Oct 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants