Phaseline by VERIFYGet the checker
Tutorial Software contracts

Check a replacement

This worked example uses Dafny to check whether a replacement preserves an earlier list contract. The Phaseline CLI does not verify arbitrary list implementations.

Approved · arrange
For arrange on integer lists, return the input elements in ascending order.
Proposed · arrange
For arrange on integer lists, return one zero for each input element.
A one-item counterexample

Input [7] may become [0] under the proposal. The length is right and the result is sorted. The original value 7 has disappeared.

What does “refine” mean?

Fix an input the old contract accepts. List the outputs the replacement allows. Each of those outputs must still be allowed by the earlier contract. The replacement must also handle the previously supported inputs. Here both contracts promise an output for every finite list of integers.

Suppose the old promise allows any reordering of [2, 1]. Both [2, 1] and [1, 2] qualify. Requiring ascending order chooses [1, 2] and keeps the old promise. Going the other way permits an unsorted result that the stronger promise ruled out. The direction of the check matters.

A type such as “list of integers in, list of integers out” admits all these behaviors. Choosing which values must survive is a product decision. Review inputs, observations and invariants.

Read the result

An output allowed by the new promise violates the old one. A deliberate change needs the owner’s decision. A rewrite that still returns the same elements in ascending order keeps the guarantee.

The same case in Dafny

Dafny
abstract module Adopted {
  method Arrange(input: seq<int>) returns (output: seq<int>)
    ensures multiset(output) == multiset(input)
}

This excerpt isolates the element-preservation guarantee. Dafny can reject the zero-producing implementation when the new module refines this parent. The same implementation can pass a standalone zero-producing specification. VERIFY aims to recover the applicable approved parent across conversations. The measured comparison supplies it explicitly.

Dafny reference