…validation (#380)
## Description
This PR fixes panic paths in `override_range`/`atomic_operation` flows
by centralizing index/range validation and converting invalid inputs
into explicit errors.
Related to: #379
## Changes
- Added shared validator: `validate_override_range_inputs` in
`utils/src/merkle_tree/override_range_validation.rs`.
- Added `EmptyIndicesPolicy` enum (`Allow` / `Reject`) to make
adapter-specific empty-index behavior explicit.
- Wired shared validation into:
- `rln/src/pm_tree_adapter.rs`
- `utils/src/merkle_tree/full_merkle_tree.rs`
- `utils/src/merkle_tree/optimal_merkle_tree.rs`
- Replaced unchecked `start + leaves_len` arithmetic with `checked_add`
in `set_range` paths for full/optimal trees.
## Testing
- Added regression coverage in `rln/tests/ffi.rs` for:
- valid `start` with problematic delete-index layout (previously could
panic),
- overflowing `start` (`usize::MAX`) in atomic operation.
- Added unit tests for validator behavior (overflow, incompatible mixed
offsets, empty-index policy).
Covered scenarios:
- OOB delete indices now return error (no panic).
- Overflow in `start + leaves_len` now returns error (no panic).
- Empty-index handling is explicit per implementation via
`EmptyIndicesPolicy`.
---
## PR Lifecycle
> [!IMPORTANT]
> **Draft PRs** signal that work is still in progress and **will not
trigger CI**.
> Only mark your PR as **Ready for review** when you believe it is
complete.
> All CI checks **must pass** before requesting a review.
## Code Guidelines
Please keep the following in mind (see
[CONTRIBUTING.md](../CONTRIBUTING.md) for full details):
### Commits
- Follow [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) (`feat(rln):`,
`fix(utils):`, `chore:`, etc.)
- Use the appropriate scope: `rln`, `rln-cli`, `rln-wasm`, `utils`, `ci`
- GPG-sign your commits
### Error Handling
- **No panics in library code.** Do not use `unwrap()`, `expect()`, or
`panic!()`
in production paths inside `rln/src/` or `utils/src/`.
The only acceptable exception is an internal invariant that is
statically guaranteed — and even then,
prefer returning an error.
- Use the project's `thiserror`-based error types (`RLNError`,
`ProtocolError`, `UtilsError`, etc.)
and propagate errors with `?`.
- Provide context in error variants (e.g., `InsufficientData { expected,
actual }`).
- `unwrap()` is fine in **tests**.
### Code Style
- Run `cargo fmt --all -- --check` to verify formatting (CI enforces
this on stable).
- Group imports: std first, then external crates, then local modules
(see `rustfmt.toml`).
- Use `pub(crate)` for items that should not be part of the public API.
- Apply `Zeroize` / `ZeroizeOnDrop` to any struct holding secret
material.
### Linting (mirrors CI)
CI runs clippy across multiple crate/feature combinations. Run the
relevant checks locally before pushing:
```bash
# Default features — workspace root (rln + utils)
cargo clippy --all-targets --tests --release -- -D warnings
# Stateless feature — from rln/
cd rln && cargo clippy --all-targets --tests --release \
--features=stateless --no-default-features -- -D warnings
# WASM target — from rln-wasm/
cd rln-wasm && cargo clippy --target wasm32-unknown-unknown \
--tests --release -- -D warnings
```
At minimum, run the default-features check. If your changes touch
`stateless` or `rln-wasm`, run those checks as well.
## Checklist
- [x] My PR title follows [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) format
- [x] I have linked the related issue(s)
- [x] `cargo fmt --all -- --check` produces no changes
- [x] Clippy passes for all affected crate/feature combinations (see
[Linting](#linting-mirrors-ci) above)
- [x] `make test` passes locally
- [x] No new `unwrap()` / `expect()` / `panic!()` in library code
- [x] New code includes appropriate tests (unit / integration / WASM
where applicable)
- [x] I have run the CI coverage report — add the `run-coverage` label
to enable it
- [x] All CI checks pass and the PR is marked **Ready for review**
Description
A batch of tests to cover serialization and FFI error cases for witness/proof values. C FFI coverage extension for out-of-bounds, bad depth, and invalid inputs.
Tests modified/added
rln/tests/ffi.rs:
rln/tests/protocol.rs:
Issues reported
Coverage changed
Before 88.05%
Download HTML Report
After 88.98%
Download HTML Report
Checklist
run-coveragelabel to this PR to enable it.