0xMiden / 0xMiden/protocol

Test stack padding and truncation in kernel procedure wrappers

Offen
#2,881 1 Kommentar 0 Reaktionen 1 zugewiesene Person Beansprucht von @partylikeits1983 Auf GitHub ansehen
kernels
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

We should consider implementing one or more tests that checks that all wrappers around kernel procedures pad and truncate the stack correctly. Stack padding/truncation is done manually in every one of these procedures and is easy to get wrong, in a few cases _without_ breaking the functionality of the procedure itself. This means tests that check the functionality in isolation don't always catch these issues.

A real example was fixed in https://github.com/0xMiden/protocol/pull/2871, where `add_attachment` was internally padded with `push.0 movdn.8` instead of `push.0 movdn.7`. This resulted in one of the existing stack elements to be used as the note idx, which happened to be 0. Since 0 is often the target note idx in tests anyway, this didn't break tests. The error surface when the procedure was called in a loop.

The goal of these tests is to make sure that the stack effect of these procedures is neutral, no stray elements are left behind, and no existing elements are unintentionally dropped, according to the procedure's signature.

We'd need to execute a valid invocation of each procedure, so parameters will likely need to be customized. One test per module (`output_note`, `input_note`, ...) might be useful and `rstest` might be handy to parameterize over all procedures. But if we can automate more of this away, that'd be even better.

Since this is critical for correctness, it would be good to do before mainnet.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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