Trace Terminology

Table of Contents
  1. NotationΒ§1
    1. Trace SemanticsΒ§2
      1. Semantic Program PropertiesΒ§3
        1. Bounded PropertiesΒ§3.1
        2. Program AnalysesΒ§4
          1. Soundness and CompletenessΒ§4.1
            1. Duality of AnalysesΒ§4.2
              1. Warnings vs PositivesΒ§4.3
                1. Bounded AnalysesΒ§4.4

                This is a short overview of the terminology we use in this class. We know that it is somewhat inconsistent between the lectures, but we hope to clean it up over time.

                Notation Β§1

                Before we get started, we need to introduce some basic notation. We use capital letters I and A to indicate sets, and small letters a and b to be elements of those sets.

                We use small p and q to indicate programs.

                Trace Semantics Β§2

                A Transition System

                A Transition system is a triplet βŸ¨π’π­πšπ­πžp,Ξ΄p,Ip⟩ where π’π­πšπ­πžp is the set of program states, Ξ΄p is the transition relation (defined by the single step semantics) and Ip are possible initial states.

                A trace is now the sequences of states that a program traverse during execution.

                Trace

                The traces of a program p is a sequence of states π“π«πšπœπžpβŠ†π’π­πšπ­πžpn for n∈[1,∞]. We use Ο„ to refer to individual traces. We sometimes index the traces like so Ο„i, where Ο„0 is the initial state.

                We define the semantics a program to be the set of traces which we can generate from the transition system. This is also known as the Maximal Trace Semantics.

                Maximal Trace Semantics

                Sem:ππ«π¨π π«πšπ¦β†’2π“π«πšπœπžSem(p)={Ο„βˆˆπ’π­πšπ­πžpnΒ |Β n∈[1,∞],Ο„0∈Ip,βˆ€i∈[1,nβˆ’1],Ξ΄p(Ο„iβˆ’1,Ο„i)}

                Semantic Program Properties Β§3

                Using the trace semantics, we can now talk about properties of programs. When the property is generic we use capital letters Q and R, but when we are talking about a concrete property we use πš˜πš” okay or πšŽπš›πš› error.

                We differentiate between two kinds of properties, may-properties, and must-properties. A may property is true for one trace, while a must property is true for all traces.

                May Property

                A may-property is true for at least one trace in the program: pβŠ¨π—†π–Ίπ—’Qβ‰‘βˆƒΟ„βˆˆSem(p).Q(Ο„)

                Must Property

                A must-property is true for all traces in the program: pβŠ¨π—†π—Žπ—Œπ—Qβ‰‘βˆ€Ο„βˆˆSem(p).Q(Ο„)

                Interestingly, if we negate the property of a may analysis we get a must analysis and visa-versa.

                Β¬(pβŠ¨π—†π–Ίπ—’Q)β‰‘Β¬βˆƒΟ„βˆˆSem(p).Q(Ο„)β‰‘βˆ€Ο„βˆˆSem(p).Β¬Q(Ο„)≑pβŠ¨π—†π—Žπ—Œπ—Β¬Q

                Bounded Properties Β§3.1

                Sometimes we talk about properties which are bounded by some depth k. In this world we only look at traces shorter than k states.

                Bounded Trace Semantics

                Semk:ππ«π¨π π«πšπ¦β†’2π“π«πšπœπžSemk(p)={Ο„βˆˆπ’π­πšπ­πžpnΒ |Β n∈[1,k],Ο„0∈Ip,βˆ€i∈[1,nβˆ’1],Ξ΄p(Ο„iβˆ’1,Ο„i)}

                In this world, we can also talk about may and must properties p,kβŠ¨π—†π—Žπ—Œπ—Q and p,kβŠ¨π—†π–Ίπ—’Q. Which claims that Q is true for one or all traces smaller than size k in p.

                Program Analyses Β§4

                Program analysis is an automatic procedure that attempts to determine a property about a program. Since an analysis 𝐀 is tailor-made to predict a specific may property Q, we write it like so pβŠ’π€π—†π–Ίπ—’Q, and we write a must property Q as pβŠ’π€π—†π—Žπ—Œπ—Q.

                Soundness and Completeness Β§4.1

                Since program analysis is undecidable, it is in general impossible for an analysis to perfectly match the true property of the code; therefore, we approximate it.

                A common confusion in program analysis is that static analyses accept or reject properties over programs, where dynamic analyses accept and reject properties over traces.

                This has consequences over what they consider sound and complete.

                A sound analysis is never wrong:

                Soundness

                In a sound system, every proved fact is a true fact. Any property found by a sound analysis is true.

                pβŠ’π€π—†π—Žπ—Œπ—Q⟹pβŠ¨π—†π—Žπ—Œπ—QpβŠ’π€π—†π—Žπ—Œπ—Q⟹pβŠ¨π—†π–Ίπ—’Q

                A static analysis focuses on properties over all traces: must properties. So when we say a static analysis is sound, it is must sound. A dynamic analysis focuses on properties over some traces, may properties, so when we say it is sound it is may sound.

                When we use the notation pβŠ’π€π—†π—Žπ—Œπ—Q or pβŠ’π€π—†π–Ίπ—’Q you can assume that they imply pβŠ¨π—†π—Žπ—Œπ—Q and pβŠ¨π—†π–Ίπ—’Q respectively.

                If a may analysis finds that a program raises a null-pointer exception for some trace, then there exist a trace that raises a null-pointer exception.

                If a must analysis finds that the program must raise a null-pointer exception, then the program will raise a null-pointer exception on all traces.

                The other side of the coin is completeness. A complete analysis never misses a property. To clearly differentiate the sound analyses from the complete ones, we use not-must and not-may instead, to indicate that the analysis tries to under approximate a property.

                Completeness

                In a complete system, every true fact can be proved. All false properties can be rejected by a complete analysis.

                pβŠ¨π—†π–Ίπ—’Q⟹pβŠ’π€Β¬π—†π–Ίπ—’QpβŠ¨π—†π—Žπ—Œπ—Q⟹pβŠ’π€Β¬π—†π—Žπ—Œπ—Q

                When we use the notation pβŠ’π€Β¬π—†π—Žπ—Œπ—Q or pβŠ’π€Β¬π—†π–Ίπ—’Q you can assume that they are implied by pβŠ¨π—†π—Žπ—Œπ—Q and pβŠ¨π—†π–Ίπ—’Q respectively.

                If a program raise a null-pointer exception for any trace, a not-may analysis will find the that the program can raise a null-pointer exception on some trace.

                If a program raise a null-pointer exception on all traces (must), a not-must analysis will find the program raises null-pointer exception on all traces.

                An analysis can be sound or complete, but never both.

                Duality of Analyses Β§4.2

                Recall that it is generally true that a may property is an inverted must property:

                Β¬(pβŠ¨π—†π–Ίπ—’Q)≑pβŠ¨π—†π—Žπ—Œπ—Β¬Q

                This is also the case for program analyses, any complete may analysis can be made into a sound must analysis over the negated property:

                Β¬(pβŠ’π€Β¬π—†π–Ίπ—’Q)≑pβŠ’π€π—†π—Žπ—Œπ—Β¬Q

                We can see this quite clearly. If take the completeness requirement, and flip the implication by negating on both sides:

                pβŠ¨π—†π–Ίπ—’Q⟹pβŠ’π€Β¬π—†π–Ίπ—’QΒ¬(pβŠ¨π—†π–Ίπ—’Q)⟸¬(pβŠ’π€Β¬π—†π–Ίπ—’Q)

                Now by using the rule above we see that Β¬(pβŠ’π€Β¬π—†π–Ίπ—’Q) implies pβŠ¨π—†π—Žπ—Œπ—Β¬Q, which means that Β¬(pβŠ’π€Β¬π—†π–Ίπ—’Q) is a sound must analysis.

                Warnings vs Positives Β§4.3

                It is common to use the terminology of false/true positives/negatives, when referring to a classifier. However, this is confusing when referring to program analysis as it unclear if we are referring to classification over programs (must analyses and not-may analyses) or classification over traces (may analyses and not-must analyses).

                To clear up this confusion, we use warnings to refer to specific bugs reported in the program, essentially classification over traces.

                A sound static analysis might produce false warnings, where a sound dynamic analysis will never produce false warnings.

                Bounded Analyses Β§4.4

                Like with our semantics we can bound our analyses, for example we can write βŠ’π€π—†π—Žπ—Œπ—/k, and βŠ’π€π—†π–Ίπ—’/k.

                However, generally a bounded must analysis is not a must analysis,

                p,kβŠ’π€π—†π—Žπ—Œπ—Q⟹̸pβŠ’π€π—†π—Žπ—Œπ—Qbecausep,kβŠ¨π—†π—Žπ—Œπ—Q⟹̸pβŠ¨π—†π—Žπ—Œπ—Q

                and a bounded not-may analysis is not a not-may analysis:

                p,kβŠ’π€Β¬π—†π–Ίπ—’Q⟸̸pβŠ’πΒ¬π—†π–Ίπ—’becausep,kβŠ¨π—†π–Ίπ—’Q⟸̸pβŠ¨π—†π–Ίπ—’Q