0xMiden / 0xMiden/web-sdk

InputNotes.getNote and OutputNotes.getNote panic on out-of-bounds indexes

Offen Anfängerfreundlich
#305 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
TypeScript
Sterne
1
Forks
21
Ø Merge
12 Std. 14 Min.
Gemergte PRs (30 T.)
41

Beschreibung

The web-client wrappers for `InputNotes.getNote(index)` and `OutputNotes.getNote(index)` pass the JS-provided index directly into the native collection:

```rust
pub fn get_note(&self, index: u8) -> InputNote {
self.0.get_note(index as usize).into()
}

pub fn get_note(&self, index: u32) -> OutputNote {
self.0.get_note(index as usize).into()
}
```

The native Miden collections index directly into their internal vector (`&self.notes[idx]`). If a caller asks for `getNote(numNotes())` or any larger index, the WASM binding panics instead of returning a catchable JS error.

This is easy for consumers to hit when iterating notes or when an index comes from UI state. The adjacent APIs already expose `numNotes()` and `isEmpty()`, so it would be more robust for `getNote()` to validate the bounds at the JS boundary and return a normal `JsErr` with the requested index and collection length.

Suggested fix:

- Change both `get_note` wrappers to return `Result<..., JsErr>`.
- Check `index < num_notes()` before calling the native getter.
- Add a regression test that `getNote(numNotes())` throws a JS error instead of panicking the WASM instance.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Look for the web-client wrappers in the codebase, likely in a directory like `src/wasm` or `src/bindings`. Find the `InputNotes` and `OutputNotes` structs and their `get_note` methods. The fix involves changing the return type to `Result<..., JsErr>`, adding a bounds check against `num_notes()`, and updating the JS/TS bindings accordingly. Write a test in the web-client test suite that calls `getNote(numNotes())` and expects a JS error, not a panic.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust, typescript, wasm
Bereich
api, web-dev
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Aktiv
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
75/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.