Skip to content

test: comprehensive coverage for indefinite-length CBOR map support (#23)#24

Merged
leopoldjoy merged 5 commits into
mainfrom
test/indefinite-length-cbor
Mar 30, 2026
Merged

test: comprehensive coverage for indefinite-length CBOR map support (#23)#24
leopoldjoy merged 5 commits into
mainfrom
test/indefinite-length-cbor

Conversation

@leopoldjoy

Copy link
Copy Markdown
Contributor

Summary

Adds 23 tests across 2 test contracts covering the indefinite-length CBOR changes introduced in #23 (ai==31 handling in CborDecode.sol and 0xFF break marker detection in NitroValidator.sol).

Tests

CborDecode-level (7 tests):

  • Indefinite-length map and array parsing (ai==31 returns value=0)
  • Reserved AI 28/29/30 revert correctly (not swallowed by the new ai==31 branch)
  • Definite-length regression baselines

NitroValidator-level (16 tests):

  • Synthetic data: definite vs indefinite equivalence, reordered keys
  • Real AWS attestation data (4441 bytes, 16 PCRs, 4-cert cabundle, non-null public_key) with 20 embedded 0xFF bytes in DER-encoded certificate content — verifies the break-marker check doesn't false-trigger on content bytes
  • Converter verification: independently validates _toIndefiniteLength helper output (length, break byte, map header, bstr length, content preservation)
  • Edge cases: empty indefinite map, early break termination, 0xFF value bytes immediately before the break marker
  • Inner indefinite-length structures: documents that an empty indefinite-length inner map's 0xFF break triggers the outer loop's break check (silent early termination) — safe for real attestations since AWS always uses definite-length inner structures
  • Negative: missing break marker reverts, unknown keys revert, non-empty indefinite inner array reverts

Notes

  • Test helper _toIndefiniteLength() programmatically converts any definite-length TBS to indefinite-length, avoiding hand-maintained duplicate test data
  • Named constants for all CBOR markers and expected values; shared assertion helpers to reduce duplication
  • Real attestation hex sourced from existing NitroValidator.t.sol

U0001F3A2 and others added 5 commits February 26, 2026 14:27
Real AWS Nitro attestation documents use indefinite-length CBOR maps (0xBF)
which were not supported. Added ai==31 handling in CborDecode and 0xFF
break-marker detection in NitroValidator's map parsing loop.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover the two changes in the fix PR: ai==31 handling in CborDecode.sol
and 0xFF break marker detection in NitroValidator.sol.

18 new tests across 2 contracts:
- CborDecodeIndefiniteLengthTest: 7 tests for mapAt/arrayAt with
  indefinite-length, definite-length regression, and reserved AI reverts
- NitroValidatorIndefiniteLengthTest: 11 tests covering synthetic and
  real AWS attestation data, indefinite/definite equivalence, edge cases
  (empty map, early break), and negative cases (unknown keys)

Real attestation data exercises 20 embedded 0xFF bytes in DER-encoded
certificate content, verifying the break-marker check does not
false-trigger on content bytes.
5 new tests covering gaps identified in test coverage review:

1. test_neg_missingBreakMarker_reverts: indefinite-length map without
   trailing 0xFF — parser reads into garbage and reverts
2. test_converter_structurallyCorrect: independently verify that
   _toIndefiniteLength produces correct output (length, break marker,
   map header, bstr length, preserved content)
3. test_edge_certValueContainingFF_beforeBreak: byte-string value
   containing 0xFF immediately before the break marker — verifies
   break check examines header positions, not value content
4. test_edge_innerIndefinitePcrsEmpty_outerBreakTriggered: empty
   indefinite-length inner PCRs map — documents that the inner 0xFF
   break marker triggers the outer loop's break check, causing silent
   early termination of remaining entries
5. test_neg_nestedIndefiniteNonEmptyArray_reverts: non-empty
   indefinite-length inner array — inner elements are not consumed,
   causing type mismatch revert
The individual definite/indefinite tests already verify all fields
against expected constants, making the explicit field-by-field
comparison tests logically redundant. Removes test_synth_indefiniteMatchesDefinite,
test_real_indefiniteMatchesDefinite, and the now-unused _assertPtrsMatch helper.
Per RFC 8949, indefinite-length encoding is only defined for major
types 4 (array) and 5 (map). Other major types with ai=31 (e.g. 0x5F
indefinite byte string, 0x7F indefinite text, 0x1F reserved) are not
supported by this decoder. Downstream validation in validateAttestation()
would catch these cases regardless, but rejecting here gives an
immediate, unambiguous revert rather than a confusing downstream failure.

@robriks robriks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

The require(_type == 0xa0 || _type == 0x80, ...) guard in CborDecode.elementAt is a meaningful improvement over the original fix — without it, a crafted attestation containing an indefinite-length byte/text string (0x5F/0x7F) would have silently been treated as an empty string, potentially bypassing certificate and key length checks in validateAttestation.

Test coverage is thorough 👍

@leopoldjoy leopoldjoy merged commit 75c1145 into main Mar 30, 2026
5 checks passed
@leopoldjoy leopoldjoy deleted the test/indefinite-length-cbor branch March 30, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants