The tour · 15 minutes
From install
to proved and running.
A quick walk through Verada for programmers who already know a
language or two. Every example comes in all three syntaxes; pick a
tab, and every output is what veradic really printed.
1 · What Verada is
One language, three syntaxes.
Verada is a compiler and program prover in the spirit of Ada. It is one language written three ways: Vada is Ada's syntax, Varc is a C-family syntax, and Vibe is typed Python.
A normal build proves that the program has no run-time error and keeps every contract it states, then compiles it to native code through LLVM.
2 · Install
Get Verada.
The beta package runs on macOS on Apple silicon. It includes
veradic, Z3, the VS Code extension and example projects.
Write to
hello@verada.dev
for access, then follow the
Beta Quick Start
to install it and connect your editor. Once installed,
veradic --version names the build, its LLVM and the solvers it found.
Building from source? The installation guide covers Stack, GHC and LLVM setup.
Prefer a browser workspace? veradic ide opens the current
folder with source editing, project tools, a REPL and the Guide.
Explore the Verada IDE
or follow its user guide.
3 · A first project
A package with a contract.
A project is a directory with a verada.toml naming its
source directories. This one has a package, Counters,
and a main program that uses it.
Each subprogram states a contract. The precondition
(Pre, requires) is what a caller must
promise; the postcondition (Post,
ensures) is what the subprogram promises back.
increment may only be called below the largest
Natural, and then adds exactly one.
Varc marks an argument the call may change,
increment(&hits). In Python an int
argument cannot be changed by the callee, so Vibe's
increment returns the new count instead.
verada.toml
[project]
source-dirs = ["src"] src/counters.vads
package Counters is
function Clamp (Value, Low, High : Integer) return Integer
with Pre => Low <= High,
Post => Clamp'Result in Low .. High;
procedure Increment (Count : in out Natural)
with Pre => Count < Natural'Last,
Post => Count = Count'Old + 1;
end Counters; src/counters.vadb
package body Counters is
function Clamp (Value, Low, High : Integer) return Integer is
begin
if Value < Low then
return Low;
elsif Value > High then
return High;
else
return Value;
end if;
end Clamp;
procedure Increment (Count : in out Natural) is
begin
Count := Count + 1;
end Increment;
end Counters; src/main.vadb
with Ada.Text_IO; use Ada.Text_IO;
with Counters; use Counters;
procedure Main is
Hits : Natural := 0;
begin
Increment (Hits);
Increment (Hits);
Put_Line ("hits:" & Natural'Image (Hits));
Put_Line ("clamped:" & Integer'Image (Clamp (42, 0, 10)));
end Main; verada.toml
[project]
source-dirs = ["src"] src/counters.va
package Counters {
pub fn clamp(value, low, high: Integer) -> Integer
requires low <= high
ensures result in low..=high
{
if value < low {
return low;
} else if value > high {
return high;
}
return value;
}
pub fn increment(count: inout Natural)
requires count < Natural::Last
ensures count == old(count) + 1
{
count += 1;
}
} src/main.va
import Ada.Text_IO; use Ada.Text_IO;
import Counters; use Counters;
fn main() {
var hits: Natural = 0;
increment(&hits);
increment(&hits);
Put_Line("hits:" ++ Natural::Image(hits));
Put_Line("clamped:" ++ Integer::Image(clamp(42, 0, 10)));
} verada.toml
[project]
source-dirs = ["src"] src/counters.vb
from verada import Natural, ensures, requires, result
def clamp(value: int, low: int, high: int) -> int:
requires(low <= high)
ensures(low <= result <= high)
if value < low:
return low
elif value > high:
return high
return value
def increment(count: Natural) -> Natural:
requires(count < Natural.last)
ensures(result == count + 1)
return count + 1 src/main.vb
from counters import clamp, increment
def main() -> None:
hits = 0
hits = increment(hits)
hits = increment(hits)
print("hits:", hits)
print("clamped:", clamp(42, 0, 10))
if __name__ == "__main__":
main() Start your own project.
veradic new writes a project file, a small program with a contract,
and a .gitignore in a new directory. Choose vada,
varc or vibe; Vada is the default.
veradic new hello --syntax varc
cd hello
veradic check
veradic prove
veradic run
This starter prints hello: 42; the tour's larger Counters
example is shown above. In VS Code, Verada: New Project…
creates the same starter and opens its folder. See
starting a project
for the options.
To create a starter and open its browser IDE in one step, use
veradic ide new ~/Projects/hello --syntax varc.
For a project you already created, run veradic ide .
from its directory.
4 · Check, prove, run, build
Four commands.
- veradic check
- Syntax, names, types and flow, without proof. Silence means it checks.
- veradic prove
- Proves every run-time check and every contract, and counts them.
- veradic run
- Compiles the program in memory with LLVM's JIT and runs it.
- veradic build
- Proves, compiles each unit and links a native executable.
Run them in the project's directory. Vibe's increment
is a function, so it has fewer checks to prove than the procedure
in Vada and Varc.
$ veradic check
$ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
$ veradic run
hits: 2
clamped: 10
$ veradic build -o counters
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
built counters
$ ./counters
hits: 2
clamped: 10 $ veradic check
$ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
$ veradic run
hits: 2
clamped: 10
$ veradic build -o counters
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
built counters
$ ./counters
hits: 2
clamped: 10 $ veradic check
$ veradic prove
proved 12 of 12 checks in 3 subprograms (5 statically, 7 by the solver)
$ veradic run
hits: 2
clamped: 10
$ veradic build -o counters
proved 12 of 12 checks in 3 subprograms (5 statically, 7 by the solver)
built counters
$ ./counters
hits: 2
clamped: 10 5 · Break it
Take the precondition away.
Delete increment's precondition and prove again. The
build stops, and Verada says why:
src/counters.vads
package Counters is
function Clamp (Value, Low, High : Integer) return Integer
with Pre => Low <= High,
Post => Clamp'Result in Low .. High;
procedure Increment (Count : in out Natural)
with Post => Count = Count'Old + 1;
end Counters; $ veradic prove
error[B4101]: overflow check fails
--> src/counters.vadb:16:16
|
16 | Count := Count + 1;
| ^^^^^^^^^ might overflow `Integer` (-9223372036854775808 .. 9223372036854775807)
|
= note: replaying these values on the program reaches this check and it fails
= counterexample: fails when Count = Integer'Last
= failing inputs: exactly Count = Integer'Last
= help: a precondition `Count <= 9223372036854775806` on `Counters.Increment` excludes exactly the values that fail, and is proved to make this check pass
1 error emitted
proved 11 of 12 checks in 3 subprograms (4 statically, 7 by the solver) src/counters.va
package Counters {
pub fn clamp(value, low, high: Integer) -> Integer
requires low <= high
ensures result in low..=high
{
if value < low {
return low;
} else if value > high {
return high;
}
return value;
}
pub fn increment(count: inout Natural)
ensures count == old(count) + 1
{
count += 1;
}
} $ veradic prove
error[B4101]: overflow check fails
--> src/counters.va:17:15
|
17 | count += 1;
| ^^^^ might overflow `Integer` (-9223372036854775808 .. 9223372036854775807)
|
= note: replaying these values on the program reaches this check and it fails
= counterexample: fails when count = Integer::Last
= failing inputs: exactly count = Integer::Last
= help: a precondition `count <= 9223372036854775806` on `Counters.increment` excludes exactly the values that fail, and is proved to make this check pass
1 error emitted
proved 11 of 12 checks in 3 subprograms (4 statically, 7 by the solver) src/counters.vb
from verada import Natural, ensures, requires, result
def clamp(value: int, low: int, high: int) -> int:
requires(low <= high)
ensures(low <= result <= high)
if value < low:
return low
elif value > high:
return high
return value
def increment(count: Natural) -> Natural:
ensures(result == count + 1)
return count + 1 $ veradic prove
error[B4101]: overflow check fails
--> src/counters.vb:16:12
|
16 | return count + 1
| ^^^^^^^^^ might overflow `Integer` (-9223372036854775808 .. 9223372036854775807)
|
= note: replaying these values on the program reaches this check and it fails
= counterexample: fails when count = 9223372036854775807
= failing inputs: exactly count = 9223372036854775807
= help: a precondition `count <= 9223372036854775806` on `counters.increment` excludes exactly the values that fail, and is proved to make this check pass
1 error emitted
proved 9 of 10 checks in 3 subprograms (4 statically, 5 by the solver)
Without the precondition a caller may pass the largest
Natural, and adding one to it overflows. Verada found that
input, replayed it on the program to show the failure is real, and
worked out exactly which inputs fail and the precondition that
excludes them, which it has already proved to be enough.
To fix it, put a precondition back: the one Verada suggests, or the
original, which says the same thing in terms of
Natural. Prove again and every check passes.
veradic explain B4101 explains any numbered diagnostic.
$ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver) $ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver) $ veradic prove
proved 12 of 12 checks in 3 subprograms (5 statically, 7 by the solver) 6 · Day to day
Prove, then run.
Proofs are kept in the project's proof cache, under
.verada/. In a project, veradic run
starts at once with the proofs the cache holds and keeps every
check not proved yet as a run-time check, saying so with warning
B8012. So prove, then run: prove fills the cache, and
the next run leaves every proved check out.
By default, build proves before producing an executable.
The proving commands take -j N, the number of solvers
to run at once; by default it is half the processor cores.
$ veradic run
warning[B8012]: 7 checks are not proved yet, and are kept as run-time checks
= note: this build used only the proofs the project's proof cache holds (`--proof cached`), so it did not wait for the prover
= help: build with `--proof full` to prove them first, or run `veradic prove`
1 warning emitted
hits: 2
clamped: 10
$ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
$ veradic run
hits: 2
clamped: 10 $ veradic run
warning[B8012]: 7 checks are not proved yet, and are kept as run-time checks
= note: this build used only the proofs the project's proof cache holds (`--proof cached`), so it did not wait for the prover
= help: build with `--proof full` to prove them first, or run `veradic prove`
1 warning emitted
hits: 2
clamped: 10
$ veradic prove
proved 14 of 14 checks in 3 subprograms (5 statically, 9 by the solver)
$ veradic run
hits: 2
clamped: 10 $ veradic run
warning[B8012]: 5 checks are not proved yet, and are kept as run-time checks
= note: this build used only the proofs the project's proof cache holds (`--proof cached`), so it did not wait for the prover
= help: build with `--proof full` to prove them first, or run `veradic prove`
1 warning emitted
hits: 2
clamped: 10
$ veradic prove
proved 12 of 12 checks in 3 subprograms (5 statically, 7 by the solver)
$ veradic run
hits: 2
clamped: 10 In the editor
Proofs in the background.
Verada's extensions for VS Code and Zed start its language server,
veradic lsp. It checks as you type and, once the text
checks cleanly, proves it in the background. A lens above each
subprogram shows its proof state: proving, proved, or how many
checks are not proved, with a failed proof's counterexample above
the check.
The editor's proofs go into the same proof cache, so a
veradic run in the terminal leaves out what the editor
has already proved. Any other editor with a language server client
gets the same behaviour from veradic lsp.
VS Code also has Check, Prove, Run and Build buttons above the editor. They run on the current file's project, with output in a terminal and diagnostics in the Problems panel. Cmd+Shift+B on macOS runs Build. The editor guide covers project commands and tasks.
code_lens setting is "on".
These editor screenshots show an earlier build. The current beta uses
a 64-bit Integer, so its overflow counterexample has a larger bound.
7 · What a proof guarantees
No run-time errors. Every contract.
A proved program cannot overflow, index outside an array, put a value out of its type's range, divide by zero or dereference null, and every contract holds: preconditions at each call, postconditions at each return, and every invariant and assertion. Flow analysis adds that no variable is read before it is set.
A proof rests on what it trusts. veradic trust lists
it in one report: assumptions, anything justified by review instead
of proof, raised proof budgets, the predefined library and the
solvers. For this project there are no assumptions of its own.
$ veradic trust
assumed, not proved: none
justified by review, not proved: none
proved outside Verada: none
proof budgets raised: none
the predefined library:
its contracts are trusted by its clients; its bodies are proved when Verada is built, except the C run-time's (Verada.Strings.Texts.To_Text assumes what it keeps)
the solvers:
Z3's, cvc5's and Yices's answers are trusted (`prove --check-proofs` checks cvc5's proofs of them with Carcara) $ veradic trust
assumed, not proved: none
justified by review, not proved: none
proved outside Verada: none
proof budgets raised: none
the predefined library:
its contracts are trusted by its clients; its bodies are proved when Verada is built, except the C run-time's (Verada.Strings.Texts.To_Text assumes what it keeps)
the solvers:
Z3's, cvc5's and Yices's answers are trusted (`prove --check-proofs` checks cvc5's proofs of them with Carcara) $ veradic trust
assumed, not proved: none
justified by review, not proved: none
proved outside Verada: none
proof budgets raised: none
the predefined library:
its contracts are trusted by its clients; its bodies are proved when Verada is built, except the C run-time's (Verada.Strings.Texts.To_Text assumes what it keeps)
the solvers:
Z3's, cvc5's and Yices's answers are trusted (`prove --check-proofs` checks cvc5's proofs of them with Carcara) 8 · Where next
Much Ado About Verada.
The tutorial book takes you from a first program to a proved box office in fifteen short chapters, every example in all three syntaxes. After it, the user manuals document the languages, the verification and the tools in full.