Type-Confusion Security
Silei Ren, Hanxi Chen, Suraaj Kanniwadi, Andrew C. Myers
cs.PL
Nov 15, 2026 · v1
cs.CR
TL;DR
All security results of an information-flow-typed core calculus, including type-confusion security and examples, are mechanized in Lean 4 with Mathlib, sorry-free.
Abstract
Type systems are a lightweight way to obtain formal assurance that code upholds security properties. However, decentralized systems, such as smart contracts and Model Context Protocol ecosystems, have limited ability to constrain the behavior of untrusted code. In such systems, attackers may attempt to confuse trusted code by supplying values that do not behave according to their advertised types, an attack that we call type confusion. Well-known attacks such as confused deputy attacks, reentrancy attacks, and control-flow hijacking can be understood as instances of type confusion. We define type confusion security as the property that unrestricted attackers who need not follow the type system have no more power than limited attackers who fully obey it. We formally define type confusion security as a real–ideal emulation, and in the context of an information-flow-typed core calculus that statically enforces security against well-typed attackers, prove that its run-time checks also enforce security against ill-typed attackers. In this system, programmers can write code while reasoning about security only against well-typed attackers; the security guarantees enforced by the type system still hold. We mechanize a proof of type confusion security in Lean.
Problem
In decentralized systems such as smart contracts and MCP ecosystems, attackers can supply values that do not behave according to their advertised types (type confusion). Confused deputy and reentrancy attacks are instances of this. Static security type systems are not sound against such ill-typed attackers.
Approach
Type-confusion security is defined as a real–ideal emulation: every unrestricted, ill-typed real attacker must be simulable by a well-typed ideal attacker. The setting is an information-flow-typed core calculus with first-class function pointers and remote calls, in which the attacker is modeled as a state machine. The proof composes simulations across four worlds using context-based backtranslation. All results are mechanized in Lean 4 with Mathlib, with AI coding assistants helping under human guidance.
Results
The calculus's run-time checks enforce security against ill-typed attackers, so confused-deputy and reentrancy security proved for well-typed attackers transfer to all worlds. The Lean artifact contains no sorry, relies only on standard classical axioms, and also proves type safety.