Formal verification for RISC-V processors
This article is part of our formal verification guide, which covers the foundations, model checking, solvers, theorem proving, equivalence checking and industry use cases.
RISC-V made processor design open to everyone — and with it, processor verification. Because the ISA is open and has an official formal model, RISC-V is one of the best places to see formal verification applied to a complete CPU, from individual instructions to caches and interrupts.
Why formal fits processors so well
- Processor bugs hide in rare interactions: a load hitting a pending store in the same cycle as an interrupt and a pipeline flush. Random simulation reaches such combinations slowly; formal tools explore them all.
- The specification is precise: every instruction has an exact meaning, which makes it ideal for automatic checking.
- The cost of a silicon bug in a CPU is extremely high, and security bugs (speculative leaks, privilege escalation) are especially hard to find by testing.
A formal ISA specification: Sail
The RISC-V specification is written in English, but RISC-V International also maintains an executable formal model of the ISA written in Sail, a language for describing instruction-set semantics. The Sail model serves as a golden reference: it can generate emulators for comparison testing and formal definitions for theorem provers, so "what does this instruction do?" has one unambiguous answer.
ISA compliance with model checking: RVFI and riscv-formal
The open-source riscv-formal framework (from the YosysHQ / SymbiYosys community) checks a core against the ISA using bounded model checking. The core exposes a standard trace port, the RISC-V Formal Interface (RVFI): for every retired instruction it reports the instruction word, the registers read and written with their values, the PC before and after, and any memory access.
Two kinds of checks run on the RVFI trace:
- Instruction checks: for an arbitrary retired instruction, the destination register value and next PC must equal what the ISA says, given the reported source operands.
- Consistency checks: the value read from a register equals the last value written to it, PCs are consecutive, instructions retire in order and none are skipped or duplicated.
Notice the techniques: the checkers follow one arbitrary instruction and one arbitrary register — symbolic variables exactly as taught in symbolic (oracle) variables — so a short bounded run covers every instruction and register. Bugs found this way include wrong forwarding, broken exceptions and illegal instructions that are silently executed.
Beyond ISA compliance: block-level FPV
| Block | Typical formal properties |
|---|---|
| Pipeline control | No instruction lost or duplicated, correct stalls and flushes, forwarding returns the newest value |
| Register file, CSRs | Read returns last write; privileged CSRs not writable from user mode |
| Caches and memory system | Data integrity with a symbolic address, no lost writes, coherence invariants |
| Bus interfaces | Protocol compliance (valid/ready, AXI rules), no deadlock — see handshakes and credits |
| Interrupts and exceptions | Precise exceptions, correct cause and return address, interrupts eventually taken |
| Security | Privilege checks, no leakage of secrets into architecturally visible state |
A practical roadmap for your own RISC-V core
- Add RVFI outputs to the core (a few dozen signals) and run riscv-formal's consistency and instruction checks with BMC.
- Write FPV environments for risky blocks: the load/store unit, the CSR file and the bus interface.
- Use tracked items and symbolic addresses for data integrity (tracked-item technique).
- Add covers for every exception type and pipeline hazard to show the environment is rich enough.
- Keep it in regression: formal runs make excellent nightly checks on every RTL change.
For the foundations behind these techniques, read the formal verification guide.