Lectures onType Theory
Chapter 136
Chapter 136Optional

Secure Compilation and Robust Property Preservation

Prerequisites. Direct starred prerequisites: Chapter 134. No later core chapter depends on this route.

A semantics-preservation theorem quantifies over whole programs. Compile a component instead, and link it with a context, and the theorem is silent unless the context is the image of a source context.

Here is what that silence costs. Let a source language have a partial program that receives a boolean or a natural from its context and outputs a natural, and let the target have only naturals, with true and false compiled to 0 and 1. Compile P=f(x:Bool)e to P = f(x:Nat)if x<2 then e else if x<3 then f(x) else 42. On an input a source context could have produced — 0 or 1 — the compiled function runs the compiled body. On the input 2 it diverges, and on every larger input it outputs 42, whatever P was. A whole-program correctness theorem is untouched: no whole source program ever supplies 2. A user linking P with untrusted target code has lost every guarantee P had.

The question this chapter answers is what a compiler must satisfy so that a property of the source component survives linking with an arbitrary target context, and how the resulting criteria are related to each other and to full abstraction. The development follows Abate, Blanco, Garg, Hriţcu, Patrignani and Thibault (2019).

The setting

Definition 136.1 — Programs, contexts, traces

A partial program P is linked with a context C to form a whole program C[P]. Write CS for source contexts, CT for target contexts, and P for the compilation of P. Fix a set Trace of traces, each recording the observable events of one execution, together with a set of finite prefixes ordered by mt (“m is a prefix of t”). Write C[P]t when the whole program C[P] can produce the trace t, and C[P]m when it can produce a finite prefix m.

Definition 136.2 — Properties and behaviours

A trace property is a set πTrace. A hyperproperty is a set H of sets of traces. The behaviour of a whole program is Behav(W)={tWt}; the program satisfies H when Behav(W)H.

The distinction is the one that makes the chapter necessary. A trace property is satisfied or violated by one execution; a hyperproperty may require comparing two, as noninterference does.

Robust preservation of trace properties

Definition 136.3 — Robust trace property preservation

A compilation chain satisfies RTP when for every πTrace and every partial program P, (CS,t. CS[P]ttπ)(CT,t. CT[P]ttπ).

Definition 136.3 quantifies over all properties, which makes it awkward to prove for a particular compiler. It has an equivalent statement that mentions no property at all.

Definition 136.4 — Property-free characterization

A compilation chain satisfies RTC when P,CT,t.CT[P]tCS. CS[P]t.

Theorem 136.5 — RTP and RTC are equivalent

RTP holds if and only if RTC holds.

Proof of Theorem 136.5 — RTP and RTC are equivalent

Proof. The mechanism is worth naming once, because every other equivalence in this chapter uses it: from RTP to RTC one instantiates the universally quantified property with the strongest property the source program robustly satisfies; from RTC to RTP one uses the produced source context to transport the hypothesis.

RTPRTC. Fix P, and apply RTP to the property π0={tCS. CS[P]t}. Its hypothesis is CS,t. CS[P]tCS. CS[P]t, which holds by taking CS=CS. Its conclusion is CT,t. CT[P]ttπ0, and tπ0 is by definition the existence of a source context producing t. That is RTC.

RTCRTP. Fix π and P and assume CS,t. CS[P]ttπ. Take any CT and t with CT[P]t. By RTC there is CS with CS[P]t, and (136.1) instantiated at that CS and t gives tπ. ◻

Theorem 136.5 is what makes the criterion usable: to establish RTP one exhibits, for each target context, a source context that explains the same trace. Constructing that source context is called back-translation, and section 136.6 describes the two shapes it takes.

Safety, density, and their criteria

Definition 136.6 — Safety and dense properties

Safety={πtπ. mt. tm. tπ},Dense={πevery terminating t lies in π}.

A safety property is refuted by a finite prefix: once the bad prefix has occurred, no continuation repairs it. A dense property can be refuted only by an infinite trace, and plays here the role liveness plays elsewhere.

Definition 136.7 — The two criteria

