Skip to content

contracts: cap deposit_batch size and validate deposit_amount > 0 in constructor #62

Description

@tech-adrian

Area
contracts/pool/src/lib.rs (deposit_batch, __constructor)

Problem
Two small but real input-validation gaps in the pool contract:

  1. deposit_batch (lib.rs:357-410) only checks the aggregate next_index + count > MAX_LEAVES; there's no independent cap on commitments.len(). Each iteration does two persistent writes plus up to TREE_DEPTH (20) instance writes, so a large-enough batch can exceed Soroban's per-transaction CPU/resource budget and revert with an opaque host error instead of a clear PoolError.
  2. __constructor (lib.rs:296-311) stores deposit_amount: i128 with no check that it's > 0. A zero or negative deposit_amount would let deposit/deposit_batch mint a valid leaf while transferring nothing (or attempting an invalid transfer), and contracts/compliance's amount_to_field_bytes casts amount as u128, which mishandles a negative i128 silently. Low likelihood (it's a one-time, operator-controlled deploy parameter) but cheap to guard.

Proposed change
Add a MAX_BATCH_SIZE constant and a BatchTooLarge error checked up front in deposit_batch, documented alongside TREE_DEPTH/MAX_LEAVES. Add an InvalidDepositAmount error returned by the constructor if deposit_amount <= 0.

Acceptance Criteria

  • deposit_batch rejects batches over MAX_BATCH_SIZE with a clear BatchTooLarge error (tested)
  • Constructor rejects deposit_amount <= 0 with InvalidDepositAmount (tested)
  • Relevant tests (just test, pnpm test, cargo test, or nargo test as applicable) pass locally and in CI
  • A screenshot or short screen recording is attached to the PR showing the change working (cargo test output for both new checks) — required before this can be merged.

Open your PR against the dev branch, not main. All active development merges into dev.

Discuss this issue / coordinate work: join the DShield contributor Telegram group: https://t.me/+SiGHH24No9U2MDJk

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26bugSomething isn't workingcontracts

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions