A not-quite-there way to close the gap is that you can generate traces from the spec/proof, a sequence of states and events that must hold true. and then you can use that trace to replay back in tests, and if the implementation is correct, then it should mirror the trace.
Like if you want a program that sorts a list that is a subjective goal because you could just as easily choose a shuffled list, or a different sorting, or any other sort of list ordering.
Once you've established what you want fulfilling that is an objective task.
Today's programming languages entangle subjectivity and objectivity together, and better decoupling them means we can automate the objective parts which dramatically reduces the programming left over for humans.
That heavily depends on what problem you're trying to solve. The very example from TFA is quite illustrative:
contract ReplaceElement {
function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64
requires index < words.len
ensures result == old(words[index])
and snapshot(words) == update(old(snapshot(words)), index, value)
terminates
effects { read(words), write(words) }
}
implementation InlineReplaceElement of ReplaceElement {
function replace(words: &mutable Slice<UInt64>, index: UInt64, value: UInt64) -> UInt64 {
let previous = words[index]
words[index] = value
previous
}
}
Or take, for instance, this spec in English prose: "given a predicate that returns true or false for each value, and a list of values, `filter` returns a new list that contains exactly the values in the original for which the predicate returned true". I guarantee you that turning this into the Truss contract would produce a significantly larger amount of code that the implementation that would consist of just the following 5 lines, modified accordingly: result := []{}
for _, v := range list {
if predicate(v) { result = append(result, v) }
}
return result
And of course, please note that the spec I've given is defective: it doesn't say anything about the order of the elements in the resulting list, or the presence/absence of duplicates. Also, you probably will have to insist on the predicate being a pure or at least a repeatable (reproducible?) function — I don't know how you'll spec `filter` when it's given a non-idempotent predicate.It's a bit like writing and maintaining a declarative SQL query (new-style) vs writing a query planner (old-style programming).
There is also something excellent formal code produces: modularity