Manuscript Offprint

arXiv:2609.07365

Trust the Spec, Not the Code - A Specification-First, AI-Assisted Case Study in Online Banking

Eitan Farchi

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Formal specification promises early error detection, explicit invariants, and correctness by design, yet its notational cost has kept it out of mainstream practice. We argue that AI removes much of that cost: natural language enriched with lightweight mathematics, written in LATEX, can serve as an intermediate specification language that is precise enough to reason over and prove, while a large language model (LLM) reviews it for ambiguity, drafts proofs, and generates the implementation. The specification becomes the artifact one authors, reviews, proves, and refines; the code becomes regenerable output. This paper is a follow-on to a prior study that established the discipline on an organizational-knowledge-growth simulation [6]. Here we replicate the discipline in a different domain—an online-banking fund-transfer service—and extend it. The two domains share one spine: a conservation invariant (knowledge in the prior study, money here), which suggests the approach generalizes across domains. We contribute: (i) a second, independent case study of the method; (ii) a stress-test of the method on a richer problem—scheduled/recurring transfers—whose generated code grows substantially while the invariant and its proof do not; (iii) an AI-proposed runtime coverage model for invariants (“never violated ≠\neq covered”); and (iv) a Z formalization, including paired success/failure operation schemas and an invariant proved over the inductive set of all reachable configurations, together with an experiment in which the AI proposes the Z interfaces itself. We are explicit about the method’s limits: the proofs and runtime checks live at the specification level and do not establish that the generated code refines the specification—that step is delegated to the AI. This is a case study, not a controlled experiment.

Keywords: specification-driven development; formal methods; Z notation; conservation invariants; large language models; AI-assisted software engineering.

1 Introduction

The benefits of formal specification have never been seriously in doubt: design flaws surface before code exists, assumptions are written down as explicit invariants rather than buried in implementation, and one can reason about a system instead of debugging it into shape. What kept these benefits out of industry was cost—heavyweight notations such as Z, VDM, and B demand mathematical maturity to write and to maintain, the pool of engineers who can author or even read such specifications is small, and so teams ship informal prose and defer correctness to testing and debugging [8, 9, 4, 1].

Large language models change this cost structure. Modern LLMs can read specifications written in natural language augmented with lightweight mathematics, flag ambiguities and inconsistencies, propose invariants and proofs, and generate running code [3, 2]. This enables a shift in what the

*IBM Research. Email: farchi@il.ibm.com.

engineer treats as primary: the specification becomes the artifact one authors, reviews, proves, and refines, while the code becomes regenerable output that need not be read line by line. Validation shifts left—design flaws are caught in the specification, where they are cheap, rather than in the code, where they are not.

A prior study introduced this discipline and applied it to a simulation of organizational knowledge growth [6]. A natural question is whether the discipline transfers to a different domain with genuinely different subject matter. This paper answers that question with a second case study in online banking. It also extends the method in two ways—a runtime coverage model for the central invariant and a Z formalization of the interfaces—and stress-tests it against a richer problem, scheduled/recurring transfers, where the operation grows substantially while the invariant and its proof do not. Crucially, both domains turn out to rest on the same structural device—a conservation invariant—which is the clearest evidence we have that the approach is not tied to one problem.

References (9)