Debug info encoder decoder - #3276
Conversation
|
Automated check (CONTRIBUTING.md) Findings:
Recommendations:
Next steps:
|
huitseeker
left a comment
There was a problem hiding this comment.
Typed primitive sizing and encoding do not match declared debug primitive widths
Hi @huitseeker, thanks for your comment! I’ve updated the PR to correct the felt sizing in encoding/decoding. |
6c9ad32 to
1326478
Compare
|
I’ve rebased this branch and I’m re‑introducing |
huitseeker
left a comment
There was a problem hiding this comment.
Besides the non-canonical bool, this looks much closer now!
@huitseeker Thanks for your comments. I’ve added strict checks for boolean, and also for integer widths (including rejecting out‑of‑range felts), and expanded the typed debug errors so we get more precise diagnostics |
huitseeker
left a comment
There was a problem hiding this comment.
Please add a line to the Changelog too.
Hi @huitseeker, thanks again for the review and comments! I’ve added the changelog entry, and the other changes as well (normalizing the |
huitseeker
left a comment
There was a problem hiding this comment.
Thanks for addressing the prior bool/trust-path/changelog concerns.
Thanks again @huitseeker for all the detailed reviews and suggestions |
bitwalker
left a comment
There was a problem hiding this comment.
Looks good overall, but I have some nits/changes that I think need to be made before we merge this
|
Thanks @huitseeker and @bitwalker for all the detailed review comments. I’ve gone through the latest round and addressed the requested changes. I’ve also left a couple of follow‑up questions in the relevant threads. |
huitseeker
left a comment
There was a problem hiding this comment.
This LGTM! Please rebase.
bb3d628 to
dd62e32
Compare
Thanks @huitseeker! I've rebased this PR. |
|
Hi @huitseeker, I’ve fixed the |
huitseeker
left a comment
There was a problem hiding this comment.
i'm sorry but this will need a rebase once again. Beware that the Changelog format has changed a bit. You can also click options to let maintainers edit this PR.
|
I think we will need to wait to determine the disposition of #3398 - whether we will call it quits on the v0.25 release series and move everything to v0.26, or land #3398 on We're planning to make a final call on that tomorrow morning, but just wanted to give you a heads up @marijamijailovic |
I appreciate the heads-up! I’ll wait for the decision on #3398 and then update this PR as needed. |
Hi @bitwalker, is there any update regarding this and the plan for #3398? |
f57c182 to
d6230b5
Compare
|
Hi @huitseeker and @bitwalker, I’ve now rebased this on top of #3398. What changed:
Since the old review threads now point at code that no longer exists, it’s probably cleanest to review the single new commit. The earlier commits are still reachable through the force‑push compare in this PR’s timeline ( Thanks again for all your previous comments and suggestions. |
huitseeker
left a comment
There was a problem hiding this comment.
The anonymous type comment is the important one.
|
Hi @huitseeker, I have a quick question about the I see the latest entry is for version 0.28.0, and below that there is |
2b156e1 to
2cf5883
Compare
|
Hi @huitseeker, @bitwalker I’ve rebased this and added the changelog entry under the 0.30.0 release. Could you please take another look and let me know if it’s ready to merge? |
huitseeker
left a comment
There was a problem hiding this comment.
I still think this works. But TypedProcInfo accepts calling conventions it cannot encode correctly, so the public API promises more than the implementation delivers. The zero-width array decode also lets a small serialized type description consume unbounded time and memory. There's also an edge case paper cut in custom-codec arrays.
I would restrict the API to Component Model signatures for now, bound zero-width decoding, and make the array loop track token consumption.
| Type::Array(array_ty) => { | ||
| let mut cursor = felts; | ||
| let mut rendered = Vec::new(); | ||
| for _ in 0..array_ty.len { |
There was a problem hiding this comment.
Could we reject or cap zero-width arrays before this loop? ArrayType::len can come from a serialized usize, but felt_count([empty; n]) is zero for any n, so the stack-length check does not bound the work here.
A package declaring [empty; 1_000_000] made decode_result(&[]) spend about 0.67 seconds and 62 MB building the string, and the encoded length can be much larger. This gives a small untrusted manifest a direct memory and CPU denial of service.
There was a problem hiding this comment.
Thanks for this. I was thinking about a cap, but I was not sure about the upper limit, so I reject it with a ZeroWidthArray error instead. The test is an_array_of_elements_that_take_no_felts_is_not_decoded.
| /// anything else it reads from that export, like its digest, on the same procedure. | ||
| /// | ||
| /// The result has [`WordCodec`] and [`FeltCodec`]. Add more with [`Self::with_scalar_codec`]. | ||
| pub fn new(name: impl Into<String>, signature: FunctionType) -> Self { |
There was a problem hiding this comment.
Could TypedProcInfo reject signatures whose abi is not ComponentModel, unless the other layouts are implemented?
The encoder always flattens aggregate fields separately. That matches the canonical ABI used by the downstream miden call, but not Fast: the Miden ABI packs struct { u8, u8 } into one raw stack part, while this API emits two felts. C and Wasm have different aggregate rules too.
The test helper currently labels every fixture CallConv::Fast, so it hides this mismatch.
There was a problem hiding this comment.
Thanks for this catch! The tests now use ComponentModel, and TypedProcInfo::new refuses any other convention
| // check, a big `len` would loop and never move forward. | ||
| let empty = chunk.is_empty(); | ||
| felts.extend(chunk); | ||
| if empty { |
There was a problem hiding this comment.
A custom codec for a zero-field struct still consumes one token even though it correctly emits zero felts. For [empty; 2], the count check accepts two tokens, this breaks after the first codec call, and encode_args returns TokenCountMismatch.
Checking token_count or otherwise tracking token progress would preserve the large zero-width-array guard without skipping token-consuming codecs.
There was a problem hiding this comment.
Thanks! The array now skips its elements on token_count == 0, not on an empty chunk, so a codec that reads a token runs once per element and the token count matches.
|
Hi @huitseeker @bitwalker, just a quick bump on this PR. Can you look into this, and let me know if there’s anything else blocking merge? |
bitwalker
left a comment
There was a problem hiding this comment.
I think the only thing I would like to change before this is merged is to move this code into miden-assembly-syntax under the ast::types module, maybe as ast::types::signatures or something to that effect, and re-export TypedProcInfo (or whatever makes the most sense) from ast::types.
Nothing implemented here is relevant to miden-mast-package itself though - the details are all type signature oriented, and should live as close to that code as possible IMO.
Once this is moved into miden-assembly-syntax, it can be merged.
4b5813b to
766a8d6
Compare
Hi @bitwalker, I have moved |
|
Thanks @marijamijailovic! |
|
@marijamijailovic Can you make sure every commit in this PR is signed? |
766a8d6 to
2d71834
Compare
Hi @huitseeker, I’ve rebased this branch so that every commit is signed |
This PR adds
ast::types::TypedProcInfotomiden-assembly-syntax: a typed view over procedure signatures that can print the signature, encode argument into stack felts, and decode result felts back. Callers pass the procedure name and itsFunctionType;wordandfeltare built in, while other types such asaccount-idare provided by the caller via theWitScalarCodectrait. Themiden callcommand (0xMiden/rust-sdk#2179) uses this to print typed signatures and decode results instead of raw feltst. The module was moved frommiden-clientintomiden-assembly-syntaxsince the types already live inmiden-vm(0xMiden/rust-sdk#2179 (review)).The relevant issue 0xMiden/rust-sdk#2098, and context and motivation: Main issue #1395, and see the comment in #1943.