Skip to content

Commit

Permalink
LVS: Fix temporary tag IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Oct 25, 2024
1 parent 02e70bc commit 8143b5f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
18 changes: 9 additions & 9 deletions docs/src/lvs/binary-format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ Every node has an integer ID, which equals to the index it occurs in the LVS mod
In current compiler implemented in python-ndn, it is ``0`` to indicate that the first Node is the root,
but there is no guarantee in future and a checker should not rely on this convention.

Every pattern edge is also assigned with a number.
If the number is lower than ``NamedPatternCnt``, then it is a named pattern edge.
If it is larger than or equal to ``NamedPatternCnt``, then it is a temporary named pattern ``_``.
Every pattern edge is also assigned with a number, which starts from ``1``.
If the number is lower than or equal to ``NamedPatternCnt``, then it is a named pattern edge.
If it is larger than ``NamedPatternCnt``, then it is a temporary named pattern ``_``.
Note that since TLV encoding does not support negative numbers, we use ``NamedPatternCnt`` to differentiate temporary and normal named patterns.
A checker does not need to tell whether a pattern edge is named or not,
if it only checks the signature validity, since every temporary pattern edge is assigned with a different tag.
if it only checks the signature validity, since every occurrence of a temporary pattern edge is assigned with a different tag.
Tag symbol information is only needed if the checker needs the name identifiers of named patterns.

``TagSymbol`` describes the identifiers for each named pattern edge.
It is ununsed and can be safely discarded if a checker does not dump error reason after verification fails.
It is unused and can be safely discarded if a checker does not dump error reason after verification fails.
The TLV-Type is still marked as critical for sanity check reason expressed in the next section.

Node
Expand All @@ -119,13 +119,13 @@ Node
``NodeId`` always equal to the index it occurs in the LVS model, starting from ``0``.

``RuleName`` is the identifier used to identify this node in the original LVS schema.
It is ununsed if a checker does not dump error reason after verification fails.
It is unused if a checker does not dump error reason after verification fails.

``ValueEdge`` and ``PatternEdge`` are edges to children under its subtree.
A ``ValueEdge`` requests an exact match; a ``PatternEdge`` specifies a match of a constraint set,
and assigns the component value to the corresponding pattern variable.
A checker must always check ``ValueEdge`` for exact matches before it uses ``PatternEdge`` to match.
When multiple ``PatternEdge`` can match, the first one occuring in the file should hit.
When multiple ``PatternEdge`` can match, the first one occurring in the file should hit.

``SignConstraint`` indicates zero or more node IDs.
When a packet name matches the current node, the signing key should match one of the nodes specified by ``SignConstraint``.
Expand Down Expand Up @@ -164,7 +164,7 @@ The following sanity checks are recommended but not required.

- After the application finishes providing user functions, check all user functions used in the programs are given.

+ If the implementation chooses not to do so, it should let the verifcation fail whenever an unknown user function is triggered.
+ If the implementation chooses not to do so, it should let the verification fail whenever an unknown user function is triggered.

- After the application finishes providing trust anchors, check all roots of signing constraint are provided with a trust anchor.

Expand All @@ -173,7 +173,7 @@ The following sanity checks are recommended but not required.
* (a) specified as a signing constraint of another node, and
* (b) a node without any signing constraint attached to it

+ If the implementation chooses not to do so, it should let the verifcation fail whenever reaches a leaf node without sign constraint.
+ If the implementation chooses not to do so, it should let the verification fail whenever reaches a leaf node without sign constraint.

- *[Optional]* No unreachable nodes from the tree root. (python-ndn does not check this)

Expand Down
8 changes: 8 additions & 0 deletions docs/src/lvs/demonstration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ Therefore, no rule replication is needed.
Generating tree
~~~~~~~~~~~~~~~

.. warning::
The figures in this page are out-of-dated. Unfortunately I am not able to fix them now.
Please check with the actual result of code.
More specifically, note the following things:

- There is a ``#KEY`` branch attach to the root, which is omitted in the figure.
- Temporary pattern edges do not share tag IDs.

.. image:: /_static/lvs-ptree.svg
:align: center
:width: 100%
Expand Down
6 changes: 5 additions & 1 deletion src/ndn/app_support/light_versec/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Compiler:
named_pats: dict[str, str]
node_pool: list[bny.Node]
rule_node_ids: dict[str, list[int]]
temp_tag_index: int = 0

@dataclass
class RuleChain:
Expand Down Expand Up @@ -292,7 +293,9 @@ def _generate_node(self, depth: int, context: list[RuleChain], parent: Optional[
edge.tag = tag
else:
# TLV integer is required to be unsigned, so we use maximum named pattern + x for temporary pattern -x
edge.tag = len(self.named_pats) - tag
self.temp_tag_index += 1
edge.tag = self.temp_tag_index
# edge.tag = len(self.named_pats) - tag
edge.cons_sets = next(pm[1] for pm in p_moves if pm[2] == pm_str)
edge.dest = self._generate_node(depth + 1, new_context, node.id, previous_tags | {tag})
node.p_edges.append(edge)
Expand Down Expand Up @@ -323,6 +326,7 @@ def compile(self) -> bny.LvsModel:
sorted_rep_rules = list(self.rep_rules.items())
sorted_rep_rules.sort(key=lambda tup: tup[0])
rule_chains = sum([v for (k, v) in sorted_rep_rules], start=[])
self.temp_tag_index = len(self.named_pats)
start_node = self._generate_node(0, rule_chains, None, set())
self._fix_signing_references()
ret = bny.LvsModel()
Expand Down

0 comments on commit 8143b5f

Please sign in to comment.