0xMiden / 0xMiden/protocol

Test stack padding and truncation in kernel procedure wrappers

Aperta
#2,881 1 commento 0 reazioni 1 assegnatario Rivendicata da @partylikeits1983 Vedi su GitHub
kernels
Lingua principale
Rust
Stelle
132
Fork
167
Merge medio
1g 23h
PR unite (30g)
110

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.