Writing With a Machine · Solidity, and the Tool That Writes It · Week 12 · Checkpoint 26
What You Want Saying
Two drafts of the same contract, from two different requests. One of them settles the interface, the units, the refusals, the absences and the assumptions. The other decides all five for you and mentions none of them.
14 steps~26 min3 nodes for your map
01 · The half of the loop that is yours
Four acts of reading, and here is what they were for. From here on a machine writes the first draft and you read it, which makes the reading the fast part and the asking the part nobody ever taught you. This checkpoint is the asking.
This board is the real thing: OpenZeppelin's `IERC20`, pinned at a commit, the same file you read in week four. Two of the boards ahead are not real code. They have no upstream, they were written for this lesson, and you will be told before each one.
02 · One sentence, and what came back
This board is not deployed code and belongs to no repository. It was written for this lesson as the answer to one sentence: write me a contract where people can deposit tokens. Thirty five lines came back, and they compile, and nothing in them is wrong.
Read it the way you read the last four acts. An interface, a state block, a constructor, three functions. It answers a question that was never asked, and the four boards after this one are about which questions those were.
03 · An interface it wrote for itself
The sentence said tokens and named no standard, so lines 4 to 7 are the file deciding for itself what a token is. Two declarations, written from recollection, under a name of its own choosing, with nothing on the board saying where the shape came from.
Now hold line 5 against line 41 of the real board. `IERC20` declares `transfer` as returning a `bool`, and this one declares it returning nothing at all. Both compile and both call the same token. The file chose, because the sentence did not.
04 · A mapping two keys deep
Line 13 is the whole of the accounting, and it carries two keys rather than one. Line 24 takes a token address as its first argument, line 27 writes under both keys, and line 30 asks for a token back again. Read those four lines together.
The sentence that produced this file said tokens and said nothing whatever about how many. Line 13 is an answer to a question nobody put. Say what that answer is before you scroll.
Lines 13, 24 and 30 all carry a token address. Reading only this file, what has it settled about how many tokens the contract holds?
05 · Two variables nobody asked for
Line 10 stores an owner and line 11 stores a flag. Line 19 is a function only that owner can reach, line 20 is what keeps everybody else out of it, and line 25 makes every deposit in the file depend on the flag. Six lines, and a whole capability.
Now go back to the sentence: people can deposit tokens. It asks for no owner and no switch, and the file has both, because a request that says nothing about privilege leaves the shape to be picked from everything the model has read. It picks the common one.
06 · Withdrawing, all or nothing
Line 30 takes a token and takes nothing else. Line 31 reads the caller's whole entry into a local, line 32 writes zero over that entry, and line 33 sends the lot. There is no amount named anywhere in the four lines and no refusal in them either.
That is a real decision about how the thing behaves, taken in the shape of a parameter that is not there. Decide what it means for somebody holding a balance here before you read another board.
07 · The strongest thing you can point at
Back to the real board for one step. The strongest single move available when you ask for code is to point at a file: name `IERC20`, name the commit it sits at, and line 41 and line 78 stop being a matter of recollection. A draft either matches them or it does not.
Match this file at this commit is checkable. Make it standard is not. One of them names a text that exists and can be opened by anybody. The other names a feeling about a text, and a great many files feel standard.
08 · The same task, asked properly
This board is not deployed code either and has no upstream. It was written for this lesson as the answer to a second request for the same thing: a vault holding one token for depositors that lets them take it back, announcing each deposit and each withdrawal.
Underneath that came five lines, naming the interface to match, the units and their type, what must revert and with what, what must not be in the file, and what the code may assume. The same shape as the first draft, with every guess settled.
09 · One token, and a file to match
Line 4 imports `IERC20` by name rather than writing a copy of it, so `transfer` and `transferFrom` here carry exactly the signatures the real board declares on lines 41 and 78. Line 12 holds one token and is `immutable`, and lines 17 and 18 are the only place it is ever written.
Neither line is cleverness. Both came out of one sentence of the request: match that interface at that commit, one token, fixed at construction. The first draft had to guess at both, and it guessed differently at both.
10 · The same operation, first draft
Here is withdrawal in the first draft one last time. One argument, and it is the token. The whole entry read on line 31, written to zero on line 32, sent on line 33. Four lines, no amount, no refusal, and nothing announced to anybody watching.
Keep those four lines in your head for exactly one board. The next one is the same operation in the second draft, and what separates them is not style and not length.
11 · The same operation, second draft
Line 28 takes an amount. Line 29 reads what the caller has, line 30 refuses anything larger and carries both numbers out with the refusal, line 31 writes the remainder back where the other draft wrote zero, and lines 32 and 33 send and announce.
Nothing here is more sophisticated than the first draft. It is the same operation with the guesses taken out of it. Name what changed, and name the line of the request that changed it.
12 · Five things worth naming every time
Five lines of this draft exist because five lines of the request named something. They are not the same five ideas, and no one of them substitutes for another, so a request that names four and skips one gets a file that decides the fifth quietly.
Tap each of the five lit lines and read which of the five it answers. Then look at the first draft again and notice that all five were still decided there, just not by anybody who was asked.
13 · What a good request buys
The whole second draft, lit. It matches an interface that exists at a commit anybody can open, holds one token in units the request fixed, refuses by name, carries no owner and no switch, and writes its one assumption onto line 22 where a reader will meet it.
That is what naming five things bought. Be exact about what it did not buy before you leave the board, because two more checkpoints follow this one and they exist for a reason.
14 · Said, rather than left open
Not a better model and not a longer prompt. Five things named that the first request left for something else to settle: the interface, the units, the refusals, the absences, and what the code may take for granted. Each one was decided either way.
Point at a file whenever you can. A commit and a line number are checkable in a way a word like standard never is. The next checkpoint takes what came back and turns four acts of reading onto it.
BANK_DBowner: the bank
you2,400
what the app is actually showing you
BANK_DBowner: the bank ✍
you2,400their pen
you hold a claim. they hold the pen.
your digital life
BANK · you2,400the bank ✍
INSTAGRAM · you2.1M followersMeta ✍
STEAM · you134 gamesValve ✍
AIRLINE · you58,200 milesthe airline ✍
four tables. zero pens that are yours.
BANK_DBowner: the bank ✍
you2,400
DENIED ✗
try both pens
PLATFORM_DBowner: the platform ✍
her · 8 years2,000,000 followers
one automated decision away
your row stands on all three
FTX_DBowner: FTX ✍
you5 BTC
the row stayed. the backing did not.
CARD_DBowner: your bank ✍
TV you never bought−1,100
fraud reversal+1,100 ✓
someone holds the pen, so someone can fix it
?_DBowner: nobody
youstill yours?
can a table exist that nobody owns?
?_DBowner: ̶n̶o̶b̶o̶d̶y̶
you100
no owner, no pen, no trust?
keeper 1
you100
keeper 2
you100
keeper 3
you100
keeper 4
you100
keeper 5
you100
no THE copy, only copies.
keeper 2
you100
keeper 3
you100
keeper 4
you100
keeper 5
you100
your copy
you100
five copies. one of them is yours.
one attacker, ten thousand faces.
writing costs watts. faking voters buys nothing.
proof of work, burn energy to vote.
rewrite one line, break every lock after it.
the price buys trustlessness. the office already has trust.
ownerless ledger
you?
nobody owns the table. so who owns your row?
Three new nodes on your map
requests as specifications · pointing at a file · silent defaults · +10 Lynx