verified-network-toolchain / petr4

Petr4: Formal Semantics for P4
Apache License 2.0
74 stars 20 forks source link

Problems with semantics for headers and header unions #287

Closed QinshiWang closed 2 years ago

QinshiWang commented 2 years ago

There are some problems with semantics for headers and header unions.

  1. The comment about write_header_field_undef is wrong. write_header_field_undef is needed. Consider the case
    a[n].x = y;

    for out-of-bounds n. The execution relation is constructed by (let us use expressions like (a[n].x) to denote values)

    exec_write (a[n].x) y
    exec_read (a[n]) (ValBaseHeader unit_fields None)
    update_member (ValBaseHeader unit_fields None) "x" y (ValBaseHeader unit_fields None)
    exec_write (a[n]) (ValBaseHeader unit_fields None)

    write_header_field_undef is needed to complete this write.

  2. write_header_field_invalid and write_header_field_undef are unfriendly with (abstract) symbolic execution, it's better to set uninitialized fields instead of doing nothing.
  3. update_union_member violates the global invariant that invalid headers must have initialized fields. That's violated by https://github.com/verified-network-toolchain/petr4/blob/poulet4/deps/poulet4/lib/Semantics.v#L1093 and https://github.com/verified-network-toolchain/petr4/blob/poulet4/deps/poulet4/lib/Semantics.v#L1095.