Putting the tamper and the price together
A rewrite has two quantities in it and they are usually mixed up. One is how many blocks have to be redone, which is set by where in the register the edit sits and is not random at all. The other is what one block costs to redo, which is set by the difficulty and is random every single time. Tonight the first is counted, the second is drawn live, and the two are kept apart on purpose.
★ What you walk out with tonight. The count: an edit at block 2 of a six block register forces four blocks to be re-mined. The shape of the price: four independent draws, so the total swings far harder than the per block mean suggests. And the reason depth matters, which is the argument underneath every confirmation count you have ever seen quoted.
Self-studyThe words that will keep coming back4 min▶
- Reforge. Re-mine a block and every block after it, so the register becomes internally consistent again.
CHAIN.reforge(chain, index, difficulty). - attempts. The field
reforgereturns alongside the rebuilt chain. It is the total across every block it re-mined, not a per block figure. - Draw. One block's search for a qualifying nonce. Independent of the last one, with no memory and no progress.
- Depth. How many blocks sit on top of the entry you want to change. The count of blocks to redo is exactly that number plus the block itself.
- Confirmation. One block added on top of the block holding your entry. Counting them is counting depth.
- Finality. The point at which a rewrite stops being worth worrying about. A probability that strengthens, not a line that is crossed.
- Mean. An average over many independent blocks, quoted with its trial count. A single run is not one.
- Spread. How far individual runs sit from the mean. At difficulty 3 the measured range ran from 40 attempts to 17,343.
Four blocks, and the count is not the random part
12 min liveEdit block 2 and block 2's own hash changes. Block 3 records the old one, so block 3 has to be rebuilt, which changes block 3's hash, so block 4 has to be rebuilt, and so on to the end. Blocks 0 and 1 are untouched because nothing above them moved. The register has six blocks, the edit is at index 2, and that makes the count 4.
...
LivePress it again, and again4 min▶
The first total means almost nothing on its own. Press the same button a second time at the same difficulty and watch the total land somewhere else entirely, sometimes by a factor of several. Same register, same edit, same difficulty, same four blocks. Four fresh draws.
That is the correct mental model of a rewrite cost, and it is why a single measured figure is not a number you should quote to anybody. It is one sample of a quantity with an enormous tail.
LiveWhere the randomness in the box comes from3 min▶
Worth being exact about, because it is easy to mistake for a trick. The nonce search itself is not random: it starts at zero and counts upward, so searching the identical bytes twice finds the identical nonce after the identical number of attempts. Re-running a fixed model gives a fixed answer, which is the same reproducibility that lets session 2 print hashes in a diagram.
What varies between runs is the block being searched. An attacker forging blocks 2 to 5 writes their own timestamps into them, and the box does exactly that, stamping a different second on each forged block each time you press it. Different bytes, different search, an independent draw per block. That is what a real block does anyway, since no two blocks ever carry the same contents.
LiveWhat reforge actually does, step by step3 min▶
Starting at the index you give it, reforge copies the chain, then walks forward. For each block it sets prev to the hash the block below it now has, searches for a nonce that satisfies the difficulty, stores the new nonce and the new hash, and adds that block's attempts to a running total. When it reaches the end it hands back the rebuilt chain and one number.
Note the order. Block 3 cannot be mined until block 2 is finished, because block 3's prev is an input to block 3's hash. The four draws are independent in their outcomes and strictly sequential in their execution, and that distinction does real work in session 8.
Self-studyWhy the rebuilt register verifies cleanly3 min▶
Run CHAIN.verify() on the reforged chain and it returns ok. Every hash recomputes, every link matches, and the entry at block 2 now says whatever the attacker wanted it to say. Nothing inside the register objects.
This is the uncomfortable half of proof of work and it is worth being blunt about it. Work does not make a rewrite detectable. Session 3 already made it detectable, with no work at all. Work makes a rewrite expensive, and expensive is a completely different property from visible. A reader holding only the rewritten register sees a perfect chain.
Four draws, not four times the mean
12 min liveSession 4 measured what one block costs at each difficulty, as a mean across many independent blocks, with the trial count beside it. Those are the figures below and they are per block. They are also the only cost figures on this page, because the total for four blocks is not a figure at all: it is whatever your four draws happen to come to, and the live box above is where you get yours.
LiveWhy four draws are wilder than one, and tamer at the same time4 min▶
Both things are true and they sound contradictory. In absolute terms four draws swing further than one, because one unlucky block is enough to blow the total out on its own and there are now four chances of that happening. In relative terms four draws are steadier than one, because a very short draw and a very long draw can land in the same total and partly cancel.
So a four block rewrite is a little more predictable as a proportion of itself and a lot less predictable as a raw count. Neither of those makes any single run a cost estimate. Run the box several times at difficulty 2 and write the totals down before you believe anything about them.
LiveEach extra zero is a step change, not a step3 min▶
Read the mean column downward: 16, then 277, then 4,115, then 74,190. Each row is roughly sixteen times the one above it, because one more required leading zero divides the qualifying hashes by sixteen. The difficulty dial is not a slider with linear notches, it is an exponent.
That is what makes difficulty a usable defence at all. A modest increase in what one block costs honest writers is a huge increase in what four blocks cost an attacker, and both sides feel it, which is the trade the next card is about.
Self-studyWhere the disagreement really is4 min▶
One camp holds that this cost is the security. The register is safe to the extent that redoing it is expensive, the expense is measurable, and a threat model can be written with the measurement in it. On that reading, work is the thing that turns a detectable edit into an edit nobody will attempt, and everything else is commentary.
The other camp holds that cost is the wrong unit entirely. Honest writers pay the cost continuously, for as long as the register is in use; an attacker pays it once, for the short window they care about. A quantity that one side pays forever and the other side pays once is not a fair comparison, and calling it security smuggles in an assumption about the attacker's budget that nobody has checked.
Both camps agree completely about the arithmetic on this page and disagree about what the arithmetic licenses you to claim. It is worth knowing which one you are talking to before agreeing that a chain is secure, because they mean different things by the word.
The deeper it is buried, the dearer it is to move
7 min liveThe count of blocks to redo is the depth of the entry plus one. Change the last block and you redo one. Change block 2 of six and you redo four. Change block 0 and you redo all six. Nothing about the entry matters, only how much has been written on top of it since.
LiveA confirmation is just another block on top4 min▶
When a register is described as waiting for six confirmations before an entry is acted on, that is this arithmetic being used as a policy. Six confirmations means six blocks have been written on top, so a rewrite now has seven draws to win instead of one, and each of those draws is the full price at the current difficulty.
The choice of six is not a property of the mathematics. It is somebody deciding how much residual risk they will carry, on what they are willing to lose, and reasonable people pick different numbers for different consignments. Treat any confirmation count you are quoted as a risk appetite, not a fact.
LiveWhy it is a probability and never a certainty3 min▶
A draw with an enormous tail can always come in short. Difficulty 3 has a mean of 4,115 attempts and it has produced a block in 40. There is no depth at which the chance of a lucky sequence becomes zero, only depths at which it becomes small enough that nobody reasonable would plan around it.
So the honest sentence is that an entry gets harder to move every time a block lands on it, without limit and without ever arriving anywhere. If somebody tells you a record on a chain is final, the useful question is what depth they mean and what they are willing to lose if they are unlucky.
Self-studyDepth does nothing for a register nobody is extending3 min▶
Everything in this part assumes blocks keep arriving. Depth is accumulated by other people writing, and an entry in a register that has been quiet for a year is exactly as deep as it was a year ago. The protection did not grow; it stopped growing the moment the writing stopped.
Worth checking against whatever you are being sold. A private register with one writer and a handful of entries a month accumulates depth very slowly, so the cost argument that makes this structure interesting is doing almost no work there. The tamper evidence from session 3 still holds, and it holds at difficulty 0 for free.
What this prices, and what it says nothing about
5 min liveEverything measured tonight is one machine, working alone, redoing four blocks in sequence. That is a real and useful quantity. It is also not the threat most people mean when they ask whether a chain can be rewritten, and pretending otherwise is the commonest overclaim in the subject.
Price it yourself
14 min hands onConsole open on this page. Build the register at a difficulty, tamper it, reforge it, and read the total. Then do the whole thing again and compare.
Check the hash before you price anything
Run CHAIN.selfTest().ok. If the published test vectors do not pass in your browser, every attempt count you are about to read is meaningless, and that is worth four seconds.
Count the blocks before you mine them
Print r.chain.length - 2 and confirm it is 4. Then say why it is 4 without using the word hash, using only the words register, position and end.
Prove to yourself that the search is not random
Run CHAIN.reforge(bent, 2, 2).attempts twice, with no restamp. Identical both times, because the same bytes get the same search. Reproducibility is a property of the model, exactly as in session 2, and it is why the restamp is there.
Read a total, then throw it away
Now run CHAIN.reforge(restamp(bent), 2, 2).attempts twice. Different blocks, different searches, two independent totals. Write both down. Anyone quoting one of them as the cost of a rewrite has shown you they did not run it twice.
Do it five times at difficulty 2
Loop the restamped reforge five times and collect the totals. Look at the lowest and the highest. Compare that gap with the per block figures in the table above, where difficulty 2 has a mean of 277 attempts over 300 trials and a single block ranged from 1 to 2,147.
Move the target and watch the count move
Reforge from index 4 instead of 2. Confirm the rebuilt chain still verifies and that only two blocks were touched. Then reforge from index 0 and confirm all six were. The count is the only part of tonight you can predict.
Raise the difficulty one notch and feel the exponent
Rebuild at difficulty 3 and reforge again. It will take noticeably longer, and the mean per block moves from 277 to 4,115. Say out loud what a fifth zero would do to the same four blocks, given the pattern in the mean column.
The habit to keep. When somebody quotes you the cost of rewriting a register, ask two questions in this order. How many blocks, which is arithmetic they should be able to answer exactly. And how many runs is that figure averaged over, which is where most quoted costs quietly fall apart.
Three questions
An attacker edits block 2 of the six block Harbourgate register. How many blocks must be re-mined, and is that number random?
An edit propagates upward through the prev field and never downward, so blocks 0 and 1 are untouched. Blocks 2, 3, 4 and 5 all have to be produced again, which is 4. That count comes from the position of the edit and the length of the register, and it is the one quantity tonight that is not a lottery.
At difficulty 3 one block has a mean of 4,115 attempts over 120 trials. What can you say about the cost of a four block rewrite at that difficulty?
A single block at difficulty 3 was measured at 40 attempts at one extreme and 17,343 at the other, a factor of more than 400 around the mean. Drawing that four times gives a total nobody can hand you in advance. The per block mean with its trial count is a real figure; a rewrite total from one run is a sample, and should be labelled as one.
Why are confirmations counted at all, and what does a high count actually give you?
Depth is the count of blocks on top, and the count of blocks to redo is that depth plus one. Nothing re-checks the entry and nothing locks. A draw with a long tail can always come in short, so waiting buys a probability that keeps strengthening and never arrives at a guarantee. Any specific confirmation count is a risk appetite somebody chose.
Homework
Twenty five minutes, turning tonight's arithmetic into a sentence you would sign.
Run the restamped reforge ten times and keep the list
Difficulty 2, index 2, ten totals. Write down the lowest and the highest you saw. Bring the gap to session 6, because it is the cleanest evidence you will get that a single measurement of anything in this subject is not a measurement.
Find the depth in a register you rely on
Take a log or audit trail from your own work and ask how much gets written after a given row before anybody acts on it. That is your depth. Then ask what it costs anybody to rewrite from there today, and whether the honest answer is nothing at all.
What this session covers
Cheat sheet
CHAIN.reforge(chain, 2, d) returns the rebuilt chain and one total attempts.