rustyAC

How it works

rustyAC is not written to feel like Assetto Corsa. It is written to compute the same numbers, and then made to prove it.

There are four steps, and every part that is ported goes through all of them: decompile the original, map what it does, port it to Rust one to one, and prove the port by running it next to the original's own code until every bit matches.

The rustyAC pipeline Four steps in a row. Decompile acs.exe and its debug symbols in Ghidra. Map each system into a written report. Port it to Rust, one to one, from the disassembly. Prove it: the oracle compares every bit. When a bit differs, the port is fixed and the proof runs again. 01 Decompile acs.exe and its debugsymbols, in Ghidra 02 Map a written reportfor each system 03 Port Rust, one to one,from the disassembly 04 Prove the oracle comparesevery bit a bit differs: fix the port, run it again
Each system that is ported goes through the same four steps.

1. Decompile

Assetto Corsa is one native program, acs.exe (game version 1.16.4, built on 2018-01-10, 22,890,776 bytes). It ships with its debug symbols, acs.pdb, a 66 MB file that holds the real names of the game's functions and data. Loaded into Ghidra 12 together, the decompiler shows Tyre::addTyreForcesV10 where it would otherwise show an address.

All 7,453 hand-written functions of the game were decompiled. The symbols also show what the game is built on: its rigid-body physics is ODE 0.13.1, an open-source library, compiled into the program (609 functions of it).

2. Map

Before any Rust is written, each system gets a written report: what its functions do, in what order, with which constants, and which file each number comes from. There are sixteen of these maps, from the tyre to the force-feedback number.

Each map was then attacked by a second, independent reviewer: 658 claims were checked against the code, and 54 were found wrong and fixed. Every address in every document is checked by a script.

A few to read: the whole car, one physics step, the tyre, the physics engine.

3. Port

The port is Rust, one to one: the same functions, the same fields, the same order of operations. The rule that makes it work is to transcribe from the disassembly, not from the decompiler's pseudo-C.

The pseudo-C is right about what is computed, but it regroups arithmetic. In the tyre formula it shows (cos · speed) · slipRatio where the real code computes cos · (speed · slipRatio). With floating-point numbers those two can differ in the last bit, and a last bit is the whole point.

The same goes for source code, where there is any. The physics library's source is public, but a literal port of it matched the game on only 54 % of the steps of a car: the game's machine code adds some sums in packed four-lane blocks, which add up in a different order. So the game's machine code was followed, not the source text.

The Ferrari F2004 at speed at Spa, seen from the chase camera in rustyAC
The F2004 at Spa, 175 km/h, drawn by rustyAC with Assetto Corsa's own shaders.

4. Prove

The test tool is called the oracle. It loads the real acs.exe into its own process as a plain block of code. The game never starts: its entry point and start-up code never run. The oracle then calls the game's own functions directly, by the addresses from acs.pdb, and asks the Rust port the same question. The two answers are compared as bit patterns, not as rounded numbers.

The oracle The same inputs, step by step, go to two places: the real acs.exe, mapped into the test program and called by the addresses from its debug symbols, and rustyAC's Rust port of the same functions. The numbers both give back are compared bit by bit. Either all are equal, or the port is fixed and the comparison runs again. inputs The same for both the driver's controls, step by step acs.exe, the real game The game's own functions mapped into the test program and called by their address from acs.pdb rustyAC, the port The same functions in Rust rewritten one to one, in the same order of operations compare Every bit of every number all equal: done one bit off: not done, fix the port and run again numbers out numbers out
The game is never started. Its code is only borrowed, one function at a time, to answer the same question the port is asked.

It refuses to run against any other build of the game than the one that was decompiled. And the comparison is checked too: deliberate small faults were put into the Rust car, one at a time (24 in the whole car), and each one was caught.

WhatHow muchResultReport
The tyre formula 329,734 rows, seven numbers each zero differences read
A whole tyre 97,800 steps the same in every step (93,200 bit for bit; the rest are not-a-number inputs) read
The rigid-body solver 1,996,043 steps identical read
A whole car 49 drives, 228,184 steps identical read
Every track 8,800,000 ray casts; 89 drives, 2,752,168 steps zero differences (one value is left out on the drag strips) read
Sound 18 drives, 16,704,338 FMOD calls every argument bit-equal read
The car, drawn 27 sequences, 2,353 frames same commands, same pixels read
The browser build 160 drives, 1,787,777 steps equal to the desktop read