RSP and RDP are definition 136.3 with π restricted to Safety and to Dense respectively. RSC is P,CT,m. CT[P]mCS. CS[P]m, quantifying over finite prefixes; RDC is definition 136.4 with t restricted to infinite traces.

Theorem 136.8 — Both characterizations are equivalent to their criteria

RSP holds if and only if RSC does, and RDP holds if and only if RDC does.

Proof of Theorem 136.8 — Both characterizations are equivalent to their criteria

Proof. RSPRSC. Fix P and a finite prefix m0 with CT[P]m0, and suppose no source context produces m0. Put π1={tm0t}. Then π1Safety: if tπ1 then m0t, and every tm0 also fails π1, so m0 is the required bad prefix. The hypothesis of RSP at π1 holds, since a source context producing some tm0 would produce the prefix m0, contrary to assumption. Its conclusion applied to the target trace extending m0 gives a trace in π1 that has m0 as a prefix, a contradiction. So some source context produces m0.

RSCRSP. Fix πSafety, P satisfying (136.1), a target context CT and a trace t with CT[P]t; suppose tπ. Safety gives a bad prefix mt with every extension outside π. Since CT[P] produces t, it produces m, so RSC gives CS with CS[P]m. Extend: CS[P] produces some tm, and (136.1) puts tπ, contradicting the choice of m. Hence tπ.

RDPRDC. The same two moves with π0 replaced by π2={tt terminating}{tCS. CS[P]t}, which is dense by construction, and with the observation that a dense property is violated only by a non-terminating trace, so only infinite traces need explaining. ◻

Theorem 136.9 — Decomposition

Every trace property is the intersection of a safety property and a dense property.

Proof of Theorem 136.9 — Decomposition

Proof. Let π be arbitrary. Put S(π)={tmt. tm. tπ} and D(π)=π{ttS(π)}.

S(π) is safety: if tS(π) there is mt with no extension in π; every tm then also has m as a prefix with no extension in π, so tS(π).

D(π) is dense once terminating traces are read as those with a maximal finite prefix: a terminating t either lies in π or has a prefix with no extension in π, and in the second case tS(π), so tD(π).

Finally S(π)D(π)=π. For : if tS(π) and tD(π), the second gives tπ or tS(π), and the first excludes the alternative. For : tπ gives tD(π) immediately, and tS(π) because every prefix of t extends to t itself. ◻

Theorem 136.9 says that RSP and RDP together are not weaker than RTP for a fixed property — the property splits — but it does not say that the two criteria imply RTP, because the hypothesis of RTP at π does not give the hypotheses at S(π) and D(π) separately.

Exercise 136.1

★★☆ Exhibit π, a program P and a source context showing that “P robustly satisfies π” does not imply “P robustly satisfies S(π) and P robustly satisfies D(π)” — or prove that it does. State which direction of theorem 136.9 your answer uses.

Hyperproperties

Definition 136.10 — Robust hyperproperty preservation

RHP holds when for every hyperproperty H and every P, (CS. Behav(CS[P])H)(CT. Behav(CT[P])H). Its characterization RHC is P,CT. CS. Behav(CT[P])=Behav(CS[P]). RSCHP restricts H to the subset-closed hyperproperties SC={Hb1b2Hb1H}, and its characterization RSCHC replaces the equality above by t. CT[P]tCS[P]t.

Theorem 136.11

RHPRHC and RSCHPRSCHC.

Proof of Theorem 136.11

Proof. RHPRHC. Fix P and apply RHP to H0={bCS. b=Behav(CS[P])}, whose hypothesis holds by taking the same context. The conclusion says that every target context’s behaviour is some source context’s behaviour, which is RHC.

RHCRHP. Given H, P with Behav(CS[P])H for all CS, and any CT, RHC supplies CS with equal behaviour, so Behav(CT[P])H.

The subset-closed pair is the same argument with H1={bCS. bBehav(CS[P])}, which is subset-closed, in place of H0; the conclusion then gives an inclusion rather than an equality, and in the converse direction subset-closure of H is what turns the inclusion supplied by RSCHC into membership. ◻

Remark 136.12 — Why the behaviour is per context

