FVO — Formal Verification Online
📘 Formal verification guide

Formal verification for RISC-V processors

9 min read · Updated

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.

RISC-V coreunchanged RTLRVFIper-instruction checkersconsistency checkersBMC (sby)
The core reports every retired instruction on RVFI; small checkers compare it with the ISA.

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

BlockTypical formal properties
Pipeline controlNo instruction lost or duplicated, correct stalls and flushes, forwarding returns the newest value
Register file, CSRsRead returns last write; privileged CSRs not writable from user mode
Caches and memory systemData integrity with a symbolic address, no lost writes, coherence invariants
Bus interfacesProtocol compliance (valid/ready, AXI rules), no deadlock — see handshakes and credits
Interrupts and exceptionsPrecise exceptions, correct cause and return address, interrupts eventually taken
SecurityPrivilege checks, no leakage of secrets into architecturally visible state

A practical roadmap for your own RISC-V core

  1. Add RVFI outputs to the core (a few dozen signals) and run riscv-formal's consistency and instruction checks with BMC.
  2. Write FPV environments for risky blocks: the load/store unit, the CSR file and the bus interface.
  3. Use tracked items and symbolic addresses for data integrity (tracked-item technique).
  4. Add covers for every exception type and pipeline hazard to show the environment is rich enough.
  5. 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.

Learn it hands-on

More from the formal verification guide

← Back to formal verification foundations: the complete guide

Discussion

No comments yet.

Was this page helpful?

Tip: select any text on the page before clicking Report and it will be quoted in your report.