qd: emit the same_kind assert_norm in the Pulse sum/dsum readers - #324
Merged
Conversation
331a411 added assert_norm (LP.parse_sum_kind (LP.get_parser_kind <tn>_repr_parser) <n>_sum parse_<n>_cases == <n>_parser_kind); to the Pulse payload accessors, the Unknown payload accessor and write_<n>, for both sums and dsums, but not to the copyful readers read_<n>_sum. They need it for the same reason: after FStarLang/FStar#4519 ("Encode prop like bool, with boxing to SMT Bool") a prop-valued definition only gets the formula equation `Valid (f x) <==> body`, so a goal of the form pts_to_parsed_prop p1 w v == pts_to_parsed_prop p2 w v can no longer be closed by unfolding both sides and has to go through congruence on the parser arguments instead. Without the assert_norm, read_<n>_sum can fail its own ascription with - Subtyping check failed - Expected type LowParse.PulseParse.Base.copyful_parse (...) handshake_parser (...) got type LowParse.PulseParse.Base.copyful_parse (...) (LowParse.Spec.Sum.parse_sum handshake_sum LowParse.Spec.Int.parse_u8 parse_handshake_cases) (...) - The SMT solver could not prove the query. Note this is an incompleteness, not a timeout, so raising the rlimit does not help. The existing qd tests do not reproduce: for the small sums there, Z3 still finds the congruence unaided. It shows up on the 9-case Handshake sum and the Extension* sums of the TLS 1.3 RFC in project-everest/mitls-fstar, where all six affected modules verify again with this change. `make -C share/everparse/tests/qd` is unaffected: 385 modules verify, and the only output change is the new assert_norm line in the seven modules that have a copyful owned sum or dsum reader (T6, T6le, T16_x, T17, T18, T22 and, for the dsum path, T7). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
331a41199added the kind equationto the Pulse payload accessors, the Unknown payload accessor and
write_<n>, for both sums and dsums. The copyful readersread_<n>_sumwere missed, and they need it for exactly the same reason.After FStarLang/FStar#4519 ("Encode prop like bool, with boxing to SMT Bool") a prop-valued definition only gets the formula equation
Valid (f x) <==> body; the term equation is no longer emitted, since the new encoding is extensional. So a goal of the formcan no longer be discharged by unfolding both sides, and has to go through SMT congruence on the parser arguments instead — which is what the
assert_normenables.Without it,
read_<n>_sumcan fail its own ascription:Note this is
The SMT solver could not prove the query(all-incomplete), not a timeout — raising the rlimit does not help.Fix
same_kindis already in scope at both reader emission sites, so this is a two-line change mirroring whatwrite_<n>already does: insert%sright after the=\nof the ascription and passsame_kindas the 11th argument, inemit_copyful_owned_sumandemit_copyful_owned_dsum.Why the existing tests did not catch it
They do not reproduce the failure: for the small sums in
unittests.rfc, Z3 still finds the congruence unaided. It shows up on the 9-caseHandshakesum and theExtension*sums of the TLS 1.3 RFC in project-everest/mitls-fstar, where all six affected modules verify again with this change.I did not add a regression test here because reproducing it needs a sum large enough to defeat Z3's unaided search, which would be a fairly brittle test. Happy to add one if you'd prefer.
Validation
make -C share/everparse/tests/qd— 385 modules verify, 0 F* errors, no change in behaviour.assert_normline in the seven modules that have a copyful owned sum or dsum reader:T6,T6le,T16_x,T17,T18,T22, and for the dsum pathT7. For example, inT7.fst:let read_t7_sum : PPB.copyful_parse (PPS.vmatch_dsum t7_sum t7_low t7_tag_of_low t7_mid_of_tag t7_casevmatch) t7_parser (PPS.dsum_conv t7_sum t7_mid_of_tag t7_conv_of_tag) = + assert_norm (LP.parse_dsum_kind (LP.get_parser_kind tag2_repr_parser) t7_sum parse_t7_cases (LP.get_parser_kind t2_parser) == t7_parser_kind); PPS.copyful_parse_dsum t7_sum read_maybe_tag2_key tag2_repr_jumper parse_t7_casesmake verify,make verify-samplesand the full test suite of project-everest/mitls-fstar are clean at EverParseac626cd45.