Behav in definition 136.10 is the set of traces produced when linked with one context, not the union over all contexts. With the union the criterion would be strictly weaker: a compiler could add a target context whose behaviour is not any source context’s, as long as the union is unchanged.

Full abstraction is a different criterion

Definition 136.13 — Observational equivalence preservation

OEP holds when P1ctxP2 implies P1ctxP2, where ctx is contextual equivalence. It is the security-relevant half of full abstraction.

For determinate languages contextual equivalence coincides with equality of the trace sets produced in all contexts, so OEP coincides with robust preservation of trace equivalence. How that criterion relates to the ones above it is not what one might expect, and the next theorem settles one direction.

Theorem 136.14 — Full abstraction does not imply robust safety preservation

There is a compiler between two deterministic languages that satisfies OEP and is correct — it preserves whole-program behaviour and compiles separately — and does not satisfy RSP.

Proof of Theorem 136.14 — Full abstraction does not imply robust safety preservation

Proof. The compiler is the one displayed in the opening. Source partial programs take a boolean or a natural from the context and output naturals; the target has only naturals; true and false compile to 0 and 1; and a boolean-accepting P=f(x:Bool)e compiles to P↓=f(x:Nat)if x<2 then e else if x<3 then f(x) else 42.

Correctness. A whole source program supplies only true or false, hence only 0 or 1, so the first branch is taken and the compiled program runs e. Compilation is compositional in the function definitions, so separate compilation holds.

OEP. Let P1 and P2 be contextually equivalent source programs. A target context can feed P1 and P2 an input below 2, where both behave as the corresponding source programs under the corresponding source context and are therefore indistinguishable; the input 2, where both diverge; or an input above 2, where both output 42. In every case the two compiled programs agree, so they are contextually equivalent.

Failure of RSP. Take P=f(x:Bool)0 and the safety property π={tt contains no output 42}. Every source context linked with P produces the single output 0, so P robustly satisfies π. The target context supplying 3 makes P output 42, violating π. Hence RSP fails. ◻

Theorem 136.14 is the reason the chapter’s criteria are not a reformulation of full abstraction. Full abstraction constrains only which programs the target can distinguish; it permits the compiled program to do anything at all, provided it does the same anything to equivalent programs.

Theorem 136.15 — A converse, under hypotheses; imported

Assume the source language is determinate and the target has a determinate, input-total small-step semantics. Then robust preservation of two-relational relaxed safety implies robust trace-equivalence preservation, and hence OEP.

This is Theorem 5.1 of the frozen source, with the mechanized proof in its Coq development. It is imported at exactly those hypotheses: determinacy of both languages, input totality of the target — if the target accepts one input value it accepts every other — and the property, also proved there, that a whole program producing every finite prefix of an infinite trace produces that trace. Nothing weaker is claimed, and no direction of theorem 136.14 is affected by it.

Remark 136.16 — When the hierarchy collapses

If the source language has full reflection — a context can obtain complete intrinsic information about the program it is linked with — then RHP implies its two-relational strengthening, and several other levels collapse. The construction is short: given target context CT, apply RHC once to P1 and once to P2, obtaining unrelated CS1 and CS2, then use reflection to build one source context that inspects its argument and behaves as CS1 on P1 and as CS2 otherwise. The collapse is a property of the source language, not of the compiler, and it does not touch criteria whose relations have infinite arity.

Exercise 136.2

★★☆ Show that RHC implies OEP for determinate languages, and then say precisely which step of your argument fails if one tries to run it backwards to derive RHC from OEP.

Exercise 136.3

★★☆ Repair the compiler of theorem 136.14 so that it satisfies RSP, and check that your repair still satisfies OEP and whole-program correctness. Then say what your repair costs at run time.

Back-translation

The characterizations of section 136.2, section 136.4 all require producing a source context from a target context. Two techniques do this, and they trade strength for generality.

Definition 136.17 — Context-based back-translation

A universal embedding is a map from target contexts to source contexts such that the source context, linked with P, produces exactly the behaviour the target context produces with P. A compilation chain with a universal embedding satisfies RHC, and therefore every criterion below it.

Definition 136.18 — Trace-based back-translation

