Skip to main content
QUICK REVIEW

[Paper Review] Inferring Concise Specifications of APIs

John L. Singleton, Gary T. Leavens|arXiv (Cornell University)|Jan 1, 2019
Software Testing and Debugging TechniquesComputer Science48 references2 citations
TL;DR

This paper presents a novel technique to infer concise, human-readable postconditions for Java API methods by transforming the exponentially large formulas generated by the strongest postcondition (SP) predicate transformer. By exploiting structural patterns in SP outputs, the method reduces specification size by up to 76.7% in proof length and 26.7% in prover time, achieving 75.7% success rate on 2,300+ methods across seven libraries with 84.6% of specifications under 20 lines.

ABSTRACT

Modern software relies on libraries and uses them via application programming interfaces (APIs). Correct API usage as well as many software engineering tasks are enabled when APIs have formal specifications. In this work, we analyze the implementation of each method in an API to infer a formal postcondition. Conventional wisdom is that, if one has preconditions, then one can use the strongest postcondition predicate transformer (SP) to infer postconditions. However, SP yields postconditions that are exponentially large, which makes them difficult to use, either by humans or by tools. Our key idea is an algorithm that converts such exponentially large specifications into a form that is more concise and thus more usable. This is done by leveraging the structure of the specifications that result from the use of SP. We applied our technique to infer postconditions for over 2,300 methods in seven popular Java libraries. Our technique was able to infer specifications for 75.7% of these methods, each of which was verified using an Extended Static Checker. We also found that 84.6% of resulting specifications were less than 1/4 page (20 lines) in length. Our technique was able to reduce the length of SMT proofs needed for verifying implementations by 76.7% and reduced prover execution time by 26.7%.

Motivation & Objective

  • To address the challenge of generating concise, usable formal postconditions for API methods, which are essential for formal verification and software engineering tasks.
  • To overcome the exponential bloat in strongest postcondition (SP) formulas that renders them impractical for human understanding and tool use.
  • To develop a method that transforms SP-generated formulas into compact, readable, and semantically equivalent specifications without losing precision.
  • To evaluate the practicality and effectiveness of inferred postconditions in real-world Java libraries using formal verification.
  • To identify and eliminate redundant, tautological, or unsatisfiable clauses that hinder usability in real-world specifications.

Proposed method

  • The method uses forward symbolic execution combined with the strongest postcondition (SP) predicate transformer to generate initial logical formulas from method bodies.
  • It applies a series of optimization rules to SP-generated formulas, leveraging structural patterns such as disjoint conditionals and common subexpressions to reduce redundancy.
  • The approach employs a pluggable equivalence relation (∼) to identify and collapse semantically identical expressions, enabling global simplification beyond branch-level optimization.
  • It integrates frame axioms and purity/assignable clauses to preserve memory safety semantics while minimizing verbosity.
  • The technique is implemented as an extension to OpenJML, using Z3 as the SMT solver for verification of inferred specifications.
  • The tool, Strongarm, applies these optimizations systematically to produce compact, human-readable JML-style specifications.

Experimental results

Research questions

  • RQ1Can SP-generated postconditions be systematically simplified to produce concise, usable specifications without losing semantic accuracy?
  • RQ2To what extent can structural patterns in SP formulas be exploited to reduce specification size and improve readability?
  • RQ3How effective is the proposed optimization technique in reducing proof size and prover execution time in real-world API methods?
  • RQ4What percentage of real-world API methods can be successfully specified using this approach, and how concise are the resulting specifications?
  • RQ5How do developers perceive the usability of the inferred specifications compared to common anti-patterns like tautologies, redundancies, and unsatisfiable preconditions?

Key findings

  • The technique successfully inferred postconditions for 75.7% of 2,300+ methods across seven popular Java libraries, all of which were verified correct using OpenJML’s Extended Static Checker.
  • 84.6% of the inferred postconditions were less than 1/4 page (20 lines) in length, indicating high conciseness.
  • The method reduced the length of SMT proofs needed for verification by 76.7%, significantly improving scalability.
  • Prover execution time was reduced by 26.7% on average, demonstrating improved performance for downstream tools.
  • All inferred specifications included either a purity or assignable clause, indicating strong support for memory safety modeling.
  • A developer survey confirmed strong preference for the concise, non-redundant, and non-tautological specifications produced by the technique over common anti-patterns.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.