Description
// provenance.rs:86-118
pub fn get_by_address(env: &Env, address: &Address, offset: u32, limit: u32) -> Vec<ProvenanceRecord> {
...
let end = if offset + limit > len { len } else { offset + limit };
...
}
Unlike pagination::paginate (the shared helper documented as the canonical place "any module that needs offset/limit pagination" should use, and already used by registry.rs), get_by_address reimplements pagination inline. It doesn't clamp limit to MAX_PAGE_SIZE, and it computes offset + limit with plain u32 addition before checking against len. A caller passing large offset/limit values (e.g. both near u32::MAX) causes offset + limit to overflow, which panics in any build with overflow checks enabled — violating this codebase's "never panic!, return Result" convention — rather than returning a clamped/empty result the way pagination::paginate would.
Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/provenance.rs (get_by_address, lines 86-118)
Fix direction
Replace the inline pagination logic with the shared pagination::paginate helper (or, at minimum, use saturating_add/checked_add and clamp against MAX_PAGE_SIZE the same way pagination::paginate does) so behavior is consistent with the rest of the codebase and can't panic on adversarial input:
let end = offset.saturating_add(limit).min(len);
Acceptance Criteria
get_by_address no longer panics when called with offset/limit values that would overflow u32 addition.
get_by_address's pagination behavior (clamping to available records, respecting a max page size) matches pagination::paginate's conventions.
- A test calls
get_by_address with offset/limit near u32::MAX and confirms it returns cleanly instead of panicking.
cargo test passes.
Estimated Effort
Beginner: 2 hours
Intermediate: 1 hour
Expert: 0.5 hours
How to work this issue
- Read
contracts/ContributionGuide.md for the contribution workflow.
- Comment on the issue to claim it before starting.
- Branch:
fix/issue-921-provenance-pagination-overflow.
- Run
cargo fmt, cargo clippy -- -D warnings, cargo test before opening your PR.
- Use a Conventional Commit message, e.g.
fix: use checked pagination arithmetic in provenance::get_by_address.
Before you start
If you find this project interesting, please consider starring the repository on GitHub. It helps the project gain visibility and supports the Drips Wave program that rewards contributors for merged fixes like this one.
Description
Unlike
pagination::paginate(the shared helper documented as the canonical place "any module that needs offset/limit pagination" should use, and already used byregistry.rs),get_by_addressreimplements pagination inline. It doesn't clamplimittoMAX_PAGE_SIZE, and it computesoffset + limitwith plainu32addition before checking againstlen. A caller passing largeoffset/limitvalues (e.g. both nearu32::MAX) causesoffset + limitto overflow, which panics in any build with overflow checks enabled — violating this codebase's "never panic!, return Result" convention — rather than returning a clamped/empty result the waypagination::paginatewould.Technical Requirements
Files to update
contracts/contracts/stellar-grants/src/provenance.rs(get_by_address, lines 86-118)Fix direction
Replace the inline pagination logic with the shared
pagination::paginatehelper (or, at minimum, usesaturating_add/checked_addand clamp againstMAX_PAGE_SIZEthe same waypagination::paginatedoes) so behavior is consistent with the rest of the codebase and can't panic on adversarial input:Acceptance Criteria
get_by_addressno longer panics when called withoffset/limitvalues that would overflowu32addition.get_by_address's pagination behavior (clamping to available records, respecting a max page size) matchespagination::paginate's conventions.get_by_addresswithoffset/limitnearu32::MAXand confirms it returns cleanly instead of panicking.cargo testpasses.Estimated Effort
Beginner: 2 hours
Intermediate: 1 hour
Expert: 0.5 hours
How to work this issue
contracts/ContributionGuide.mdfor the contribution workflow.fix/issue-921-provenance-pagination-overflow.cargo fmt,cargo clippy -- -D warnings,cargo testbefore opening your PR.fix: use checked pagination arithmetic in provenance::get_by_address.Before you start
If you find this project interesting, please consider starring the repository on GitHub. It helps the project gain visibility and supports the Drips Wave program that rewards contributors for merged fixes like this one.