A trace-based back-translation maps a finite set of finite execution prefixes to a source context that reproduces them. It yields the criteria whose characterizations quantify only over finite prefixes: the criterion RSC, its K-relational strengthenings, and the relaxed-safety criterion of theorem 136.15. It therefore yields robust preservation of safety, of hypersafety, and of trace equivalence, and no criterion above those.

The trade is exact. The first technique must embed an arbitrary target context, which requires knowing enough about the target language to simulate all of it; the second only has to replay a finite interaction, so it depends on the calls-and-returns interface between context and program and on nothing else. The first yields the strongest criterion; the second does not yield RHC.

Exercise 136.4

★★☆ Given a trace-based back-translation for single finite prefixes, construct one for finite sets of finite prefixes, or show what extra hypothesis on the source language is needed. (Two lines if the source language has a case analysis on the first event.)

Limits and seminar

The frozen source is Abate, Blanco, Garg, Hriţcu, Patrignani and Thibault (2019). Definition 136.3, Definition 136.4, Definition 136.6, Definition 136.7, Definition 136.10, Definition 136.13 and theorem 136.5, theorem 136.8, theorem 136.11, theorem 136.14, theorem 136.15 are its definitions and theorems, at their exact statements; the proofs of theorem 136.5, theorem 136.8, theorem 136.11, theorem 136.14 are written out here. Theorem 136.9 is its Theorem B.7, proved here. Theorem 136.15 is imported and not reproved.

Five boundaries. First, every criterion is a statement about a compilation chain and a fixed notion of trace; changing what an event records changes every criterion, and no result here says which events a real compiler should emit. Second, none of the criteria is a theorem about any particular compiler: this chapter proves equivalences between criteria and one separation, and exhibits no verified secure compiler. Third, the criteria say nothing about cost: a compiler can satisfy RSP by inserting arbitrary dynamic checks, and exercise 136.3 is exactly that observation. Fourth, theorem 136.14 separates full abstraction from robust safety preservation for determinate languages only; the relationship in the presence of internal nondeterminism is not settled here. Fifth, the two back-translation techniques of section 136.6 are described, not carried out: no universal embedding is constructed in this chapter.

[4]

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 136.5, then complete exercise 136.8.

Exercise 136.5

★★☆ Order RTP, RSP, RDP, RHP and RSCHP by implication, proving each implication from the property-free characterizations and giving a counterexample chain for each non-implication you claim. State which orderings your argument leaves open.

Exercise 136.6

★★★ Termination-insensitive noninterference is a hyperproperty, not a trace property. Write it as a set of sets of traces for a language whose events record public outputs, show that it is subset-closed, and conclude which of the criteria of this chapter suffice to preserve it robustly. Then exhibit a compiler satisfying RSP that does not preserve it.

Exercise 136.7

★★★ For a source language with first-order functions over naturals and a target that adds arbitrary jumps, sketch a universal embedding of target contexts into source contexts, or identify the target feature that makes one impossible. If it is impossible, give the strongest criterion of this chapter that a trace-based back-translation still yields.

Exercise 136.8 — Practical: criteria checker

★★★ Practical project.sec-criteria-checker Complete project sec-criteria-checker. For a finite model — a finite set of traces, finitely many source and target contexts, and a table giving the traces each linked program produces — implement (i) the predicates Safety and Dense of definition 136.6, (ii) the criteria RTP, RSP and RHP and the characterizations RTC, RSC and RHC by exhaustive search over the finite model, and (iii) the decomposition π(S(π),D(π)) of theorem 136.9. The invariant the implementation must maintain is that on every model in the fixture the criterion and its characterization agree, which is theorem 136.5, theorem 136.8, theorem 136.11 restricted to that model. The named cases print

rtp-iff-rtc: ok
rsp-iff-rsc: ok
rhp-iff-rhc: ok
decomposition: ok
fa-model-violates-rsp: confirmed

The checker is independent evidence on the finite models in the fixture; it does not prove theorem 136.5, theorem 136.8, theorem 136.11, theorem 136.9, which quantify over all traces and all properties, and it contains no compiler, no back-translation and no infinite traces.

Search the book

Type to search the local edition.