This repo contains Tamarin models for Intel SGX application components of three open source projects: Hyperledger Sawtooth, SGXEnabledAccess, BI-SGX. These models can be helpful to verify the properties of any other SGX application. Each model uses many SGX primitives, some of which are directly reusable. Other primitive requires customized integration as per application requirement. Details of the three open-source projects, the SGX threat model, the working principles behind the SGX primitives are described in our USENIX Security '21 paper.
- Tamarin codes files for each case study of our paper are in 3 separate folders – Sawtooth, SGXEnabledAccess, BI-SGX. Each of these folders contains two sub-folders: safe and vulnerable, which contain the safe and vulnerable Tamarin model files respectively.
- The Tamarin model files are with extension .spthy; Tamarin proof output is saved with .proof files; the attack trace images are saved with file names trace_*.png for vulnerable models.
- The proofs were run with Tamarin prover (v1.7.0) on a machine with a quad-core 1.80GHz Intel© Core i7-8550U CPU and 16 GB RAM, and Ubuntu Linux 18.04. Proof of SGXEnabledAccess also requires python3 installation. Tamarin (v1.7.0) can be installed from the Tamarin GitHub repo.
- For each Tamarin model, the Tamarin heuristics and trace algorithm parameters are specified in the model files as comments.
SGX primitives | Programming primitives |
---|---|
|
Out of the above primitives monotonic counters, locks, local/global variables, and the programming primitives can be reused directly. Other require manual integration based on the code component under consideration.
Sawtooth uses all the SGX primitives with single threaded ecalls.
SGXEnabledAccess uses multi-threaded ecalls, local/global variables, SGX threat model, key derivation, locks, loops, and branching
BI-SGX uses single threaded ecalls and all the primitives except Loops and Branching.
- Install Tamarin prover and learn how to use it from the Tamarin Manual, Tamarin code examples, other research works, Exercise at VeryCrypto, Exercise by Dr. Kiesl, Tutorials Blog Video
- Identify the control flow of your SGX application’s code component and the desired properties that you hope to verify.
- Identify the code variables, trusted and untrusted boundaries, and the SGX primitives required to build the formal model of the code component. Explore the models in this repo to find what primitives can you reproduced for your model.
- Start with a simple model and ensure correct syntax and protocol behavior using executability lemmas
- Write properties in First-Order Logic; Get Initial results; validate the trace result into application code if possible; gradually add other functionalities, and repeat the process. If you encounter non-termination, see the section below.
-
Run Tamarin Interactive GUI without
--prove
flag. Observe if all the partial deconstructions are resolved. If not, the Auto-Source paper and the TLS1.3 thesis can help. -
Try all Tamarin binary parameters
--stop-on-trace
and--heuristic
to see if any combination terminates the proof in a reasonable time (learned by experience; this can vary for different model sizes and complexity). UT Tamarin could be useful here. -
Try induction lemmas
-
Try to minimize looped fact dependencies. An example could be found here. The looped dependencies could be complex — "Another source of non-termination that is a feature of Tamarin's unrolling is interacting inductive lemmas. You can create pathological examples where you have loops that are not well-bracketed, i.e. the loops partially overlap, something like
[(])
where[]
and()
are looping states. If you have one inductive lemma for each loop you may not be able to solve either one. The only times I've ever run into this in practice is when I've tried to decompose inductive lemmas too far to try and make the automated prover solve more." noted by Jonathan Hoyland -
Try following methods
- Manually reason about why the property you expect should hold in the model
- Observe the proof steps in Tamarin interactive GUI and identify the pattern of the proof or observe if the proof process is resolving a set of similar constraint repeatedly
Based on the above methods build helper lemmas or customized heuristic using an oracle script
-
Check if the XOR equation theory and the corresponging rule variants are correct. google group chat ("An adversary can not rule out the possibility of Fr(a) from one rule to be the same as Fr(b) from another rule.")
-
Go through Tamarin Google Forum and ask for help. The forum history contains many modeling tips and tricks.
-
Also, note that proving a property for a given model is undecidable. Therefore, it is impossible to ensure termination in all cases.
- The paper -- SoK: Computer-Aided Cryptography describes the state of Formal Methods in a broader perspective.
- The equivalence of an application code and the constructed model is made by the best human effort (without proof). Therefore, verification results for any constructed model convey knowledge about the model rather than the application code that it represents. In my opinion, this approximation (aka verification gap) is not a big barrier to the utility of formal verification because verification results: especially flaws can be double-checked back in the application code. Moreover, proving the property of an approximate model serves the purpose of formal verification well enough in many real-world cases.
- It is very important to understand the assumptions involved in the model and the properties proved. "A proof is only as good as its model" (source, page 43)
We thank Cas Cremers, Jonathan Hoyland, Benjamin Kiesl, Jannik Dreier, Kevin Milner and the Tamarin community at the Google forum for providing insight into Tamarin.