Skip to main content
QUICK REVIEW

[Paper Review] Soft Contract Verification for Higher-Order Stateful Programs

Phúc C. Nguyễn, Thomas Gilray|arXiv (Cornell University)|Nov 9, 2017
Security and Verification in ComputingComputer Science3 citations
TL;DR

This paper presents a symbolic execution-based approach for soft contract verification in higher-order, stateful, dynamically-typed Racket programs. By combining higher-order symbolic execution with behavioral approximation and opaque function modeling, the method verifies 99.94% of dynamic contract checks statically across a diverse benchmark suite, significantly reducing runtime overhead while maintaining soundness in the presence of mutable state and untyped contracts.

ABSTRACT

Software contracts allow programmers to state rich program properties using the full expressive power of an object language. However, since they are enforced at runtime, monitoring contracts imposes significant overhead and delays error discovery. So contract verification aims to guarantee all or most of these properties ahead of time, enabling valuable optimizations and yielding a more general assurance of correctness. Existing methods for static contract verification satisfy the needs of more restricted target languages, but fail to address the challenges unique to those conjoining untyped, dynamic programming, higher-order functions, modularity, and statefulness. Our approach tackles all these features at once, in the context of the full Racket system---a mature environment for stateful, higher-order, multi-paradigm programming with or without types. Evaluating our method using a set of both pure and stateful benchmarks, we are able to verify 99.94% of checks statically (all but 28 of 49, 861). Stateful, higher-order functions pose significant challenges for static contract verification in particular. In the presence of these features, a modular analysis must permit code from the current module to escape permanently to an opaque context (unspecified code from outside the current module) that may be stateful and therefore store a reference to the escaped closure. Also, contracts themselves, being predicates wri en in unrestricted Racket, may exhibit stateful behavior; a sound approach must be robust to contracts which are arbitrarily expressive and interwoven with the code they monitor. In this paper, we present and evaluate our solution based on higher-order symbolic execution, explain the techniques we used to address such thorny issues, formalize a notion of behavioral approximation, and use it to provide a mechanized proof of soundness.

Motivation & Objective

  • To address the challenge of verifying software contracts in higher-order, stateful, dynamically-typed languages where traditional type inference fails.
  • To enable static verification of contracts without requiring programmer annotations or restricting language features.
  • To scale contract verification to realistic, modular codebases by modeling opaque, stateful external functions soundly.
  • To provide a sound, modular analysis that approximates program behavior under arbitrary interactions with unknown, potentially stateful components.
  • To demonstrate that symbolic execution can be extended to handle untyped, higher-order functions with mutable state while preserving correctness guarantees.

Proposed method

  • Employs higher-order symbolic execution to track the behavior of functions and contracts under abstract execution.
  • Introduces a behavioral approximation model that overapproximates program behavior to ensure soundness in the presence of untyped, stateful code.
  • Models unknown, opaque functions as potentially stateful and capable of escaping to external contexts, tracking heap access to prevent false positives.
  • Uses symbolic heaps and path-sensitive analysis to reason about mutable state and ensure invariants are preserved across function calls.
  • Applies a frame-like principle: if a function does not access a heap location, it cannot affect it, enabling modular reasoning.
  • Supports arbitrary contracts written in unrestricted Racket, including those with side effects, by treating them as first-class, executable predicates during symbolic simulation.

Experimental results

Research questions

  • RQ1Can symbolic execution be extended to support higher-order, stateful, and untyped programs with full contract expressiveness?
  • RQ2How can a modular static analysis soundly handle functions that escape to opaque, stateful contexts?
  • RQ3What approximation strategy enables high-precision verification of contracts without sacrificing soundness in the presence of arbitrary side effects?
  • RQ4Can the approach verify a majority of contracts in realistic, mixed-pure and stateful benchmarks without requiring type annotations or language restrictions?
  • RQ5How effective is the method in verifying contracts in a full-featured, production-grade language like Racket?

Key findings

  • The proposed method verified 99.94% of dynamic contract checks (49,833 out of 49,861) across a diverse benchmark suite.
  • The approach successfully handles 86% stateful and 14% pure benchmarks, demonstrating scalability to realistic, mixed-workload programs.
  • The analysis remains sound even when contracts themselves are stateful or divergent, by treating them as executable predicates in symbolic execution.
  • The method achieves high precision by modeling heap access and opaque function behavior without requiring separation logic or strong updates.
  • The evaluation shows that the tool can verify many 'small but tricky' examples from prior HORS literature, indicating robustness to complex idioms.
  • The approach enables full static verification of contracts in the full Racket system, removing runtime checks and enabling further optimizations.

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.