Grading
How X Layer decides that a chip passes, which tests it runs, and what a sample can miss.
Where the tests live
Every lesson's tests are a table stored in the LessonBook contract. A row is the input bits and the output bits a right chip must give. A lesson without memory has one row per test. A lesson with memory has runs: each run is a list of beats, played in order from a cleared memory.
The lesson page reads the same table and runs your design against it in the browser before you tape out. The answers are not secret, and they do not need to be: a chip has to compute them.
Lessons graded inside the tape-out
Lessons 1 to 7 and 9 to 11 are small enough to test on every stored row. The Grader does it inside the transaction that makes the chip. If the chip is wrong on any row it fails, and you know at once.
Lessons graded on a sample
The 4-bit adder, the three memory lessons, the ALU and the computer store more tests than one transaction should run. For these the Grader checks:
- chosen runs, always the same, picked to catch the usual mistakes, and
- drawn runs, picked by the hash of the block after the chip was made.
The maker cannot know the drawn runs when they tape out, because that block does not exist yet. Anyone can work out afterwards which runs a chip was checked on:
seed = keccak256(abi.encode(blockhash(seedBlock), circuitId))
test k = run k for k below fixedTests
test k = run fixedTests + uint256(keccak256(abi.encode(seed, k))) % (runs - fixedTests) otherwiseseedBlock is the block after the tape-out. Grading is a second call, grade(circuitId), which
anyone may send; the lesson page sends it for you. It must happen within 8,191 blocks of the
tape-out, while X Layer still remembers that block's hash. After that the chip expires and has to be
made again.
What a sample can miss
A sample is not a proof, and these docs will not pretend it is.
The 4-bit adder and the ALU check 8 chosen cases and 16 drawn ones. A chip that is right on the chosen cases and wrong on a share p of the rest passes with chance (1 - p) to the power 16:
| Share of inputs the chip gets wrong | Chance it still passes |
|---|---|
| 1 in 4 | about 1 percent |
| 1 in 10 | about 18 percent |
| a single input | about 97 percent |
So the sample catches a broken chip and can miss a chip with one rare fault. A test in the repository builds an adder that is wrong on one input in eight and checks, over 40 block hashes, that it fails exactly when a drawn run lands on a wrong input.
The memory bit, the register and the counter each store 32 runs whose answers all differ, so a chip that ignores its inputs and plays back a recording matches at most one of them. One or two hand-made runs are always checked, and two more are drawn. Thirty-six deliberately broken memory chips, each with one named fault, were run against the stored tests; every one fails a run that is always checked.
The computer runs two chosen programs and one drawn from 30. The chosen two exercise every instruction. A computer that is right on both and wrong on one of the 30 random programs passes 29 times in 30. It is a strong check of each instruction and a weak check of rare combinations.
Gas
A chip is given a fixed amount of gas for each beat, the same whoever sends the call: 4,000 per gate the lesson allows, plus 90,000 per reused chip it allows, plus an amount for memory, plus 100,000. Every lesson's allowance is at least one and a half times what the most expensive chip its limits permit was measured to need. A chip that outruns its allowance fails. A grading call that cannot hand the full allowance over stops without writing a result, so nobody can fail someone else's chip by sending too little gas.
Measured on a fork of X Layer, with the reference chips going through the real Fab and Grader:
| Lesson | Gas to tape out | Gas to grade |
|---|---|---|
| NOT gate | 1,000,062 | inside the tape-out |
| Full adder | 1,088,312 | inside the tape-out |
| Instruction decoder | 1,402,109 | inside the tape-out |
| 4-bit adder | 709,093 | 6,274,746 |
| 4-bit counter | 700,637 | 9,645,562 |
| ALU | 796,725 | 10,338,922 |
| Sillu-4 computer | 874,408 | 35,245,516 |
The whole course is about 89 million gas. Making the 16 reference chips on X Layer mainnet cost under 0.002 OKB in gas.
Records
For each lesson the Grader keeps the smallest passing chip that is the first of its design. Between two chips with the same number of gates, the record goes to the one submitted first.