Theoremcore
Undecidability of virus detection
Also called Cohen's theorem.
No program can decide for every program whether it is a virus, by reduction from the halting problem.
Cohen (1987) defined a computer virus as a program that can infect other programs by changing them to include a possibly evolved copy of itself, and proved that no program can decide, for every program, whether it is a virus. The proof is a diagonal argument in the style of Turing's halting problem: a detector that is always right can be used to build a program that does the opposite of what the detector says about it. The same result follows by a reduction from the halting problem, and in a model where "being a virus" is a property of the function a program computes, from Rice's theorem. Adleman (1988) put the problem in the arithmetical hierarchy. The theorem says that every practical malware detector must sometimes be wrong or never answer. The page treats copying as an abstract step in a formal model and gives no working code.
Statement
Model. Programs are texts for a fixed universal machine, such as a Turing machine. A program runs on a store: a finite list of slots, each holding a program text. Running a program can read the store and can write texts into slots. All runs start from a fixed initial store . A program writes nothing if no run of from writes a slot. A program copies itself if its run from eventually writes its own text into a slot that held another program.
Theorem 1 (Cohen). Let be any set of programs such that every program that copies itself is in and no program that writes nothing and halts is in . Then no total computable function satisfies for all programs .
Cohen's own definition of a virus, with infection by a possibly evolved copy, satisfies both conditions, so his set of viruses is undecidable. So is the narrower set of programs that copy themselves exactly.
Theorem 2 (reduction). Let contain every program that copies itself and no program that writes nothing, whether it halts or not. Then the halting problem many-one reduces to : there is a computable map with if and only if halts on .
In plain words
Suppose someone claims to have a perfect checker: you give it any program, and it always answers, and it is always right about whether the program spreads copies of itself.
Then you can write a tricky program that first asks the checker about itself. If the checker says "it spreads", the tricky program stops at once and spreads nothing. If the checker says "it does not spread", the tricky program spreads a copy of itself.
Either way the checker was wrong about the tricky program. So the perfect checker cannot exist.
This does not stop useful checkers. A checker can look for known patterns, or run a program for a limited time and watch. It only means that every checker makes mistakes on some programs, or never gives an answer on some programs.
Proof
Theorem 1. Suppose a total computable decides . Let be the copy step: "write the text into the first slot of that holds another program". Consider the computable map that takes a program text to the program
Since is total and computable, is a total computable map on program texts. By the Kleene recursion theorem, in the form that allows a program to use its own text, there is a program that behaves exactly as does. So computes , and then:
- If , then halts without writing, so writes nothing and halts, so . Then is wrong.
- If , then writes its own text into a slot that held another program, so copies itself, so . Then is wrong.
Both cases contradict the assumption that decides . So no such exists.
This is the argument of Cohen's paper, with the self-reference made exact by the recursion theorem. Cohen writes the program in pseudocode and lets it call the detector on itself by name.
Theorem 2. Given a machine and an input , let be the computable map that takes to the program "simulate on without touching the store; when the simulation halts, run with the text , then halt". The map is computable, so the recursion theorem with parameters gives a computable such that behaves as .
- If halts on , then writes its own text into a slot that held another program, so copies itself and .
- If does not halt on , then never writes the store, so .
Cohen's definition satisfies the condition on , because a program that never writes cannot infect anything. So if and only if halts on , which is the many-one reduction. Because the halting problem is undecidable, so is .
From Rice's theorem. Suppose the store is part of the input and the output, so that each program computes a partial function from stores to stores. If the definition of a virus depends only on this function, and some program is a virus and some is not, then the set of viruses is a nontrivial semantic property, and it is undecidable by Rice's theorem. Self-copying as defined above mentions the text of the program, so it is not of this form, and the direct proofs above are needed.
Consequences
- Every detector errs (theorem). For every total computable detector there is a program on which gives the wrong answer. Running the same argument on versions of that carry different unused instructions gives infinitely many such programs. A detector that is never wrong must fail to answer on some programs.
- No perfect detector, but always a better one (theorem). Given a detector and the program that defeats it, the detector that answers correctly on and as elsewhere is again computable. So no detector is best, in the same sense as the full employment theorem for compilers.
- Evolutions (theorem). Cohen used the same kind of argument to show that no program decides, for every pair of programs, whether one is an evolution of the other. So detection by comparison with a known virus is also undecidable once the copies may change.
- What remains decidable (theorem). Decidable questions are those about the text or about bounded runs: whether a file contains a given string, or whether a program writes its own text within steps, which a simulation of steps answers. Practical detectors decide such questions and accept errors on the real question.
Tightness
- Semi-decidable in the one-run model (theorem). With a fixed initial store, the set of programs that copy themselves is computably enumerable: simulate the program and accept when it writes its own text into a slot. Theorem 2 shows that the halting problem reduces to it, so it is complete for the computably enumerable sets under many-one reductions. So undecidability is the exact answer in this model: a detector can confirm every program that copies itself, but it cannot reject every program that does not.
- Higher in the general model (theorem). Adleman (1988) defined a virus abstractly, as a total recursive function that maps each program to an infected form of it, with conditions over all inputs. He showed that the set of viruses under this definition lies at the second level of the arithmetical hierarchy, above the halting problem. In this model a detector cannot even confirm every virus.
- Restricted programs. If programs have a finite number of states, or are known to halt within a bound, every run can be simulated, and the question is decidable. The theorem needs programs that can run without bound.
History
Cohen named and studied computer viruses in the 1980s, and his 1987 paper in Computers and Security gives the formal definition on a Turing machine model, the undecidability results, and reports of controlled experiments. Adleman gave the abstract recursion-theoretic treatment at CRYPTO 1988. Both proofs follow the diagonal argument of Turing (1936) and, for semantic properties, Rice (1953). Later work on malware detection treats the theorem as the reason why detectors must be heuristic.
References
- Fred Cohen, Computer viruses, theory and experiments, Computers and Security 6(1), 1987, pages 22 to 35, the definition of a virus as a program that infects other programs with a possibly evolved copy of itself, the contradiction argument that no program decides whether a program is a virus, and the same argument for the detection of evolutions
- Leonard M. Adleman, An abstract theory of computer viruses, Advances in Cryptology, CRYPTO 1988, LNCS 403, Springer, 1990, pages 354 to 374, the definition of viruses as total recursive functions on programs and the classification of the set of viruses in the arithmetical hierarchy
- Alan M. Turing, On computable numbers, with an application to the Entscheidungsproblem, Proceedings of the London Mathematical Society (2) 42, 1936, pages 230 to 265, Section 8, the diagonal argument that no machine decides whether a machine is circle-free
- Henry Gordon Rice, Classes of recursively enumerable sets and their decision problems, Transactions of the American Mathematical Society 74(2), 1953, pages 358 to 366, the theorem that every nontrivial class of recursively enumerable sets has an undecidable index set
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 | W4 complete |
|
Tag HJMJKK Edit this page History Report an error Markdown