Algorithm Search⌘K

Modelresearch

Software testing as species discovery

Also called STADS.

Models fuzzing as sampling species from an ecology and uses the Good-Turing estimator to estimate the chance that the next input finds new behavior.

Software testing as species discovery (STADS) is a statistical model of automated testing that borrows the methods ecologists use to count the species of a forest from a sample of animals. A test generator, such as a fuzzer, produces inputs for a program one after another. STADS treats each input as one sample drawn from a population of program behaviors, and the behavior the input shows, for example the path it takes through the code, is its species. Some behaviors are common and are seen again and again; others are rare and may not have been seen yet. With this view, the species estimators of ecology answer testing questions: Good-Turing estimation estimates the probability that the next input shows a behavior never seen before, and the Chao1 estimator estimates how many behaviors there are in all. Böhme (2018) introduced the model.

For fuzz testing, this gives a statistical answer to an old problem: a campaign that has found no bug does not show that none is left, but the discovery probability bounds the chance that the next input finds an error of a kind not seen yet. This residual risk can be estimated while the campaign runs and used to decide when to stop. The guarantee needs the samples to come from a fixed distribution, which a feedback-driven fuzzer does not satisfy, so for such a fuzzer the estimates are approximations.

The machine

  • Inputs as individuals. A fuzzer FF generates inputs x1,x2,…x_1, x_2, \ldots. A dynamic analysis assigns to each input its species: the path it executes, the function where it crashes, or a pair such as (path, crashed or not).
  • The multinomial model. Each input belongs to exactly one of SS species D1,…,DSD_1, \ldots, D_S, and each input belongs to DiD_i with probability pip_i, independently of the other inputs, with p1+⋯+pS=1p_1 + \cdots + p_S = 1. The number of species SS and the probabilities are unknown.
  • Fixed abundances. The probabilities do not change during the campaign. This holds for a blackbox fuzzer with a fixed input distribution. A greybox fuzzer adds inputs that found new species to its queue and so raises the probability of their neighbors; Böhme calls this adaptive bias.
  • The Bernoulli product model. When one input can belong to several species at once, such as the branches it covers, each species is present in an input with its own probability, independently across inputs. The data are then incidence counts, and the estimators change accordingly.
  • What is observed. After nn inputs, XiX_i is the number of inputs in species DiD_i, S(n)S(n) is the number of species seen so far, and fkf_k is the number of species seen exactly kk times. f1f_1 counts the singletons and f2f_2 the doubletons.

What it counts

The discovery probability. U(n)U(n) is the probability that input n+1n + 1 belongs to a species not seen in the first nn inputs, so U(n)=∑ipi [Xi=0]U(n) = \sum_i p_i \, [X_i = 0] and U(0)=1U(0) = 1. Its expected value over the campaign is

E[U(n)]=∑i=1Spi(1−pi)n.\mathbb{E}[U(n)] = \sum_{i=1}^{S} p_i (1 - p_i)^n.

The sample coverage C(n)=1−U(n)C(n) = 1 - U(n) is the probability that the next input belongs to a species already seen, and 1/U(n)1/U(n) is the expected number of further inputs to the next discovery while UU stays as it is.

The Good-Turing estimate. U^(n)=f1/n\hat U(n) = f_1 / n. A species seen once is a species that was nearly missed, and the share of singletons predicts the share of the species still missing.

The residual risk. The residual risk after nn inputs without a failure is the probability that input n+1n + 1 is the first input to show a failure. If the analysis is fine enough that every kind of failure is a union of species, then an input that shows a new kind of failure belongs to a species not yet seen, so the residual risk is at most U(n)U(n). STADS uses U^(n)\hat U(n) as the estimate of this bound.

Richness and extrapolation. The Chao1 estimate S^=S(n)+n−1nf122f2\hat S = S(n) + \frac{n - 1}{n} \frac{f_1^2}{2 f_2} (with n−1nf1(f1−1)2\frac{n-1}{n} \frac{f_1 (f_1 - 1)}{2} when f2=0f_2 = 0) gives a lower bound estimate of the number of species, and S(n)/S^S(n) / \hat S is the share discovered. Formulas of ecology for rarefaction and extrapolation estimate S(n+m)S(n + m) and U(n+m)U(n + m) after mm more inputs, which tells how much more fuzzing buys.

Example. A made-up function reads one byte and branches on the number of leading 1 bits, from 0 to 8. With uniform random bytes this gives nine species A to I with probabilities 1/2,1/4,…,1/1281/2, 1/4, \ldots, 1/128 and 1/256,1/2561/256, 1/256 (I is the byte 255). The first 50 bytes of Python's random.Random(0).randrange(256) give these counts:

species A B C D E F G H I
probability 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/256
count in 50 inputs 23 14 5 2 3 2 1 0 0

So S(50)=7S(50) = 7, f1=1f_1 = 1 (species G) and f2=2f_2 = 2 (D and F). The Good-Turing estimate is U^=1/50=0.02\hat U = 1/50 = 0.02, and the true discovery probability is pH+pI=1/128≈0.0078p_H + p_I = 1/128 \approx 0.0078. Chao1 gives 7+4950⋅14=7.2457 + \frac{49}{50} \cdot \frac{1}{4} = 7.245 against the true 9. If byte 255 is the one input that crashes, the residual risk is 1/2561/256, below U(50)U(50). One sample is noisy: after 100 inputs of the same stream, f1=0f_1 = 0 and the estimate is 0, while U=1/128U = 1/128. The estimator is right on average: over all samples of size 50, E[U(50)]≈0.02784\mathbb{E}[U(50)] \approx 0.02784 and E[f1/50]≈0.02841\mathbb{E}[f_1/50] \approx 0.02841. A scratch script computed these numbers exactly with fractions.