The car oracle

For a whole car, the oracle builds the game's real car, a Ferrari F2004 with all its parts, by calling the game's own constructors. It gives it a flat road, a scripted driver and a clock that only moves when told to. Twelve drives were recorded this way, 70,673 steps in all; each was run twice from scratch, and both runs give the same checksum over every byte. Those recordings are what the Rust car is held against. The car oracle's report.

The render oracle

The renderer is proven the same way. The game's own renderer and the port each draw the same frame on WARP, Windows' software graphics card, which gives the same pixels on every run. Two things are compared: the list of Direct3D 11 commands, as text, and the finished picture, byte by byte. On the first 21 frames the two command lists were identical line for line (up to 5,943 commands a frame) and the pictures identical in every byte. Later tasks added whole sequences, and a real graphics card: on a Radeon the port matches the game's renderer with 1, 2, 4 and 8 anti-aliasing samples.

The cockpit of the Ferrari F2004 at Spa in rustyAC, with the steering wheel display lit
The F2004's cockpit: the dials, the display and the mirrors are the game's own, drawn by the port.

The audio oracle

Sound is Assetto Corsa's own: rustyAC loads the game's FMOD libraries and sound banks from your install. The oracle logs every call into FMOD from the game and from the port. On 18 recorded drives the port makes exactly the calls the game makes: 16,704,338 of them, every argument bit-equal. The sound itself is written to WAV files without a sound card, faster than real time.

Those WAV files are not identical, and that is FMOD: it mixes with random numbers of its own, so two runs of the game's own code never gave the same file either. The port's sound is held to the game's own run-to-run difference instead.

The maths library

The game does not compute its own sines and powers. It calls sinf, cosf, powf and a few more from MSVCR120.dll, the Visual C++ 2013 runtime. A different sinf would be a different game, so on the desktop rustyAC calls that same DLL.

A browser cannot load a DLL. So the ten functions were read out of the DLL's machine code and written again in Rust, instruction by instruction, and then proven:

  • for each of the seven one-argument functions, every one of the 4,294,967,296 possible inputs gives the same bits as the DLL
  • the two-argument functions (powf, atan2f) have too many input pairs to try them all, so they were tried on 59 billion more inputs: not one difference

That copy is what lets the browser preview stay exact. It is also the desktop's fallback when the DLL is not installed.

The FMA3 finding

Reading the DLL turned up a surprise about the game itself. The DLL has two versions of six of these functions and picks one by the processor: one for CPUs with the FMA3 instructions (everything since about 2013), one for older ones. The two do not give the same results: 44,232 of the 4.29 billion sinf inputs differ, and 18,018 for cosf.

So Assetto Corsa is not bit-exact with itself: a drive recorded on a pre-2013 processor would not replay bit for bit on a modern one, in the real game either. rustyAC's Rust copy is the modern path, the one the game runs on any current processor.

What "bit-exact" means here

It means this and nothing more: for the same inputs, on the same processor path, the port's numbers have the same bits as the numbers from the game's own code. The game is plain Assetto Corsa 1.16.4, without Custom Shaders Patch.

What it does not mean, and what is not proven yet:

  • Older processors. The maths path of CPUs without FMA3 is not ported. One more instruction gives different last bits on Intel and AMD processors; the browser build computes what an Intel desktop computes.
  • The browser. The 160-drive proof runs the physics as WebAssembly outside a browser. In the browser itself the check is a 10,000-step test drive on three car and track pairs.
  • The sound mix. The calls are identical; the mixed samples are not, because FMOD is random.
  • The picture. The game's post-processing filters are not ported yet. The pixel proofs are for the renderer without them. And the test gives both sides some of the same inputs (the track models, the camera), so a mistake in those would not show as a difference.
  • Code no test reached. A recorded drive only proves the branches it takes. The reports list the ones that were ported from the disassembly but never run against the game.
  • What is not ported at all: AI drivers, race rules, menus. See progress.

All of it is in the open: the reports say what was run, how to run it again, and what was left out.