A Formalization of the Yul Language and Some Verified Yul Code Transformations
Alessandro Coglio Eric McCarthy · 2025
Read A Formalization of the Yul Language and Some Verified Yul Code Transformations by Alessandro Coglio Eric McCarthy (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2507-19012.txt.
Introduction
Alessandro Coglio and Eric McCarthy present formal work from twenty twenty-five on Yul, a computer language. Yul sits in the middle of compiling Solidity, the language used for Ethereum smart contracts. A compiler changes Yul code through a chain of steps that users can adjust. If a step is wrong, the final contract may act in the wrong way.
The authors used a proof tool called ACL2 to build a strict formal version of Yul. They defined its form and its meaning, and proved how the two relate. They also formalized some code changes and proved those changes correct. Readers who build compilers get a checked base for trusting such changes.
Catalog record
| CREATOR | Alessandro Coglio Eric McCarthy |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 55 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2507-19012
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
A Formalization of the Yul Language and Some Verified Yul Code Transformations Alessandro Coglio Eric McCarthy Abstract Yul is an intermediate language used in the compilation of the Solidity programming language for Ethereum smart contracts. The compiler applies customizable sequences of transformations to Yul code. To help ensure the correctness of these transformations and their sequencing, we used the ACL2 theorem prover to develop a formalization of the syntax and semantics of Yul, proofs relating static and dynamic semantics, a formalization of some Yul code transformations, and correctness proofs for these transformations. 1 Introduction Solidity [ 22 , 19 ] is a programming language for writing smart contracts for the Ethereum blockchain [ 10 ] . Solidity is compiled to EVM (Ethereum Virtual Machine) bytecode [ 27 ] , which is directly executed by transactions on the blockchain. The Solidity compiler includes the preferred option to translate Solidity to EVM bytecode via the intermediate language Yul [ 21 ] (see Figure 1 ): first, Solidity is turned into Yul with a relatively simple translation; next, the Yul code undergoes several optimizing transformations; finally, the optimized Yul code is turned into EVM bytecode with another relatively simple translation. The rationale is to move most of the compilation complexity into the Yul code transformations, which eases the task because Yul is simpler than Solidity and more structured than EVM bytecode. Yul is also used to write inline assembly in Solidity, i.e. to embed EVM bytecode (with Yul syntax) directly in the Solidity code, which is sometimes necessary in Ethereum smart contracts. Solidity EVM Yul to Yul Yul transformations Solidity to Yul Yul to EVM Yul Yul … … Figure 1: Solidity Compiler with Yul Transformations Yul is designed to be usable as an intermediate language to compile other front ends than Solidity to other back ends than EVM bytecode. In line with this aspiration, Yul consists of a core (‘pure Yul’ or ‘generic Yul’) independent from front and back ends, which is extensible with dialects tailored to specific front and back ends. Currently only the EVM dialect is defined, for compiling Solidity to EVM bytecode. A Yul dialect extends the Yul core with specific types and operations. A few tens of Yul transformations have been defined and implemented [ 20 ] . Some are dialect-independent, while others are EVM-dialect-specific. Some transformations assume that others have already taken place, i.e. they expect the code to be in a certain form, which the previous transformations produce. Some transformations, or sequences of transformations, may be iterated, i.e. applied multiple times until either nothing changes or an iteration limit is reached. The Solidity compiler uses a default sequence of transformations, which can be overridden by the user. It is critical that Yul transformations and their sequencing are correct. Each transformation must be applied to code of the expected form, as produced by the preceding transformations, and must produce code semantically equivalent to the input code. This paper reports on our preliminary work towards addressing these problems, using the ACL2 theorem prover [ 13 ] . We developed a formalization of the syntax and semantics of Yul, which covers the generic core and a small portion of the EVM dialect; we proved some properties of the formalization, most notably that the static semantic checks rule out dynamic semantic errors. We formalized some Yul transformations, and verified that they preserve both static and dynamic semantics. We formalized some restrictions on Yul code that are expected by some transformations, and verified that they are preserved by some transformations. Although we have only scratched the surface of verifying transformations and their sequencing, we believe that our work shows the feasibility of the approach. Our ACL2 library for Yul, which contains our development, is available at [ 26 , [books]/kestrel/yul ] and documented at [ 25 , yul ] . After providing some background on Yul in Section 2 , we describe our formalization of Yul in Section 3 , and our work on verified transformations in Section 4 . Related work is surveyed in Section 5 , while future work is discussed in Section 6 . Some closing remarks are given in Section 7 . Background on Solidity and the EVM can be found in a variety of sources, starting with the Ethereum web site [ 10 ] . However, knowledge of Solidity and the EVM is not required to read this paper. 2 Background on Yul Yul is a statically typed, block-structured, imperative language. Statements consist of function definitions, variable declarations and assignments, conditionals, loops, control transfers, expressions (for side effects), and nested blocks. Expressions consist of literals, variables, and function calls. A function takes zero or more inputs and returns zero or more outputs; if it returns no outputs, it is only used for side effects, as a statement. The Yul core has no types, and no syntax to define types. The EVM dialect has a single type u256 , consisting of 256-bit unsigned integers. If a type is omitted (e.g. in a variable declaration), it defaults to a type specified by the dialect; the EVM dialect necessarily defaults to u256 , which is the only type. The Yul core includes boolean literals ( true and false ), numeric literals in decimal and hexadecimal base (e.g. 64738 and 0xff0012 ), and certain forms of string literals (e.g. "abc" and hex"90a4" ). The EVM dialect defines the meaning of literals as u256 values: boolean literals denote 0 and 1, numeric literals denote the obvious, and string literals yield byte sequences interpreted as integers in base 256. It is a static error if a literal denotes 2^{256} or more, e.g. if a string literal yields more than 32 bytes. Variables are declared via the let keyword, with or without a type (see above), and with or without an initializing expression; if the latter is missing, the variable is initialized to 0 . In the EVM dialect, let x declares a variable x of type u256 initialized to 0 , while let y := x declares a variable y of type u256 initialized to the current value of x . A variable assignment is like a variable declaration without let , e.g. x := 17 assigns 17 to x . A call of a function that returns two or more outputs can be used to initialize, or to assign to, multiple variables, e.g. let a, b := f(...) initializes a and b to the first and second result of f . If multiple variables are declared without initializing expressions, they are all initialized to 0 , as in the case of a single variable, e.g. let a, b . A function definition returns results by assigning them to its output variables, which are declared as part of the function definition, along with the input variables. For example, in a function definition of the form function f(x, y) -> a, b { ... a := ... b := ... } , the input variables are x and y , and the output variables are a and b . If a function terminates execution without assigning a value to some output variables, the corresponding result is 0 . The leave statement can be