Relation to other models

  • Ecology. The multinomial model is the abundance model of species sampling, and the Bernoulli product model is the incidence model. The estimators of Chao1 and of rarefaction are used without change.
  • Language models. Good-Turing estimation of unseen words is the same estimate of the missing mass, with words as species.
  • The coupon collector. With SS equally likely species, the time to see all of them is the coupon collector problem. STADS makes no assumption on the abundances, and real campaigns have many rare species.
  • Markov chain model of greybox fuzzing. The model behind power schedules describes how the fuzzer moves between paths and how the choice of seeds changes the probabilities. STADS assumes that the probabilities stay fixed, so it leaves out the change that the chain model describes.
  • The exponential cost of discovery. The exponential cost of vulnerability discovery is an empirical law about campaigns that a species model with a heavy tail of rare species explains.
  • The rule of succession. For a fixed distribution with no failure in nn runs, the Laplace estimate 1/(n+2)1/(n + 2) of the failure probability is an alternative, related to Laplace smoothing; Böhme, Liyanage and Wüstholz (2021) list it among the blackbox estimators.

Known results in the model

  • Bias of the Good-Turing estimate (theorem, fixed distribution). f1f_1 has expected value ∑inpi(1−pi)n−1\sum_i n p_i (1 - p_i)^{n-1}, so E[f1/n]−E[U(n)]=∑ipi2(1−pi)n−1\mathbb{E}[f_1 / n] - \mathbb{E}[U(n)] = \sum_i p_i^2 (1 - p_i)^{n-1}. This is at least 0, and at most max⁡ipi(1−pi)n−1≤1/n\max_i p_i (1 - p_i)^{n-1} \le 1/n, because ∑ipi=1\sum_i p_i = 1 and x(1−x)n−1≤1/nx (1 - x)^{n-1} \le 1/n for 0≤x≤10 \le x \le 1. So the estimate is a little too high on average, by less than 1/n1/n. In the example, the gap at n=50n = 50 is about 0.00057.
  • Residual risk bound (theorem). If every kind of failure is a union of species, the residual risk is at most U(n)U(n), as shown above. It is a bound on a probability, estimated by U^(n)\hat U(n); it is not a proof that no bug is left.
  • Other properties of the estimate. The paper cites results of the statistics literature: the Good-Turing estimate is strongly consistent, it is asymptotically normal, and its mean squared error is below 1/n1/n (Robbins). All of them assume the fixed-distribution model.
  • The djpeg campaign (measurement). In the paper's example of AFL on djpeg, after 12 hours there were 447 singleton species in 63.6 million inputs, so U^≈7⋅10−6\hat U \approx 7 \cdot 10^{-6}; after 24 hours there were 95 singletons in 124.8 million inputs, so U^≈8⋅10−7\hat U \approx 8 \cdot 10^{-7}. Here a species is a pair of a path and whether the input crashed.
  • Evaluation under adaptive bias (measurement). Böhme fuzzed six programs with AFL for a total of 8.2 months and reported low bias for the estimates of the discovery probability and of species coverage, and that the bias fell as more inputs were generated, despite AFL's adaptive bias.
  • Greybox residual risk (measurement). Böhme, Liyanage and Wüstholz (2021) measured that the classical estimators made for blackbox fuzzing, among them Good-Turing and Laplace, systematically and substantially under-estimate the residual risk of greybox campaigns, because the probability of a bug-revealing input grows as the queue grows. They gave the first probabilistic analysis of adaptive bias and new estimators that correct for it. The fixed-distribution theorems above therefore do not carry over to a greybox fuzzer; for it, the Good-Turing estimate is an approximation.

References

  1. Marcel Böhme, STADS, software testing as species discovery, ACM Transactions on Software Engineering and Methodology 27(2), Article 7, 2018, pp. 1 to 52, the multinomial model, Section 4 (the discovery probability, its Good-Turing estimate and the guarantee for undiscovered errors), Figure 2 (the djpeg campaign), Section 6 (the evaluation with AFL), Section 7 (the Bernoulli product model) and Section 9.5 (adaptive bias)
  2. Marcel Böhme, Danushka Liyanage and Valentin Wüstholz, Estimating residual risk in greybox fuzzing, Proceedings of ESEC/FSE 2021, pp. 230 to 241, the definition of residual risk, the discovery probability as its upper bound, and the measured under-estimation by blackbox estimators under adaptive bias
  3. I. J. Good, The population frequencies of species and the estimation of population parameters, Biometrika 40(3-4), 1953, pp. 237 to 264, the estimate of the total probability of unseen species from the number of species seen once
  4. Andreas Zeller, Rahul Gopinath, Marcel Böhme, Gordon Fraser and Christian Holler, The Fuzzing Book, chapter When To Stop Fuzzing, the Good-Turing estimate of the discovery probability in a fuzzing campaign

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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/WT7TJM/text.yaml