Commit 431a484
fix(decode): accept signed enum tag scalars in _extract_tag (#954)
## Summary
- Relax `_extract_tag` to accept both signed and unsigned `PrimitiveInt`
tag metadata (`signed=_`).
- Keep discriminant decoding based on raw tag bits (`int.from_bytes(...,
signed=False)`), which is what variant dispatch needs.
- Add a decode fixture for signed-tag metadata
(`enum-3-variants-0-fields-signed-tag`).
- Update the prove-rs case to a passing case and refresh its `show`
snapshot.
## Problem (concrete case)
This PR is motivated by:
`kmir/src/tests/integration/data/prove-rs/transmute-u8-to-enum-changed-discriminant-signed.rs`
```rust
#[repr(i8)]
enum AccountState {
Uninitialized = 0,
Initialized = 1,
Frozen = -1,
}
// main checks both byte-level and signed views of the same discriminant bits:
// 255 maps to Frozen in the u8 path
// -1 maps to Frozen in the i8 path
```
For this enum layout, the tag scalar metadata can be `signed=true` (I8),
even though the stored discriminant bytes are still valid raw bytes for
dispatch.
## Red (before this fix)
`_extract_tag` only matched `PrimitiveInt(..., signed=False)`. When
metadata was signed, decode failed with:
```text
ValueError: Unsupported tag: Initialized(value=PrimitiveInt(length=I8, signed=True), ...)
```
That blocked the signed-discriminant path in proving.
## Green (after this fix)
- `_extract_tag` now accepts either signedness metadata.
- The same bytes are decoded as unsigned raw bits for dispatch.
- The concrete program above now proves in integration tests:
- input case is now
`transmute-u8-to-enum-changed-discriminant-signed.rs`
- expected proof snapshot is
`show/transmute-u8-to-enum-changed-discriminant-signed.main.expected`
- terminal `#EndProgram` is reached for `main`
## Why this is the right scope
This change fixes tag extraction compatibility for signed discriminant
metadata without changing enum dispatch semantics beyond that path. It
is covered by both:
- decode-value fixture (`enum-3-variants-0-fields-signed-tag`) and
- end-to-end prove-rs integration snapshot for the concrete Rust program
above.
---------
Co-authored-by: automergerpr-permission-manager[bot] <190534181+automergerpr-permission-manager[bot]@users.noreply.github.com>1 parent 697e68a commit 431a484
6 files changed
Lines changed: 142 additions & 17 deletions
File tree
- kmir/src
- kmir
- tests/integration
- data
- decode-value
- prove-rs
- show
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
| 448 | + | |
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| 452 | + | |
| 453 | + | |
452 | 454 | | |
453 | 455 | | |
454 | 456 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Lines changed: 138 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
Lines changed: 0 additions & 15 deletions
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
| |||
0 commit comments