Expose a bounded page from a Cairo storage Vec

A storage Vec lives in contract storage and its length is separate from its element accessors. A public query that accepts a start index and count must handle the boundary before reading.

Clamp reads to the observed length

Read the vector length once. If the caller starts at or beyond the length, return an empty page or the documented error. Otherwise limit the count to the remaining elements before calculating the end index.

length = 3
valid indices: 0, 1, 2
requested index: 3

With length three, start two and requested count ten, return only element two. Reading index three reaches the out-of-bounds case. Use the optional accessor when the contract API should return absence instead of panicking.

Preserve snapshot semantics for multiple calls

Appending or popping between requests changes the length and potentially the visible suffix. Off-chain consumers paging a historical list should query one retained block. Also cap page size so an untrusted request cannot force a very large storage read. starknet.io The Cairo Programming Language