Automating creativity
Under the Hood
The short version: NStatic reads your C# code the way a mathematician reads an equation — and then solves it.
Most static analyzers work by pattern matching: they look for known-bad code patterns and flag them. This approach is fast and simple, but it misses bugs that don't fit the patterns, and it generates false positives for code that matches the pattern but is actually safe.
NStatic takes a fundamentally different approach. It translates your C# code into a mathematical representation — a denotational semantics — and then reasons about that representation algebraically. This is the same approach used in formal verification research, brought to the scale of everyday .NET development.
In a denotational model, the meaning of a program is built from the meanings of its parts — mechanically, without special cases. This makes the analysis easier to extend: adding a new language construct means defining its mathematical translation, not teaching the analyzer about a new pattern.
Lambda calculus handles higher-order functions naturally — lambdas, closures, delegates, and iterators are all just functions. Most Hoare-logic tools struggle with these; denotational semantics makes them first-class.
Once code is an expression, algebraic identities apply. x + 0 = x.If(True, A, B) = A. Fix(λf.λx. x) = Identity. These reductions eliminate large classes of potential false positives without any special-case code.
The denotational model represents loops as fixed points, which can sometimes be solved to closed forms. This is unique to the functional/denotational approach — Hoare-logic tools require user-supplied loop invariants; path-exploration tools unroll a bounded number of iterations.
NStatic is most closely related to the K Framework (denotational semantics for any language) and Maude (term rewriting with equational theories). The approach of abstracting the definitional interpreter — deriving an analysis from the language semantics itself — has been explored academically inAbstracting Definitional Interpreters (Darais et al., 2017).
In the .NET ecosystem, the closest tool is Pex / IntelliTest (Microsoft Research, built around the same time as NStatic), which also targets .NET but uses symbolic execution with Z3 as the SMT backend rather than in-process algebraic simplification.Clousot (Code Contracts analyzer) uses abstract interpretation on MSIL — a different but related approach.
NStatic's distinguishing characteristic is that it keeps everything in-process — no external SMT solver — and relies on algebraic simplification and closed-form loop solving rather than path enumeration or abstract domain widening. This trades completeness for transparency: when NStatic can solve something, it shows you exactly how.
Join the waitlist and be first to try NStatic when it ships for Visual Studio.
Join the Waitlist