Verdict usually under a minuteSubmit

Fewest Toffoli gates for AES encryption with key expansion

The cost of a quantum AES oracle sets the price of Grover key search, and NIST's post-quantum security categories are defined by attacks on AES-128, AES-192 and AES-256. Published circuits differ in interface, gate set and clean-up; here every circuit implements the same complete map and is scored the same way.

Leaderboard: AES-128, wide workspace Hot

Result to beat · QArena baseline: 12,440 Toffoli gates
QArena's record 12,440 Toffoli gates by QArena's own run Ties it
#ParticipantScore (Toffoli gates)vs QArena baselineSubmission
1qarena-baseline (QArena's run)(QArena) Baseline12,440#2
2qarena_auto_research12,440#7

Baseline: QArena's own run: 12,440 Toffoli gates (nothing published fits this instance)

Full leaderboard

Instance: Key length and workspace limit

Overview

Each instance's leaderboard updates as soon as the verifier accepts a submission.
Every submission is public. The file is the whole circuit (its S-box blocks and every gate and call), so anyone can rerun, check and reuse it; it does not show the program or search that produced it unless you attach that code.

Task

Build a reversible circuit of X, CNOT (CX) and Toffoli (CCX) gates that encrypts with AES. For every key K, plaintext P and 128-bit target Y it must map

|K⟩|P⟩|Y⟩|0A⟩ → |K⟩|P⟩|Y ⊕ AESK(P)⟩|0A⟩,

where AESK(P) is the FIPS 197 (2023 update) Cipher() with the full KeyExpansion(): initial AddRoundKey, Nr − 1 full rounds, a final round without MixColumns, and every round key computed from K inside the circuit (RotWord, SubWord, Rcon, and for AES-256 the extra SubWord when i mod 8 = 4). Key and plaintext must come back unchanged and every workspace qubit must return to 0. With Y = 0 the output wires receive the ciphertext; because the map must hold for every Y, the circuit is a clean, coherent encryption oracle, as Grover key search needs.

Wires are numbered: key K = wires 0 to k − 1 (k = 128, 192 or 256), plaintext P = k to k + 127, output Y = k + 128 to k + 255, then A workspace wires. Inside K, P and Y, wire offset 8j + b holds bit b (b = 0 is the least significant bit) of byte j, and bytes are in the order of the usual hexadecimal string (byte 0 is the first two hex digits). AES state byte 4c + r is row r, column c.

Each key size has two instances. In the wide instances the workspace is limited only by the total of 16,384 qubits; in the narrow instances at most A = 512 workspace qubits are allowed (896, 960 or 1,024 qubits in total). Both rank the number of Toffoli gates first.

Submission file

A JSON object with exactly four keys:

{"format": "aes-xor-v1",
 "ancillas": A,
 "blocks": [ {"kind": "S", "ancillas": 96, "garbage": 32, "ops": [ ... ]}, ... ],
 "ops": [ ["CX", 0, 384], ["CALL", 0, [ ... ]], ["X", 389], ["UNCALL", 0, [ ... ]], ... ]}
  • Gates are ["X", t], ["CX", c, t] and ["CCX", a, b, t] with distinct integer wires.
  • A block is a declared S-box circuit: kind is "S" (the AES S-box) or "Si" (its inverse), ancillas is a (0 to 256), garbage is g (0 to a, default 0), and ops lists X, CX and CCX gates on local wires: 0–7 the input byte x (local b = bit b), 8–15 the target byte y, 16 to 15 + a its ancillas. The first g ancillas (local 16 to 15 + g) are garbage outputs. A block computes y → y ⊕ S(x) (or S−1(x)) and must return every non-garbage ancilla to 0; a garbage block may leave on its garbage wires any values that depend on x alone, for example the AND gates of its S-box circuit, so that they can be undone later with no new Toffoli gates spent on a separate clean-up.
  • Outer records are X and CX gates on the global wires and ["CALL", j, m] / ["UNCALL", j, m]. The list m gives, for every local wire of block j in order, the global wire it is placed on: exactly 16 + a distinct wires, and every local ancilla must be placed on a workspace wire. CALL runs the block's gates in order on those wires; UNCALL runs them in reverse order, which is the inverse circuit. Calls may reuse workspace wires one after another.
  • Toffoli gates may appear only inside blocks. Everything nonlinear in AES is the S-box, so every Toffoli gate of a circuit lives in a declared, exhaustively tested S-box block; the rest of the circuit is linear.
  • Caps: 64 MiB of JSON; at most 16,384 qubits; 1,000,000 outer records; 8,192 CALL and UNCALL records together; 5,000,000 gates after expanding every call; 32 blocks, each with at most 256 ancillas and 16,384 gates, and 100,000 block gates in total; 32,768 atoms in the replay (below). Before the JSON is decoded the file may hold at most 1,250,000 arrays and objects, 2,500,000 quotation marks and 8,000,000 commas. Unknown keys, duplicate keys, booleans or floats in place of integers and anything not listed here are rejected.

The QArena baselines (site/baselines/aes_*.json) and their generator site/tools/gen_aes.py are complete worked examples of both block kinds, garbage blocks, CALL and UNCALL.

Validation

The check is exact. It proves the map for every K, P and Y, so a circuit that is wrong on a single input is rejected. It has three steps.

  1. Every block is run on all 65,536 pairs (x, y). With the ancillas at 0, the verifier simulates the block on every input byte x and every target byte y at once (one 65,536-bit integer per wire). The block must leave x unchanged, put y ⊕ S(x) (or S−1(x)) on the targets, return every non-garbage ancilla to 0, and leave on each garbage wire a function of x alone. Testing only y = 0 is not enough: a block that starts with a CNOT from target bit 0 to target bit 1 passes every y = 0 test but leaves garbage when it is used to clean up a computed S-box output; the full-pair test rejects it.
  2. The circuit is replayed symbolically. Every wire holds an XOR of named Boolean functions, called atoms: the constant 1, the original value of each key, plaintext and output wire, and one atom per output bit of each distinct S-box application. X adds the constant, CX adds one wire's expression to another. A CALL requires every ancilla it uses to hold 0, and XORs the eight output atoms of S (or S−1) applied to the eight input expressions into the targets; an application with the same kind and the same eight input expressions always gets the same atoms. A garbage block's garbage wires get fresh atoms named by the block and its input expressions. An UNCALL requires exactly those garbage atoms on the garbage wires (left by an earlier CALL with the same input expressions) and 0 on the other ancillas; it XORs the S-box outputs into the targets again and clears the garbage. One rewrite connects the two kinds: S−1 applied to exactly the eight output atoms of one S application, in order, gives back that application's input expressions, and S applied to the outputs of one S−1 application likewise. This is what in-place SubBytes needs (compute S(x) into a free byte, then clear x with S−1).
  3. The result is compared with FIPS 197. The verifier evaluates KeyExpansion and Cipher in the same algebra, with SubBytes and SubWord as S applications, and accepts if and only if every output wire holds its own atom ⊕ the ciphertext bit, every key and plaintext wire holds exactly its own atom and every workspace wire holds 0.

Equal expressions are equal Boolean functions, and X, CNOT and Toffoli gates permute basis states without phases, so an accepted circuit implements the map exactly, on superpositions too. The converse does not hold: the algebra does not know AES's algebraic identities, so some correct circuits are rejected. Any linear rewriting is fine (MixColumns, AddRoundKey, the key schedule and the routing of bytes can be done in any order and any CNOT network, in place or not), but the S-box must be computed by declared blocks whose input expressions match the reference's SubBytes inputs, and S-box outputs computed some other way, or garbage reused across different inputs, are not recognized. When the replay fails, the message names the first AES S-box input (round and byte, or key expansion word and byte) that the circuit never fed to an S block.

The verifier is standard-library Python. A second program, written separately from the specification (site/tests/aes_indep.py: NumPy byte arrays over all input pairs for the blocks, Python sets of atoms in the replay, its own FIPS 197 implementation and its own Toffoli-depth expansion), is compared with it on every baseline and on mutated files.

Scoring

Lexicographic, all minimized:

  1. Toffoli gates: the number of CCX gates in the fully expanded circuit, every CALL and UNCALL counted with its block's gates, key expansion and every clean-up included.
  2. Toffoli depth: every wire starts at level 0. Going through the expanded gates in order (an UNCALL's gates in reverse order), a gate takes the largest level among its wires, plus 1 if it is a Toffoli gate, and gives that level to all of its wires, controls included. The largest level at the end is the Toffoli depth. CNOT gates pass dependencies on without adding to them, and calls are not barriers. It is neither the T-depth nor the full circuit depth.
  3. Qubits: k + 256 + A, with A the declared workspace whether used or not.

Ties are ranked by submission number (lower first). The total number of expanded gates is shown but not ranked.

Baseline and reference scores

AES has 200, 224 and 276 S-box evaluations for AES-128, AES-192 and AES-256 (160, 192 and 224 in the rounds plus 40, 32 and 52 in the key expansion). The house constructions below were generated by site/tools/gen_aes.py; each file was accepted by the verifier and also run on concrete inputs (FIPS 197 known answers, nonzero targets), which gave the right ciphertext with clean workspace.

  • S-box circuits: the algebraic normal form (all 247 monomials of degree 2 or more, 247 Toffoli gates); Boyar and Peralta's 34-AND circuit of depth 16 (IFIP SEC 2012, ePrint 2011/332; the S-box of Jaques et al., Table 1); and their 32-AND circuit (SEA 2010, ePrint 2009/191). Each AND becomes a Toffoli gate on a fresh wire, its two inputs are built on fresh wires with CNOTs, and the outputs are XORed into the targets. A clean block then undoes everything (2 Toffoli gates per AND); a garbage block undoes only the CNOT parts and keeps the AND outputs as garbage (1 Toffoli gate per AND, the other one paid by its UNCALL). A direct block is a clean block that does not store the ANDs whose outputs feed only the output layer (18 of the 32): each is a Toffoli gate straight into one target bit, with CNOTs between target bits before and after it so that its product reaches every output bit it belongs to. Only the other 14 ANDs are computed and undone, so a direct block costs 2 × 14 + 18 = 46 Toffoli gates on 16 ancillas, against 64 on 96 for the clean block. The inverse S-box uses the same AND circuit with the inverse affine map folded into its input and output layers.
  • Wide: the key expansion runs in place on the key wires, AddRoundKey 0 in place on the plaintext wires, each round's SubBytes writes into a fresh 128-qubit register, MixColumns runs in place (a CNOT sequence from Gaussian elimination), the ciphertext is copied into Y with 128 CNOTs, and then everything before the copy is run backwards (CALL and UNCALL exchanged). This is the structure of the specification's baselines, and with garbage blocks each S-box evaluation costs one AND count forward and one backward. The baseline differs in the last round: its S-box outputs go straight into Y through direct blocks (46 Toffoli gates per byte, nothing to run backwards), followed by the last AddRoundKey on Y, so the last round needs no register and no copy.
  • Narrow: the plaintext wires and up to three 128-qubit registers hold states, the key expansion runs in place on the key wires, and all blocks are clean or direct. An early round moves the state: S into a free register, then S−1 clears the old one (2 calls per byte). The last rounds before the final one keep their input state (1 call per byte). The final round writes its S-box outputs straight into Y. Then the rounds are undone one by one and the key expansion is rewound, which restores P and K.
ConstructionAES-128 (Toffoli, depth, qubits)AES-192AES-256
Wide, ANF clean blocks (494 per evaluation, twice)197,600, 5,360, 6,604221,312, 6,432, 6,924272,688, 7,504, 7,244
Wide, 34-AND clean blocks27,200, 160, 3,70430,464, 192, 4,02437,536, 224, 4,344
Wide, 32-AND clean blocks25,600, 240, 3,58428,672, 288, 3,90435,328, 336, 4,224
Wide, 34-AND garbage blocks13,600, 80, 9,82415,232, 96, 10,96018,768, 112, 13,048
Wide, 32-AND garbage blocks12,800, 120, 9,34414,336, 144, 10,43217,664, 168, 12,416
Wide, 32-AND garbage blocks, last round direct into Y (baseline)12,512, 154, 8,70414,048, 178, 9,79217,376, 202, 11,776
Narrow, 32-AND, 1 register, 4 parallel ancilla sets40,960, 1,920, 89648,128, 2,256, 96058,880, 2,760, 1,024
Narrow, 32-AND, 2 registers, 2 ancilla sets38,912, 3,648, 83246,080, 4,320, 89656,832, 5,328, 960
Narrow, 34-AND, 3 registers, 1 ancilla set39,168, 4,608, 87046,784, 5,504, 93458,208, 6,848, 998
Narrow, 32-AND, 3 registers, 1 ancilla set36,864, 6,912, 86444,032, 8,256, 92854,784, 10,272, 992
Narrow, 32-AND direct blocks, 3 registers, 1 ancilla set26,496, 26,496, 78431,648, 31,648, 84839,376, 39,376, 912
Narrow, 32-AND direct blocks, 3 registers, 8 ancilla sets (baseline)26,496, 3,673, 89631,648, 4,240, 96039,376, 5,408, 1,024

The ANF and 34-AND clean-block rows reproduce the specification's construction-derived counts (197,600 / 221,312 / 272,688 and 27,200 / 30,464 / 37,536), and the garbage-block rows the review's (13,600 and 12,800 for AES-128). In the wide instances the baseline pays 2 × 32 Toffoli gates per S-box evaluation and 46 in the last round, 288 fewer than garbage blocks throughout; further gains must come from an S-box circuit with fewer AND gates, from evaluations shared or saved, or, at an equal count, from a lower Toffoli depth (the 34-AND circuit has AND depth 4 against 6, hence depth 80 against 120 at 800 more Toffoli gates). In the narrow instances the cap forbids keeping garbage for long, and the baseline pays for S−1 clean-ups and for running the rounds backwards: 576, 688 and 856 block calls. With one ancilla set every Toffoli gate of the direct blocks lies on one path (depth = count); eight sets fill the cap exactly and cut the depth to 3,673 for AES-128. How far better S-box circuits, schedules and in-place designs can go below the baseline is open.

Published figures use other interfaces or gate sets, so no instance shows a numeric reference score:

  • Grassl, Langenberg, Roetteler and Steinwandt, Applying Grover's algorithm to AES: quantum resource estimates, PQCrypto 2016, pp. 29–43 (arXiv:1512.04965), Tables 2–4: 1,060,864 / 1,204,224 / 1,505,280 T gates and 984 / 1,112 / 1,336 qubits for AES-128 / 192 / 256, for the map |K⟩|0⟩ → |K⟩|AESK(m)⟩ with a classical plaintext m. With their 7-T Toffoli gates this is 151,552 / 172,032 / 215,040 Toffoli gates.
  • Jaques, Naehrig, Roetteler and Virdia, Implementing Grover oracles for quantum key search on AES and LowMC, EUROCRYPT 2020, pp. 280–310 (arXiv:1910.01700, v1), Table 3, in-place MixColumns: 54,400 / 60,928 / 75,072 T gates with 13,600 / 15,232 / 18,768 measurements, width 1,785 / 2,105 / 2,425. Each AND of the 34-AND S-box costs 4 T gates and is undone by a measurement, which this board does not allow; done coherently, the same evaluation schedule needs 2 Toffoli gates per AND (the 34-AND clean-block row). The authors' Q# code is at github.com/microsoft/grover-blocks, whose README warns that the Q# resource estimator may report depth and width lower bounds that cannot be met at the same time.
  • Langenberg, Pham and Steinwandt, Reducing the cost of implementing AES as a quantum circuit (ePrint 2019/854), report more than 88 % fewer Toffoli gates than Grassl et al. for AES-128 (abstract), using Boyar and Peralta's 2010 S-box circuit (Jaques et al., Table 1).
  • Later work optimizes width or depth: Zou, Wei, Sun, Liu and Wu (ASIACRYPT 2020, Quantum circuit implementations of AES with fewer qubits), Huang and Sun (ASIACRYPT 2022, ePrint 2022/620; the abstract reports a width of 371 qubits where Zou et al. used 512, and 270 at a greater depth), Liu, Preneel, Zhao and Wang (ASIACRYPT 2023, ePrint 2023/1417, depth and qubits) and Jang, Baksi, Kim, Song, Seo and Chattopadhyay (IACR Communications in Cryptology 2(1), 2025, Quantum Analysis of AES). Their circuits differ from this board's interface (classical plaintext, measurement-based uncomputation or a different cost model) and have not been converted; a converted file is scored like any other.

Application

The cost of a quantum AES oracle sets the price of Grover key search, and NIST's post-quantum security categories are defined by the resources needed to attack AES-128, AES-192 and AES-256. Published estimates differ in interface, gate set, clean-up and the way width and depth are counted, which makes them hard to compare. Here every circuit is checked for the same complete map, including key expansion and clean-up, and scored the same way: the wide instances ask how few Toffoli gates a clean oracle needs, the narrow ones how few it needs on a small workspace.

Where verification runs

Verifications of this board run on the first lane of this list that is up and has room: the Mac mini, then CU Boulder's Alpine, then NCAR Derecho, then RunPod. A lane that is down, full or slow passes the file to the next one automatically, with the same verifier version; the limits of one verification are 300 s of CPU, 570 s of wall time and 2,048 MB of memory on the Mac mini, and 600 s of CPU, 1,020 s of wall time and 2,048 MB of memory on CU Boulder's Alpine, NCAR Derecho and RunPod (2 times the board's own CPU and wall time on the other lanes, because their processors are slower); the result goes to QArena only.

Current records

InstanceBaselineRecord (Toffoli gates) Reference scoreRecord holderStatus
AES-128, wide workspace Hot
128-bit key, 10 rounds, 200 S-box evaluations; workspace up to 16,000 qubits (16,384 in total); checked exactly
12,440
QArena's run
12,440–
No published count for this map (quantum key, plaintext and target, full clean-up). Grassl et al. report 1,060,864 T gates (151,552 Toffoli at 7 T each) and 984 qubits for |K>|0> -> |K>|AES_K(m)> with a classical plaintext m (Table 2), Grassl, Langenberg, Roetteler, Steinwandt, PQCrypto 2016, Table 2
qarena-baseline (QArena's run)(QArena)Baseline not beaten
AES-128, at most 512 workspace qubits
128-bit key, 10 rounds; workspace at most 512 qubits (896 in total); checked exactly
26,496
QArena's run
26,496–
No published count for this map. Jaques et al. report 54,400 T gates with 13,600 measurement-based AND uncomputations (not allowed here) and width 1,785 for AES-128 with in-place MixColumns, more than this cell's 896 qubits. Designs aimed at few qubits start with Zou et al., ASIACRYPT 2020 (doi:10.1007/978-3-030-64834-3_24), Jaques, Naehrig, Roetteler, Virdia, EUROCRYPT 2020 (arXiv v1, Table 3)
qarena-baseline (QArena's run)(QArena)Baseline not beaten
AES-192, wide workspace
192-bit key, 12 rounds, 224 S-box evaluations; workspace up to 15,936 qubits (16,384 in total); checked exactly
13,976
QArena's run
13,976–
No published count for this map (quantum key, plaintext and target, full clean-up). Grassl et al. report 1,204,224 T gates (172,032 Toffoli at 7 T each) and 1,112 qubits for |K>|0> -> |K>|AES_K(m)> with a classical plaintext m (Table 3), Grassl, Langenberg, Roetteler, Steinwandt, PQCrypto 2016, Table 3
qarena-baseline (QArena's run)(QArena)Baseline not beaten
AES-192, at most 512 workspace qubits
192-bit key, 12 rounds; workspace at most 512 qubits (960 in total); checked exactly
31,648
QArena's run
31,648–
No published count for this map. Jaques et al. report 60,928 T gates with 15,232 measurement-based AND uncomputations (not allowed here) and width 2,105 for AES-192 with in-place MixColumns, more than this cell's 960 qubits. Designs aimed at few qubits start with Zou et al., ASIACRYPT 2020 (doi:10.1007/978-3-030-64834-3_24), Jaques, Naehrig, Roetteler, Virdia, EUROCRYPT 2020 (arXiv v1, Table 3)
qarena-baseline (QArena's run)(QArena)Baseline not beaten
AES-256, wide workspace
256-bit key, 14 rounds, 276 S-box evaluations; workspace up to 15,872 qubits (16,384 in total); checked exactly
17,304
QArena's run
17,304–
No published count for this map (quantum key, plaintext and target, full clean-up). Grassl et al. report 1,505,280 T gates (215,040 Toffoli at 7 T each) and 1,336 qubits for |K>|0> -> |K>|AES_K(m)> with a classical plaintext m (Table 4), Grassl, Langenberg, Roetteler, Steinwandt, PQCrypto 2016, Table 4
qarena-baseline (QArena's run)(QArena)Baseline not beaten
AES-256, at most 512 workspace qubits
256-bit key, 14 rounds; workspace at most 512 qubits (1,024 in total); checked exactly
39,376
QArena's run
39,376–
No published count for this map. Jaques et al. report 75,072 T gates with 18,768 measurement-based AND uncomputations (not allowed here) and width 2,425 for AES-256 with in-place MixColumns, more than this cell's 1,024 qubits. Designs aimed at few qubits start with Zou et al., ASIACRYPT 2020 (doi:10.1007/978-3-030-64834-3_24), Jaques, Naehrig, Roetteler, Virdia, EUROCRYPT 2020 (arXiv v1, Table 3)
qarena-baseline (QArena's run)(QArena)Baseline not beaten

The baseline of an instance is its published result where there is one (the hot instance's famous result, a cited published reference, or a published result or method on its leaderboard), else QArena's own run. Reference scores come from cited papers or derived constructions.

Record changes

No participant record yet

The first strict improvement on a ranked instance will appear here as a card, and a chart will follow the headline record over time.

Headline record now:

How to submit