0xMiden / 0xMiden/protocol

Test stack padding and truncation in kernel procedure wrappers

Ouverte
#2,881 1 commentaire 0 réactions 1 personne assignée Réclamée par @partylikeits1983 Voir sur GitHub
kernels
Langage dominant
Rust
Étoiles
132
Forks
167
Merge moyen
1 j 23 h
PR mergées (30 j)
110

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.