Investigate integer overflow and page size in `get_invoice_range`

Aperta
#146 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust, wasm
Ambito
backend, payments

Direzione di ricerca

Start with get_invoice_range in contracts/invoice/src/lib.rs, where start_idx + len_val is computed on usize values converted from u32. Add tests in contracts/invoice/src/test.rs for len = 0, start past the length, start = u32::MAX, and a very large len, then switch to saturating arithmetic and cap the page size. Done when no input traps, the cap is documented in contracts/invoice/README.md, and fmt, clippy and tests pass. The 32-bit wasm behaviour still needs confirming on that target, which the host tests cannot show.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

contract difficulty: intermediate help wanted security testing

Difficulty: Intermediate

Problem

get_invoice_range computes (start_idx + len_val).min(...) on usize values converted from u32. On the 32-bit wasm target usize is 32 bits, and the release profile enables overflow-checks, so a large start plus len could trap instead of returning an empty page. Host tests run on a 64-bit target and cannot show this. There is also no maximum page size.

Why it matters

A public read function should never trap on valid-looking input, and unbounded pages can exceed resource limits.

Scope of work

Confirm the behaviour on the wasm target, switch to saturating arithmetic, add a documented maximum page size, and add tests for len = 0, start greater than the length, start = u32::MAX, and a very large len.

Expected outcome

get_invoice_range handles all inputs safely, and the behaviour is covered by tests.

Acceptance criteria

  • No input traps; extreme inputs return an empty or capped page.
  • A page-size cap is documented in the contract README.
  • New tests pass; cargo fmt --check, clippy and tests pass.

Relevant files

  • contracts/invoice/src/lib.rs, contracts/invoice/src/test.rs, contracts/invoice/README.md

Dependencies

Related to #55 and #27 (same file). No ABI change is required.

Maintainer discussion needed?

No (internal behaviour only).

Lingua principale
TypeScript
Stelle
0
Fork
4
Merge medio
54m
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Yormee-103/PayLoop

Tutte le issue di Yormee-103/PayLoop

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.