Nested generic rules get the wrong argument when the outer rule is instantiated more than once
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- devtools
Research direction
Start by reproducing with the nested.cddl schema and value.cbor (82 81 82 00 01 81 82 00 61 61) using cuddle validate-cbor root value.cbor nested.cddl -f binary. The trace labels the nested instance %inner<x> instead of the substituted argument, so look at how generic rule arguments are substituted and how instances are named and shared during validation. Done when the reproducer prints Validation successful and the existing controls in the table still behave the same.
Written by the indexing model from the issue text.
Description
Summary
When a generic rule passes its parameter on to another generic rule, and the
outer rule is instantiated more than once in the same file with different
arguments, validate-cbor checks the nested rule with the argument of a
different instantiation. Valid CBOR is then rejected.
The validation trace suggests why: the nested instance is labelled with the
outer rule's formal parameter name (%inner<x>) rather than with the
substituted argument (%inner<int>, %inner<tstr>), so all instantiations of
the outer rule seem to share one nested instance.
Version: cuddle 1.8.1.0.
Reproducer
nested.cddl:
root = [a, b]
a = outer<int>
b = outer<tstr>
outer<x> = [inner<x>]
inner<y> = [0, y]
value.cbor is [[[0, 1]], [[0, "a"]]], which matches root:
82 81 82 00 01 81 82 00 61 61
$ cuddle validate-cbor root value.cbor nested.cddl -f binary
array
└ failed to apply required rule:
└ ref: a
└ ref: %outer<int>
└ array
└ failed to apply required rule:
└ ref: %inner<x>
└ array
└ 1 valid elements
failed to apply required rule:
└ failed to apply:
text
Validation failed
Inside a = outer<int>, the nested inner<x> is checked against text, the
argument of the other instantiation (b = outer<tstr>), so the integer 1 is
rejected.
Expected
Validation successful: a is [[0, int]] and b is [[0, tstr]].
Controls
All against [[[0, 1]], [[0, "a"]]] unless noted:
| Variant | Result |
|---|---|
As above (outer instantiated twice, nested generic inner) |
fails |
Only one instantiation (root = a, value [[0, 1]]) |
passes |
outer inlined, no nested generic: outer<x> = [[0, x]] |
passes |
Definitions of a and b in the opposite order |
fails the same way |
root = [b, a] with value [[[0, "a"]], [[0, 1]]] |
fails the same way (%outer<int> → %inner<x> → text) |
inner's parameter also named x (inner<x> = [0, x]) |
fails |
So it takes two instantiations of the outer rule, and the order of the rules
or of the elements doesn't matter. cuddle validate nested.cddl accepts the
schema without complaint.
Where we hit it
ouroboros-consensus describes hard-fork-combinator state with
telescope8<byron, shelley, ..., dijkstra>
= [pastEra, ..., currentEra<dijkstra>] / ...
currentEra<st> = [bound, st]
and uses telescope8 several times in the same file (for the ledger state and
for the chain-dependent state), which has the same shape as the reproducer:
the generic telescope8 passes its parameters on to the generic currentEra.
Valid snapshots were rejected until we worked around it by writing
currentEra<st> out inline as [bound, st] inside telescope8.
- Dominant language
- Haskell
- Stars
- 8
- Forks
- 5
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from IntersectMBO/cuddle
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cuddle#168 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
IntersectMBO/cuddle#167 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
IntersectMBO/cuddle#166 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 43/100
IntersectMBO/cuddle#223 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
IntersectMBO/cuddle#217 ·
All issues in IntersectMBO/cuddle
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-ledger#6276 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenZeppelin/canton-contracts#92 ·
Maintainers usually reply within 1 day