Techniqueresearch
Self-composition
Also called product programs.
Reduces a property of two runs, such as noninterference or equivalence, to a safety property of one program that runs both copies.
Self-composition checks a property of two runs of a program by checking an ordinary property of one run of a bigger program. The bigger program is the original followed by a copy of itself with every variable renamed, so one run of it is two independent runs of the original. A 2-safety property, such as noninterference, then becomes a single Hoare triple that any one-run verifier can prove. Product programs refine the idea: they run the two copies in step, so that the loop invariants become simple.
In plain words
Some questions are about two runs, not one. "Does the public output stay the same when only the secret changes?" compares a run with a secret and a run with another secret. Most checkers only know how to look at one run at a time. The trick is to glue two copies of the program into one program. The first copy uses its own variables, the second copy uses other ones, and they cannot touch each other. Start them in two related states, run them, and check that the end states are related. Now the question is about one run of the glued program, and the usual tools work. Running the two copies side by side, instead of one after the other, makes the proof much easier.
When it applies
- The property is a k-safety property: it says that every runs of whose start states are related by a condition end in states related by . For this covers noninterference, constant-time execution, determinism and monotonicity, and, with two different programs, the equivalence of a program and its transformed version.
- The copies can be kept apart: each variable, array and heap cell can be duplicated, so the two runs do not interfere.
- The property is about terminating runs, in the sense of partial correctness. Properties that need a non-terminating run, or that ask for the existence of a matching run, as possibilistic noninterference does for nondeterministic programs, do not fit the plain form.
Deciding such properties is undecidable in general, by Rice's theorem, so self-composition does not remove the need for invariants; it moves the problem to a tool that can look for them.
The template
SELF-COMPOSE(P, Phi, Psi)- 1
P1 <- RENAME(P, 1) ▷ hole RENAME: x becomes x1 for every variable, array and heap - 2
P2 <- RENAME(P, 2) ▷ x becomes x2 - 3
Q <- ALIGN(P1, P2) ▷ hole ALIGN: P1; P2, or a product that runs matching parts together - 4
pre <- Phi(x1, x2) ▷ for noninterference: l1 = l2 for every low l - 5
post <- Psi(x1, x2) ▷ for noninterference: l1 = l2 for every low l - 6
prove {pre} Q {post} ▷ hole PROVER: VC generation with invariants, a model checker, or testing - 7
if L6 succeeds then return "P has the 2-safety property" - 8
return the run of Q that breaks post, as a pair of runs of P
Why it is exact. Let be a program whose runs are the pairs of a start state and an end state. The copy reads and writes only the variables of copy 1, and only those of copy 2. So a run of from the joint state first changes the copy-1 part to with a run of , and then the copy-2 part to with a run of . Its end states are exactly the pairs of end states of two runs of . Hence the triple is valid for partial correctness if and only if every two runs and of with have . For noninterference, and are both "the low parts are equal", which is the triple of Barthe, D'Argenio and Rezk. If either copy does not stop, the triple says nothing, which matches termination-insensitive noninterference.
Alignment. The hole ALIGN may replace by any program with the same end states from each start state. Statements of different copies commute, since they touch disjoint variables. So straight-line code can be interleaved freely, and two loops can be fused:
because the fused loop runs the first of the two iteration counts of each copy, and the two tail loops run the rest. This is a product program. Its value is that the invariant of the fused loop can relate the two copies at the same point of their runs.
Walk-through. Take the program with and low, and a high variable that it does not read. With , the proof needs an invariant for the first loop that tells what is at the end, such as , and the same for the second loop. These are nonlinear, and the proof of the program's security has become a proof of its function. With the fused loop, the precondition gives the invariant . It is linear, it is preserved by one turn of , and when the fused loop exits both guards are false at once, so the tail loops do nothing and holds at the end. A VC generator with this invariant proves the triple.
Classic examples
- Noninterference. With the template proves noninterference, including programs that a security type system rejects, such as , where the weakest precondition of is .
- Constant-time code. Add a counter that each statement increases by its cost, and make an output. With "the public inputs are equal" and "", the triple says that the running time does not depend on the secret, the property that stops a timing attack.
- Program equivalence and optimizations. Compose a program with a transformed version instead of itself, with "the inputs are equal" and "the outputs are equal". Barthe, Crespo and Kunz prove loop unrolling, loop-invariant code motion and other optimizations this way, with a product that aligns the iterations. Translation validation and equivalence checking solve the same problem for one compiled program.
- Determinism and monotonicity. With "the inputs are equal" and "the outputs are equal", a program with internal choices is shown deterministic; with "" and "" it is shown monotone.
- Bounded search for leaks. Run bounded model checking on : a counterexample is a concrete pair of runs that leaks. k-induction on can prove the property when the product has simple invariants.
Variations
- Relational Hoare logic. Benton's logic proves judgments directly, with rules that pair up the statements of the two programs. A proof in it can be read as a proof of a product program.
- Type-directed products. Terauchi and Aiken use a security type analysis to find the parts of that do not depend on secrets. Those parts run in step in both copies, and only the rest is duplicated, which gives a smaller program and simpler invariants.
- Asymmetric products. For properties, such as refinement or possibilistic noninterference of nondeterministic programs, Barthe, Crespo and Kunz later built products in which the second copy is a choice to be made, not a run to be checked.
- More copies. A k-safety property needs copies; for example, the transitivity of a comparison function needs three runs. The template is the same with renamings.
- Constraint solving. Instead of a fixed product, a relational verifier can search for the alignment and the invariant together, as a system of constraints over unknown relations.
Pitfalls
- Sequential composition makes invariants hard. In each loop runs alone, so its invariant must describe what the loop computes, not how the two copies relate. Align the loops when the copies take the same branches.
- Alignment needs matching control flow. The fused loop helps only if the two copies leave the loop at the same time, usually because the guard depends on low variables only. If the guard depends on a secret, the tail loops run, and the invariant must cover them.
- Shared state breaks the reduction. The copies must not share a variable, a heap cell, a file or a global. A missed sharing makes the two runs dependent, and the proof is about a different program.
- Partial correctness only. The triple is vacuous when a copy does not stop. It proves termination-insensitive properties, and a leak through termination needs a separate termination proof.
- The model must contain the channel. A proof of noninterference over the final state says nothing about time, memory traffic or power, unless the program is instrumented to make them outputs.
Exercises
- Self-compose and find a state that breaks . Answer. , , . The end state has and .
- Prove for with weakest preconditions. Answer. Going backwards, turns into , then leaves it, turns it into , and leaves it. The precondition follows from .
- Why does a fused loop fail to give a simple proof for , and why is the program still noninterfering? Answer. The two copies run and turns, so after the fused loop one tail loop runs and in general. But is not low, and the final makes , so the invariant "true" for all three loops is enough.
- Show that statements of different copies commute: if uses only copy-1 variables and only copy-2 variables, then and have the same end states. Answer. From both orders end in , where is an end state of from and one of from , since neither statement reads or writes the other part.
References
- Gilles Barthe, Pedro R. D'Argenio and Tamara Rezk, Secure information flow by self-composition, Proceedings of the 17th IEEE Computer Security Foundations Workshop (CSFW 2004), the self-composition of a program with a renamed copy of itself, and the characterization of noninterference by a Hoare triple of the composed program
- Tachio Terauchi and Alex Aiken, Secure information flow as a safety problem, Proceedings of SAS 2005, LNCS 3672, the definition of 2-safety, the observation that plain self-composition needs hard invariants, and the type-directed transformation that interleaves the two copies
- Gilles Barthe, Juan Manuel Crespo and Cesar Kunz, Relational verification using product programs, Proceedings of FM 2011, LNCS 6664, pp. 200 to 214, product programs that align the two copies, with noninterference and loop optimizations as examples
- Nick Benton, Simple relational correctness proofs for static analyses and program transformations, Proceedings of POPL 2004, pp. 14 to 25, relational Hoare logic, a proof system for judgments about two runs at once
- Michael R. Clarkson and Fred B. Schneider, Hyperproperties, Journal of Computer Security 18(6), 2010, pp. 1157 to 1210, k-safety hyperproperties and their verification by self-composition
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag D3FA1M Edit this page History Report an error Markdown