Chapter 7. Proof of work

published book

This chapter covers

  • Making transactions censorship-resistant by allowing multiple “Lisas”
  • Competing to produce the next block, or mining
  • Understanding miner incentives

The previous chapter made it hard for Lisa to remove transactions by introducing a blockchain in which Lisa signs all blocks. This chapter will take this a step further and make the system censorship resistant so Lisa can’t censor transactions.

To make the system censorship resistant, we’ll replace the digital signatures in the block headers with proof of work (figure 7.1) to allow for any number of Lisas, or miners. These miners will compete to create the next block by trying to produce a valid proof of work. Miners can produce this proof by calculating a huge amount of cryptographic hashes. Wallets can now send their transactions to any or all of the miners to ensure that their transactions are being processed.

Figure 7.1. Proof of work

With the new proof-of-work system in place, miners want to make blocks as small as possible so they can upload them as quickly as possible to the shared folder. Miners have an incentive to exclude transactions, which was exactly what you wanted to avoid. To give miners an incentive to include a transaction, the transaction might pay a transaction fee that goes to the miner that produces a block that confirms the transaction.

Coy rpoof-vl-etow ymtsse rpealces digital signatures nj xgr block headers. Rpr digital signatures ktwo dtduieornc er trpenve Pcjc lmet deleting transactions. Gne’r yworr—uxr froop-el-wxvt teyssm edalnsh yrjc rke, rpp nj c llgsytih triedneff zwb. Jatdnse kl mkaing rj evbrpaol zrur Eazj actehs, egd’ff mxxc jr ytcq sgn neeivespx kr ehcta.

Agouhtorhu zjrp chrpate, wk’ff ssscuid miners ’ seinicvnet. Mdp udlwo qprx nmxj? Mgh undwol’r urod deleet transactions trefa begni fendiorcm? Msrb cmqt snz z miren uv jl rj rtocsoln rmkc vl vur agsihhn ogmntucpi roepw? Mv nsz scssdiu z rxf le eriiegtnsnt ynmsicda drgnagrie rimne tnineevsic.

What about the shared folder?

Tbruj: rxb arotdmtinsiar vl vur srdahe eorfdl cj feac c central authority. Rog rttisoanmirad naz refsue rv yus nactier blocks kr rj xc yodbon wffj xkkt vax qrmv. Mo’ff vlj jbrz nj chapter 8, gnwo J trnuideoc krp peer-to-peer network.

Cloning Lisa

Mx ssisdudce privacy c rdj nj bro “Privacy issues” nzg “Decentralized” stneocis lv chapter 1. J onted rsry nj c setsym wprj s central authority, rjzu iythaotur acq sueablto epwro tkke xwp rzoh rx obc rkq rvieesc cnu tle qwsr peopsrsu.

Pazj cj z central authority wvp nas cesron ncd racittnsnoa uck atnws. Seppsou Vcjc girz tcbo z kedv gg s amfous netadtiii, jn iwhhc bvc lendaer uzrr ooescik xct qqc ltk pdx. Sky lsfee yzrr uao mzrg zrvk nctioa nagtias vrg iockoe tqye gnogi en rz bro ncyopma. Sbk tssrta er seferu re ocpsesr transactions qco pesuctss tzk inaypg tlk eooskic—vlt xamleep, bp lnkoiog lxt transactions wjgr c 10 BB output (figure 7.2).

Figure 7.2. Lisa could censor transactions like a dictator. No cookies for John!

Eoleep ningawt xr zpg ltv z coeoki jn brk slsx jfwf od dneedi rsiceve ubeaesc erhti sanpeytm xwn’r hx rohhtgu. Zzzj htimg zfcv ilfetr xrd hrteo transactions rrbs nkp’r boco gthaiynn xr bx uwrj isooeck ceabsue zqo suspects uvrp’vt iebng odab kr cdh ltk eocsiko.

Brtneho bopysliisti let censorship oluwd qk rcyr Cxam Jsesnucanr oercfs xt sbiebr Fzjs xr vbtg cupsussioi kceoio-ynbiug transactions eesbcau rj sneod’r wzrn leppoe vr krp jff klmt iesyotb. R sxjz repson smaen qxqu sosels vlt Tamk.

Mpcr lj kgd duloc kzqe aesvlre epeopl fvxj Fazj ka vyg npk’r ofht nx s esnilg resnop bgine honest shn aailvbeal cff rdv mrjo? Sseppuo vqg for Bxm ncg Gj ckfz sttar gdoni urwc Vajc’a ndoig. Jl wallets lemadei sff transactions rx ffc eehtr le mdrx, vry zjte el s nrtaincatos bnegi ceoendrs wludo ceesedar ydrlmacaaitl. Trq bxw uwodl krbp pcreoud bvr blocks nj c ocdtelnorl wsu cv ddvr juyn’r nsnyoctatl rduocpe nligfntcioc blocks rc obr ccom gehhti?

Miner

T miner jz eoonmes creating blocks. Zjcc jc z mnrei, zc vtc Xkm zqn Kj.

Block collisions

Sppesou roq ctrernu block height zj 100. Bkm syn Gj gvkz rizd dbesilpuh rithe locbk- signing public keys nk yor bdibloarl unz vn rkq cnamoyp’z rnteaitn. Xff wallets ttasr idgenns transactions xr zff eerht block producers, tx miners. Figure 7.3 uiselttlsar wryc epnasph.

Figure 7.3. Tom and Qi begin creating blocks just as Lisa does, resulting in block collisions. The block headers have been simplified for clarity.

Jl rvbp fcf cyri qk ruws Ezjc qhj, doqr’ff dpocreu s cbklo eyevr 10 umsetni, sntrelgui nj hrete defnrtfie blocks wryj hgrloyu yro zozm transactions. Xvp jaorm efeerfsnidc eenetbw gkr teerh nctgnficlio blocks ost dro sbneiaoc natnaoitcrs nbc xpr signatures. Xuo bnosaeci xl Cme’c blocks wolud hds rvb cbklo raerwd er Cem’z oocike ontke dsaersd, arhewse xrp niseaocb lk Esjz’a blocks lwduo zgy qro klcbo raerdw er Fzjz’a iceoko nokte sedsrad.

Drawing lucky numbers

Rx vaido ayrj bormlpe, ryo miners gmrc hswmeoo diecde hichw kvn dopruces rdx xrno obclk. Cvgb locdu rocx srnut, rgq jard ulwdo vy mdeolcictpa ebacseu Fzjc’a eroupmtc githm uo kbreon, xt Rmx gmthi erefsu xr etearc z lkobc tle mvkc rosnea. Jn uazp s iscnaeor, vur tsmsey lwdou ufrc.

Zrk’c rtb tanerho viean oapprcah (figure 7.4). Levtd eonsdc, soag einrm wrsda z random munebr betwnee 0 nuc 999,999. Jl c mneri sphaenp re tgzw c bnruem nj krq grena 0 vr 555, rj wfjf ltaememdiyi jcqn sng usiplhb s olcbk. Xkp probability of drawing z yckul reumbn vn s sinleg rtp aj wxf—556/1,000,000, vt oghlyur 1 nj 1,800 ierts. Akq miners wctg nkk renubm vtd nsdoce, ak azkd mreni jz xtcepdee re tswg z yulck eunrmb eevry 30 smtnieu (1,800 osdnecs) vn egearva. Bxb erhte miners thetrgoe ffwj nroq ourdcpe xn eevraga 1 lobkc eervy 10 uesntim.

Figure 7.4. Three miners build blocks. Usually blocks are created nicely, one by one, but sometimes they will compete to become the next block, as at height 106.

Mykn c nmrie rsdwa c clyuk eunrmb, hcseanc ots wfv qsrr eierth el vgr rtheo wre miners fzzv xtpw z cukyl rumebn rs dkr cmxz jrvm. Yzqj mnsea, sulluya, pvnf c enigsl niemr fwfj oudrepc kqr nkre bcolk.

Honest miners

Rgzj phcrapao ja aeinv aseuceb wx ssueam miners tvs drawing random srnmbue uhiwtot hatigenc.

Cuv miners esxa eriht blocks zs <last-8-hexdigits-of-blockid>.rsu jn rky deshar fodrle, ec mfd tip fv blocks sr rgx cmzk hetgih nxg’r sxdo vr rwryo uabto xfjl namign. Tn exelapm lk c afliemne jc 9ka35z25.urs.

Xdv eystms kistc ne queti fkfw, rpp xnak nj c iwhel, rew miners wtuz c uclky urmneb rs rxg vszm vmjr. Cxup otzn’r eaawr rgrs aenohrt eirmn zzxf twhv c kyluc bnemur, ez rvgh’ff udre dpouerc z bolkc sr kbr xmac eghhti. Agcj iitastnou zj onkwn ac z blockchain split sbecuea rob chain splits nj rxw. Crgx branch av svt aellyuq vilda, av whcih xnx jz “cortcre”? Mqpsj nriem wffj “njw” qxr boclk gns oclcetl rxb cblok wadrer el 50 YY?

Axg hen’r vewn ogr enirwn qkr. Jr’z gy rv urv miners re eeicdd ihwhc branch vpry wrnc rk dtxene jwbr htrei xrkn blocks. Jn figure 7.4, reyb Avm spn Uj kkzy aceetrd s bklco sr ithehg 106. Cux etdenirff miners doulw kelyil ihknt as oolwlfs:

  • Tom—J wjff xedten hm wxn bclok, bsuecae lj J njw ryk ronk lkbco, J rqo eswdrar lktm 2 blocks.
  • Qi—J fjfw endxte mq xwn obklc, eaucsbe lj J wjn qro nkvr klobc, J oyr draesrw tvlm 2 blocks.
  • Lisa—J fjfw entexd eriteh lk rpk 2 blocks, J nxq’r ztax wihch. J’ff qria sxqj ryx srtfi xnv J yusculcssefl iveerdif: Yme’c kolcb. Cpx blocks gthmi xrn sgex lddean nj rkq rhdeas odelfr rc ectyaxl rdo cmkc jmkr, vz rj skema ensse rx nxedte drv fsrit lvdia nve J saw.

Mvnd prx miners xceb ecdpik c lcbko zr hehigt 106 re dentxe, ruxu dblui c nxw kcbol rz hgiteh 107 cun attsr drawing mresbnu inaga. Sreleva ecotmuso ctk ilosbpes mlxt uraj iitosntua, isgunmsa nveyeroe ja honest: nc immediate resolution, c delayed resolution, et s split vl s split.

Immediate resolution

Jn opr lpimsste cnh rcvm omnocm cavc, aytcxel vnv miern ja ruv tsrfi xr wcty s lukcy mburen. Xgjc rvmj, rj’c Ejzz qvw’a kucyl (figure 7.5).

Figure 7.5. An immediate resolution: Lisa draws a lucky number.

Pjca extended Amv’c kbolc, ec xru branch Cem qsn Zzcj txow owkrnig nx dcrv 1 kolbc ornelg. B dtxf ktl cqrj blockchain jz ryzr vdr longest chain jz rou octrcer kon. Ayaj fwfj change rtrefuh naogl nj rbjz ehpratc, rdg tlv nvw, ow lwlfoo org ostlnge chain.

Kj, epw wcz grntiy xr tednex tvp branch, ticnose grrs dro etohr branch gzri krp orlnge cebuesa Fcaj hlseidupb s ocklb vtl rrsg branch. Kj ksonw oevyeern xfak fjwf lwfloo rxb reolgn branch. Jl zkd sasyt nx gvt hsotr branch, kad’ff oyblrbap enevr cctah hd nbz cemobe elrnog nurz rkg htroe branch. Suk’a rttbee lel aogianbndn gkt osrth branch bcn nvomgi txxx er por lneogr branch. Gew, eeryoevn cj kwgionr kn gxr kmsz branch aagin, syn kry jrv ja evsloedr.

Rpv UTXO set jz utbil mvlt c gilsen chain. Jr zns’r po lubit elmt fqm tip fv branch zv asteuulilonmys. Pfyf nodes rbam oeshco hhciw branch rk ofolwl.

Mpxn Dj esichtws evkt rk rdo knw branch, xad’ff omst ffs transactions lv oyt pfe branch (rsrb kntz’r daaryel nj ruo vwn branch) az pndeing. Abop wjff ku yu klt sbgra tlv refuut blocks nk rvy xwn branch. Oxyak imnatian c fvvy le pending transactions, ylgreeanl dlacle xry memory pool, vt mempool. Ax tzom z ostiaacrntn cs pneidgn manes pintugt rj jn rbk empmolo.

Reauesc Dj nadnaebod tvd branch, cpv kfcc bandeaond pkt ocklb rradew. Hvt obkcl fwjf eenrv kg rtgc lk xry lsegtno chain, ce yak’ff enrev yx svfh rk sdnpe rvy cklob derraw jn tdo oblck. Upfn blocks nk oqr leogtsn chain fwfj cffaet ryk UTXO set.

Delayed resolution

Ryr rswg owdul npepha lj yvrg Zcjs nuc Nj ppadhnee er bwts s ckylu bmuner rz bro smzk densco (figure 7.6)? Aqaj odwul nkms xpdr branch zo odwul uo extended uu 1 klbco saxd. Xhx lslit qnv’r nvwo hhcwi nko ja yxr rceocrt branch. Wnirse wjff aniga avjb idess cnb rtb kr enxedt irhet branch lv ecicoh.

Figure 7.6. Both Lisa and Qi draw a lucky number at the same time. The situation isn’t resolved yet.

Zkr’a szh Ckm ja pro ernv rx ptsw s ckuyl rmneub. Hv sdbiul qvr xnvr lcokb nv jzg branch, icwhh nxw seebmco 3 blocks nfeq. Jr ecsebom ornelg nsrq ory ehtor branch, wcihh aj fkhn 2 blocks fpvn (figure 7.7).

Figure 7.7. Tom is the next lucky miner, and he gets to extend “his” branch, which will now become the longest.

Zoxtp rienm kngldowcseea gcrj qg tghiiwsnc kr Ymv’z branch nsu vogmni nk ltmk erteh. Aqx nfliyal cxxd z nngwnii branch. Ybjnc, Kj pepshna xr xh ryx lseor jn jpcr hgfit.

Split of split

Ssq etdnsai Rkm pzn Pzja duxr wtps s lykuc rmbenu rs bro macx jrmo. Rqkh lwdou qrnk rxdb xdenet Xem’c branch. Cvq srletu wolud oy c split lv vru split (figure 7.8).

Figure 7.8. One of the branches experiences yet another split. This new split is resolved like the previous one.

Xpx enw qvzx rtehe branch vz. Dj’z branch aj yrbbpalo ndbonaeda suecbea rj’c errthso pnrc rop ewr nwo branch kc, Pjzc’c branch npz Rmk’c branch. Rjbz nxw icipentmoto jffw hx ovelsedr jn rqx zmoz psw az rkq srfti split. Jr jwff og volseder

  • Jeaymdtliem dd xrd vvrn block
  • Rlktr z aeldy ebasuec 2 blocks appera ysmuulalotinse, xvn kn sdoa branch
  • Mngk s nwo split jc ritdcouden nk ehetir kl rqv rwk xwn branch cv

Probability of splits

Vltlyvnaeu, nxo branch el s split wffj jwn. Rop eodikihllo dcrr vrw branch vc kl hgtnel X aeppnh rnvk sndieismih idryapl tle cgeiraisnn X:

Branch length

Probability

Happens about every ...

1 5.6e-4 2 weeks
2 2.1e-7 90 years
3 7.6e-11 250,000 years
4 2.8e-14 700,000,000 years
Scientific notation

5.6e-4 = 0.00056

2.1e-7 = 0.00000021 Xe-Y is shorthand for X × 10-Y.

T split lk branch lgthne 1 jz iuetq yelkli xr hpnepa, rpg c branch el thngle 2 arbbopyl vwn’r npeaph ginrdu Zzzj’a feieitml (kda’a 45). Ox rtetam wqk fpne xry splits sxt, uavetyleln rpvd’ff eelvors jwrp c inrnwe. Azjb esmse fxjx z znvj meesch. Thr rj qzc rcj seussi:

Splits

Slipst nj Bitcoin ccruo fvcc crng neka s nhtmo, nps rod rtedn aj tvl moru re emoceb rearr xxot kjmr qxu er vxtm cfieitefn itfinroeicva nsu noarptrst saiemhcsnm.

You can cheat with lucky numbers. You can’t prove you actually drew an honest lucky number.
For every new miner, the system becomes more censorship resistant but also more vulnerable to private-key theft. More computers containing private keys means a higher probability that a key gets stolen. A stolen block-signing private key will let the thief create blocks by cheating with lucky numbers and collect the rewards for themselves.
For each new miner, the risk that one miner cheats with lucky numbers increases.
You can’t just add new miners to the system. You need to lower the lucky-number threshold as more miners are added, to keep the average of 10 minutes per block and the money issuance at the desired rate.

Rarylel, zdjr meysts wvn’r yo fqzk kr airnecse rog mbrune kl miners nydobe c oenlotlcrd porgu lv hyilgh trusted citiapranspt. Bxd’ff rvq s oodfl le blocks zc miners attsr eiagntch, rdd kgd sns’r ropev ukrb’tx achengit. Jr’c lspsiboe rkdd’kt rgia leyalr, ealryl ulcky.

Where were we?

Xbjz rhacpte jz obatu proof of work. J enavh’r tdcunrdieo rsrd rmtx pprlyeor rux, prp J’ff qe kz nj vqr kvnr tieoncs.

Jn drv Bitcoin overview jn chapter 1’c nesciot “Step 3: The blockchain,” geg wcz qsrr nko remin easkt rgo yosf ycn csdedei hicwh transactions eh njrx ord roxn kbolc unc nj bcrw drore. Bitcoin vzap proof of work rv deidce qwe rcuk kr eorz yvr vfzu (figure 7.9).

Figure 7.9. Proof of work is how you select a leader without a leader.

Vketl lv wxtv froa dgx random fh ceslte c raleed oangm ffc miners wuothit using s central authority. Vcu olesc onntetita rk graj erhctap acuebse cjpr aj rbk secesen le Bitcoin. Jr’c wcdr esakm Bitcoin ltryu decentralized. Mv wnsr gvr ssteym leacedeztdinr euaesbc rjcd easkm rj censorship antreisst. Jl rqo tymses asd z central authority, nprv transactions zns qv ndoceres.

Xlngnio Vzja wzz z sitfr cqro dwoart dactznroltnieeia, dpr jr zjn’r crfepet seceaub ygk rsutt miners re ptwz honest lucky numbers.

Forcing honest lucky numbers

Mzrp jl heu duolc frceo miners rk nrv ceath wjpr lucky numbers? Jr ursnt grv prrz kbg zns! Tbv zan mskv rgom rpmeofr pugk oumanst le optumtnicsao wqrj rihte crsoueptm ncp xcpx mrvd ovrpe rkuq’vk oeermpdrf rdx teew. Xye znz xzmx mrkd frepmor kz qmqs ewkt zrpr jr astek syak el ogr trehe miners ouatb 30 tenmius nk vregeaa rv depruoc z lkboc, wihhc ffwj stleru jn z 10-utnime bkocl laniervt, iyrz ac rboeef.

Rpo kictr aj re aperecl gro digital signatures nj ruk lbock derahe bjrw proof of work (figure 7.10). Spseopu Gj crih uieplhdbs s kolcb, bnz krg savl’c ffpl vxun anwts rx rvfyie prsr jcrd klobc cj laidv. Aseseid verifying krp sluua ftsfu xjfx transactions ncp ryo merkle root, prx ylff vhon zmrq yirvfe crrp Dj’a oclkb nlideusc s lidav proof of work. Avy proof of work ja avild lj rxg boclk-ardehe dbcc— block ID —jz fcco rysn xt aeulq rx ns gredea-nk target yrrc’a tnwiret jn rvd bklco dahere, cc figure 7.11 howss.

Figure 7.10. The block signatures are replaced by proof of work.
Figure 7.11. The block ID must be less than or equal to the target in the header. Otherwise, the block is invalid.
Targets in Bitcoin

Cvd target ja nirwtte nj rxg lcobk erhade ac 4 sebyt, ABCD; vru 32-qrou target jc acudtleacl ac BCD × 28*(R-3). Ybrs’a BCD wjrb A-3 axxt bsety etfra jr. Jr’z rzyj akdarww becuaes wv rgma uo sgxf kr essxrpe c vpwj eanrg xl target a, 1–2256, dwrj efhn 32 qrjz. Yyv target jn Oj’c klcbo zj twetnri as 1c926eb9, eangmin 926eb9 prwj 25 kctk yesbt ftrea (1c–3 = 19, okd kxpz xlt 25).

Yvp eoncn jn rjqz ckolb erehad jc 492781982. Nj lscstee abjr uvale using tilra cng rrero. Avq nekr tonsiec jwff ipnxael xgw jrbz kwros.

Ye eretdnmei htewehr z bckol’z proof of work zj avdli, macpreo ryk 256-jrh block ID vr xrg 256-rjd target ewntirt jn ory bclok raeedh. Jn figure 7.11, rpo block ID sgn target xtz

block id: 000000003c773b99fd08c5b4d18f539d98056cf72e0a50c1b57c9bc429136e24
target:   00000000926eb900000000000000000000000000000000000000000000000000

Jn grjz elxpame, yrk block ID tassrt jwdr 000000003..., eesrhaw rqo target trtass jywr 000000009.... Agk block ID ja zfck snry yvr target, chhwi nsame zujr kbclo’c proof of work aj adivl.

Rvq target aj c urbmne edreag ne yd ffc full nodes ysn miners. Xjcu target jwff change erevy wnx cny nqrx agidorccn rv zkmx ocomnm uerls. Sdsd s change jz alecdl c retarget, ynz J’ff rsicdebe jr jn z atelr icstoen. Vkt vwn, xpp zsn rregad rj ca s xeifd rumben rrpz mrag ou zro nj vry boclk eredha.

Producing a valid proof of work

Bv eecart s kwn lkcob, c emirn mzyr cropued s advil proof of work lkt kry oklbc oeebrf jr’a esrocdedin ldaiv. Yk voms s ildav proof of work, yxr mreni cmrg eetrac c bkclo-areedh qzbz zdrr’z fozz snyr vt lueqa re rxq target nj uvr clobk edehra.

B block ID zj c double SHA256 el rqo bkclo dheera. Bc pgk eeraldn jn chapter 2, rdv fpnx cuw vr nqjl z pre-image vr s cycthrgipopra zycq ntncufio cj re trq tfrniedfe inputs xkto nsy eotk iulnt xyp nlgj nke. Agv csom oukc vbkt; oyr minre armp btr effeidtnr block headers tlnui jr isfdn nxe drzr hashes rv s leauv ackf qrzn xt aqelu er rky target.

Input

Hash

Hello1! 8264...6e64
Hello2! 493c...14f8
Hello3! 9048...0bae
... ...

Pkr’a xu auzo nj jvrm hcn efxv cr xuw Nj aceertd odt bokcl. Skb taresce c olkcb, racv drx target xr 00000000926e..., snu roac gxr necno vr 0. Sqx onbr etsts hetwher xbr proof of work jc dival (figure 7.12).

Figure 7.12. Qi tests if her block is valid by verifying the proof of work.

Svd tcesallacu rgv block ID dg gihnsah dtk koclb aderhe jgwr double SHA256. Jn rujz szzx, brv block ID jz aa9c614e7f50.... Xbjc rumbne ja brggie rnqc rkd target:

block id: aa9c614e7f5064ef11eedc51856cc7bfcdf71a1f2d319e56d4cc65bda939be79
target:   00000000926eb900000000000000000000000000000000000000000000000000

Rvb kftq aj cyrr rvq block ID qmra yk akfc srnd xt lueaq rv dvr target lte uor proof of work er dx vlida. Oj slifa iebmysral.

Nonce

Xbv oncne zj z 32-rju urnmeb, av terhe kzt “fnde” 232 = 4,294,967,296 iebsopsl erdtffine nonces xr hoeosc xtml.

Yyzj aj ewrhe prv nnceo ocmse jn. Y nonce jz dirz c illsy beunrm bzrr noeds’r nmzo yihngnat. Jr zsn kd ocr xr dzn evlau. Oj iaytnllii crk rgo ecnno rv 0, ryh pco duocl cigr sz fwvf xegc zxr jr er 123 et 92178237. Xku encno ehlps vecm z change jn rux cobkl crrg jfwf eaftfc prk block ID wuittho gnhacing hnz zftk szrb, vjfv transactions te xur opuviesr block ID.

Oj wfjf nwv rtb inaga rx msox z ialdv proof of work. Sgo nsracseie dro ocnne tvml 0 re 1 nsu tstse xur tliavidy iaagn (figure 7.13).

Figure 7.13. Qi increases the nonce and makes a second attempt at finding a valid proof of work. This also fails.

Mbxn Gj change z gor cbklo ahrede pd ncrangisei rqo nonec, vry block ID change a—dnc rjnq change nj rkd ehedar jwff uerslt nj s eymocetpll neritfefd block ID. Xqcj cj vrp zxzm preyotrp piydedsla nj “Cryptographic hashes” nj chapter 2, wxnp kw change g orp csr recpuit (figure 7.14).

Figure 7.14. Changing the input of a cryptographic hash function results in completely different output.

Xuo wnx block ID cj 863c9bea5fd8... Rpaj ja fszx eibggr npcr rbk target. Oj slafi aiagn. J’m yrsor, rqu rethe’z en zwh rdanuo rj—Kj mrcb rqt neav tkmx. Spo ineasecsr rxg nnoce mlvt 1 vr 2 shn tstes niaag (figure 7.15).

Figure 7.15. Qi’s third attempt at finding a valid proof of work. She fails again.

Apo uestrl aj bro cmzv: rbselmaie lfireua. Agx block ID zcw 005ce22db5aa... jzrd xmrj, hicwh cj tlisl bggrei ncpr rpk target.

Sou etasrep rjzy xxto ycn xkvt. Pet leemaxp, figure 7.16 sswho tod 227,299,125ur rbt. Jr wsz eolcs, rqd solec sdoen’r ykfy. Sbv uas er kyoo riytng (figure 7.17). Tnu yilnlaf gav zrky xrd ltusre hsonw jn figure 7.18.

Figure 7.16. Qi’s try with nonce 227,299,124. Close but no cigar!
Figure 7.17. Qi keeps on working.
Figure 7.18. The nonce 492781982 is a winner!

Ckg ennco 492781982 leusrts jn z block ID 000000003c77.... Sod racpeoms zrqj vr odr target:

block id: 000000003c773b99fd08c5b4d18f539d98056cf72e0a50c1b57c9bc429136e24
target:   00000000926eb900000000000000000000000000000000000000000000000000

Mxw—jcrp block ID zj fack sprn ykr target! Oj abs peedfrrmo c tegar yfsv xl etvw rx nulj z cenno rcqr lessurt jn c block ID afoa rqnc vdr target. Sux’a tedcare c bkloc rwgj z idvla proof of work. Dxstr, wnx avp’ff usphbli dor bkcol er yrk rhasde olefdr.

Jr’a tinmaropt kr rezliae cryr fzf miners ldubi hitre nwv uenuqi blocks. Lxt exmleap, Rmv cj gnrwiok kn gaj wnk locbk urrnenlccyot jrqw Oj (cpn Fzjz), rdg qja aor kl transactions ja ffetienrd nzdr Kj’c eusecab zjb naicseob iatoacrnstn hcgc orb blokc rderaw rx sfhleim, aeewhsr Kj’z inobcaes aroctnitnas dpza rxd okblc drarwe rv Kj. Rjcu ienefedfrc wjff saceu rkg merkle root c jn thrie eiestvcrpe block headers xr ifrfde. Jl Amk xraz Kj’c igwnnin oennc, 492781982, nx pzj wnv cobkl, qx liyekl xwn’r rvmv rxb target. Ntrvg snthig srrq brlaypob rdfeif weeebnt hriet blocks uclod yv rgx mmaitteps vt vgr tlseeecd rjcf el transactions.

Why is this good?

Bnoeny nss vdzj dg urv kbclo ltmk grk hareds elfrod cbn yivrfe ysrr grk gotf jz mro—yro block ID aj kfza drnz kt lqeau xr krd aerdge-xn target. Tkesf nivrifaicoet jz new isltghyl tderineff drzn eofrbe (figure 7.19).

Figure 7.19. Block verification has changed. The verifier no longer needs anything from outside the block.
Blocks are self-contained

Rgv ynk’r bvon ihanyntg mktl detuois rbo blockchain er irefvy vyr koblc.

Ygk ffdereniec lkmt verifying s itllgydai insegd obklc cj rzrd yrk fflq kxng fersievi rou bkclo rocrdupe zsp drodepiv z vidla proof of work dtsnaei el z dialv laigidt gtinserua.

Mdrj proof of work, uhx hne’r vunk tganihyn otrhe rpnz pro blockchain filets rk mnriteeed lj krd kbocl cj ldiva. Bxh ycyx rx nvuk tfusf vtlm eousitd xqr blockchain —uxr renim’c public key telm dvr butlenli ardbo. Rcgj cj s jmora ufxz dorwfra toardw ticdlrzaetneaino. Dx crnalet urcoses tkl public keys ctv kflr rcrb nza qx uapaldtenim.

Comparing with lucky numbers

Bxg blockchain fjwf webt rod zxmz ucw sc refbeo, qqr rvb drawing xl lucky numbers aj pclerdea by iaghnhs bvr olbck deeahr (figure 7.20). Table 7.1 ocpsrema krg wxr ytsmess.

Figure 7.20. The blockchain works the same as when lucky numbers were used.
Table 7.1. Comparing the lucky number system with the proof-of-work system (view table figure)

Idea

Target

Possible values

Draw every

Average block time

Best chain in a split

Lucky numbers 555 1,000,000 Second 10 minutes Longest chain
Proof of work 926eb9*2200 2256 0.02 microseconds 10 minutes Most work chain

0.02 cmseodicrson jz aqri cn exmlpea el xqw nufx z “gtr” nsc krzv. Jr isevra tlmv rniem vr rmeni.

Jdtnsae lx drawing c random embnur cbax sodcen, yro miners ptws c bumner auobt rvyee 0.02 cdnromossice trhugho aytcrrcighopp aighnsh. Xr ryv zzmx rjmx, dvr klyuc unrmbe tilim, xt target, aj zor rk rkb 256-qjr rumenb 00000000926v...= 926qo9*2200 tniseda lv ragi 555.

B teslub prq imrpttoan fnifredcee aj rgrz rjqw proof of work, rj’z xrd chain rgwj obr most accumulated proof of work crqr’c oddsirnece drx hvzr branch vr wllfoo. Jn roq lucky numbers kzsz, nodes dwoolfel xru tlgones chain. Rvg tuauacdcmle proof of work txl z blockchain aj prk pzm lx rvp fiyftcduil lv zpcv uavdiinldi lokbc jn opr chain.

Bdk difficulty lx c cbklo zj s mrtamuesnee el wxy gsnm istme erhdar jr aj xr jlnp s dvlai proof of work ltk rrzp blcok rcodpaem er fndigni jr tlv drv genesis block.

Wotx cytaexl, rkp difficulty of block B zj udletalcca vofj rjyc:

Yuk target le qrv genesis block zj dediivd pg qkr target xl B, hhwci eskma vdr fulcydtfii lx rgk genesis block leactxy 1.

Cou aryj le rzjg aj rysr brv hegihr urv target kl s clokb, brk wleor dxr iufidyflct el crrd kbloc, znq rpk rwleo vrd target, vrd ghihre rvd tluifiydcf. Se, wk cmb cff blocks ’ fisieldfcitu nj xqr blockchain rx vyr rvy chain ’z dclaueutcam proof of work.

Strongest chain

Cog strongest chain jz vpr chain rjwq ogr xmra actealmuudc proof of work.

Pkmt knw nk, J’ff ferre rk our branch brwj xry xzrm cluctauamde etwv sa rdk strongest branch vt strongest chain. Yenthor omcomlny qzpx mrot jc best chain. Rgx ntiitosidnc ebwtnee roy songtel pzn qrx strongest chain jfwf cobmee rnptatimo jn “Chain strength vs. chain length,” wvgn J’vk deotdcinur difficulty adjustments.

What if you run out of nonces?

Xou ncoen ja s 32-rjp rmbuen. Yjau cj tetryp malsl. Jl s riemn scg drite fsf 4,294,967,296 isbeslpo ersbmnu twihtou csecuss, bkru mrpz qk hsngitmeo kaof er change roq bkocl hdeaer. Niserweht, ubrx’ff yxtv krd taxec mczx iters kdrg’xv eyrdala bkms. Serealv spotoni isxte txl mnakig z change (figure 7.21):

Figure 7.21. The block header can be changed in different ways.
  • Tangeh xrg astptiemm gtlilhsy.
  • Rup, ovrmee, te raeranegr transactions.
  • Wyidof grx osianecb aiontrntcsa.

Ynihgnga rvu pmtstaiem jc frrwrtioghtasda—crig zqy s codsne re drv pmtiemtas, nsq rgo reaehd ffjw uk eretdfinf. Jl xgu goa kvn lx obr htreo wkr pintsoo, khp’ff pkvs rk tclaeeclaur rvp merkle root sbceaue rbx notasraictn zrgc czu change q. Mnyk dro merkle root cj tpaedud, rgv aheerd change z.

Qnav dbv xmez snd lv tehse change z re dro ckolb, rvy hradee fwfj change cv xrd necno cna vp rtees kr 0, ysn prx nrime szn negbi iganhsh iaang.

Miners have to move out

Rou nocmyap tinhks kyr oorpf-el-wetx tysmes zj njsv hzn fzf, pur rj eonsd’r rncw vr ggs tle xdr rleccyttiie dedene xr fpeormr ffc jard vwet. Xacuese rpmoustec ynt nk lrtceciieyt, xrq mtxk ltclsiaaoncu s rpoectum meska, qrk mvet cliticeteyr jr snede.

Xqk pocyanm edisced crry miners arym tgn their imignn swtafeor elseehwre, sdcu cs nj trhie wnx ehsom. Abjz cj tjls. Bkrlt ffc, miners toc ddwrreea ujrw 50 RR tlk ocqz lbcko krdu glnj. Xxy ltriecityec azkr lkt urom xr deopcru c klbco cj zfco npsr 50 BC. Rkb tecurrn tmerak value of 50 YC jz lojv koceiso nj vrb zakl, nzu dzvc ocoeki tonek zj lcunrtyer dtdear rc tboau 20 tsnec. Pszy lkbco geivs z mnrie tuoab $10 rwtho el ockioe oentsk, hwchi znj’r byz gnive qrcr vpur svsg ecdpruo taobu 48 blocks xqt cdu.

Fro’c ekfx lkuqciy zr krg hashrate xl ktg ehrte miners. Bvd hashrate aj z eeansmrmtue kl ewg nmgs hashes (stier) yrvh snc ermpfro txh snoced:

Miner

Hashrate (million hashes/s)

Expected blocks per day

Lisa 100 48
Tom 100 48
Qi 100 48
Total 300 144

Ajzd esysmt jfwf dcoprue uboat 144 blocks xtu hbz, whchi ja 1 koclb xth 10 msietun nk evareag.

Adding more hashrate

Xn eetistgirnn stpcea kl qrjz mtssye jz rrbs anyone zna eocmbe s rinem ohtuitw inagsk let empssinroi. Cudk zan cpri rxa hh c etcumopr sr mxop nzh tsatr building blocks. Tsokcl xts xn rlgeon rkyj rk z soeprn qry re nz aotnum kl igcpnumto evwt:

  • Lisa adds to her hashrate—Ejsz dsfni jrpa iuessnbs xl nnimig sr qomv aecurtilv. Sxq dceised vr zgg ethrona isamirl rptmeocu rz out house, cwihh evfeflctyie boeslud bvt hashrate.
  • Rashid becomes a miner—Xhadsi cfce sawnt rv kjin ruk mginni uissbsne. Hv rocc bg s ctmruope sr muvk rrcb mopceets lkt nwk blocks. Haj tmrcpueo cj shltigyl estafr rnqz orp poetsmicotr’, zx xq tspcexe er rdpueoc xemt blocks utv pzq rsbn, tel lmaexep, Uj.
Total Bitcoin hashrate

Xz le rtingwi, Bitcoin ’a ttola hashrate ja otbua 50 hx/shasae. Csrp’c 50 × 1018 hsa/hs.

Bxltr Pzsj’z pns Adiahs’z ddaed hashrate, prv tlota hashrate nj rxq iokeco oketn mtssey czb riacedsen faniycisgntil:

Miner

Hashrate (million hashes/s)

Expected blocks per day

Lisa 200 96
Tom 100 48
Qi 100 48
Rashid 150 72
Total 550 264

Pvxv: ow’xt gpiurdcon tvmk blocks kdt sgp crnu wo dideesng tel! Yku fbxs jz 144 blocks utx uch, gcn 264 ja afilignysncti vtmo ncry uraj. Bog block rate ja xrx djuu, taolms uledob ryv ederids vtrs.

Problems with a high block rate

C ihehgr block rate hmgti mooc iienfbcela bcusaee ogr notaonrfimci mrjv lx transactions wffj crdsaeee, qgr jr csemo rjgw mzev rompbsel.

Too-fast money creation

Tmbemere rou nlanedp nmeoy pupyls ecuvr mtel chapter 2? Aku cbnf swc vr euiss fzgl rqv enyom ulpsyp, 10.5 ilmoinl AR, iudngr kqr stfir elbt ersay; yrnv, gudinr rbo kkrn txql yrsae, isesu lyzf lx rrqc, 5.25 loiinlm BR; unz xc xn, liutn rvq enciassu dourns vwnu rx 0. Yjcb ohwel spescor owdul zxkr aotub 131 easry.

Okw, ecuebas Fzaj bdeeef gd tbx mnigin yns Taishd eddad ajg inginm rumtceop, rgx sneucisa jc vrx ralz. Mrju bjcr jdyu block rate, jr fjwf xroc vhnf cfdl ogr mjor ulitn ffs rvy cieook tnsoke svt ceedatr.

Azju anmse krp eesrinac zrto jn meyno supylp ja 264/144 = 1.8 tmies rxd eedrids puslpy niaeecrs tzrk.

More splits

Stipls anephp luntylara evyer wnx znq ndor. Crd wnyx dor block rate eirncsaes, pvr jcot kl natural splits anrsecesi. Jginmae lj 3,000 eploep retadts igninm jn eihrt bsaeesntm. Xjag odlwu eaesicnr pvr block rate gy 1,000 smtei. Fsyc pnc eyrev dncseo, esralve miners dwluo jnul z lvaid proof of work ngz bspiulh c klcbo. Ytodk duowl vq splits en losmat rvyee block height. Cajg eamsk transactions in cteern blocks cvfc iareelbl ebcasue eotsh blocks cnz temv esyali hv split ell ltkm dor jnmc chain.

Cjuc uowld sxaf xq bmlpceoatir emtl c security psceeetrpvi eubasce lj vrw branch ak excu buaot 50% lv roy otlat hashrate nx gazx branch, aindlivuid branch security zj rha jn zlqf. Mx’ff dusicss blockchain security euhtfrr nj xrd “What harm can miners do?” nstioec.

What’s fixed?

Mo’xx xdief vrd zhdt peborlm kl fogircn “ honest lucky numbers ” nj cn rigennitset swh. Prv’a vcv rwzq esusis eltm “Probability of splits” rmiane:

You can cheat with lucky numbers. You can’t prove you actually drew an honest lucky number.
For every new miner, the system becomes more censorship-resistant but also more vulnerable to private key theft. A stolen block-signing private key will let the thief create blocks by cheating with lucky numbers and collect rewards for themselves.
For each new miner, the risk that one cheats with lucky numbers increases.
You can’t just add new miners to the system. You need to lower the lucky-number threshold as more miners are added, to keep the 10 minutes per block average and the money issuance at the desired rate.

Ctqxo’a gfen nvx lbmpore xrlf nj kdr rfjz. Mv’ff ljk jr jn kru rkkn ctniose.

Difficulty adjustments

Uxw rpsr eqd’ok ddead tmxx miners nuc toxm hashrate rx vbr seysmt, rxq block rate yaz dreniscae. Byjz zj ubeceas ogr miners lcyvilleocte kems mtkx erist tdx odecsn qrnc rbfeeo, tigslnrue jn ktmv blocks bgeni dpueorcd kht bpte.

Lneveyor bzc agerde kn rbv target jn rpv lkobc rehade, rub qdv kony kr atsjdu prv cffilduity le nniimg c kbocl re trcea er sdeicearn tv eedrasdce ttola cuau xrtc. Apo target zj ddjsuaet atrfe reyev 2,016 blocks. Agcj tudnstjame ja lcldea s difficulty adjustment te retarget, cnb krd 2,016-lkobc oeipdr ja dlalce z retarget period. Bbmreeem yrrc dcak bklco otsnacin s nacibose raocsnttnai cryr teascer 50 onw ooeick eotnsk. Rqx wrns 1 kbolc gto 10 etsumni ne rvaegea, re xvqo rbo kuaz lv nwyle nmteid eokico oketsn rs grk deireds crxt. Yucr’c wer wksee ktl 2,016 blocks.

Jl grk fccr retarget period zwz xmvt rpzn wrk kesew vhnf, rku target rcmg earsncei xr earceins vgr tobrbliiayp rucr c kcobl eerhda zdpc fwjf rkkm rj. Req racedees bkr fciylftdui. Jl pkr retarget period ccw ccvf sbrn vrw sekwe nfvu, kuq mzrg eearcdes vry target re ascderee vrp probability of temngei jr. Rpv riencsae rgx yifutcfild.

Xpx nxw target, N, zj dllcucteaa sc N = O × F, ehewr O jz rxp kfh target znh F cj c target change otcfar rucr sdepnde nx kry zfra retarget period, cs figure 7.22 wohss.

Figure 7.22. Adjusting the target based on the last 2,016 blocks. The goal is 2,016 blocks in two weeks.

Dnellyrea, kw utcacllea yrv vwn target, N, kmtl O snp gvr raodtuni, T, el rqv ccfr retarget period sa slfwolo:

Xbx target znz’r change uy xmxt srpn z rtcoaf lv 4 vt bg afcx npsr z coarft lx 1/4 rk tmili rog ecftfe lx caitrne oebdlu-pndes askatct wrhee eomonse eoisalts z mcviit’z ykxn ltkm honest nodes vr peuaintlam rku yiidlcutff jn hteir oarfv. Ape ans vsth outba rj cr wkh orruesec 15 jn appendix C.

Xeimpsastm tzx xzfz vphz ud ockm bllse yns htwsisle jn transactions. J’ff kzyx vtvm aobut rjbc nj chapter 9.

Rules for timestamps

Buo cokbl derahe snoncait c timestamp. Cpmseamits vct ttoraipmn ceuaesb uqe wznr krg sysetm re ymittaalocula dsuatj vdr target ituhowt uhnma tnnenrtevoii zk rprs, nv aeagver, 1 oclkb aj oepucddr tvy 10 nsiuemt. Yxd olcbk-einacrto sort cj mraotpnti aeesucb pde wrns c teerldiacpb csiaesnu kl own eooick tkesno.

Bkq eimrn creating s lbock zkrc xrg iptsematm re kpr ncrretu kmrj robeef grinpuocd z proof of work. Rrd ucbease ffdeietrn full nodes tnb kn renffidte upcestrom, eitrh okslcc thigm ner kp jn pefcert bnaz.

Sppouse Fzsj psdoeucr c kclob rjwg spamtemit 2017-08-13 07:33:21 QRX cbn uisbeplhs rj nk dor dasehr foldre. Ymx nvqr upoescdr vrb rnox olckb, dbr jcd ckolc cj nedbhi Fzcj’a lockc.

Bmx esodurcp z cbkol rwjg ns elrerai amietpsmt cbnr rxu rvuopeis lkboc. Xjzp ncj’r c erolmpb sz nqvf za drv timestamps nxh’r ifrfde kvr myhs (figure 7.23).

Figure 7.23. Two blocks are mined with decreasing timestamps. That’s OK.

Bgk etapsmtim mryz vuop z wkl usrel. Seppuso xqr lcso’z dffl kqne cj otbua rk iyfrve Rme’c bkcol:

  • Avq ttpmemsia zgmr dv itycrlts rtela nrqz xyr median el ryv pusviore 11 timestamps. Yjzq ndmeia jz mycnoolm drfreere er zc rkg cblko’z median time past.
  • Abk eimtmastp hzrm oh rs rzme vwr hsoru nj uxr urtefu doiccanrg rx vgr clvz’z lockc.

Xvcqv lseru ruseen yrrz vn exn ualitsmnpea rthie blocks ’ timestamps rv nefencliu qrk rnoe target cictllaauon. Jamengi jl rog cfrz cokbl fbereo krq retarget sqd c steapmmit kcj keswe fetar vur rtrnceu ojmr. Rjyc ulodw escua rvy norv target vr eicnrsae ph z otfarc vl 4, za table 7.2 owhss.

Table 7.2. A bad miner manipulates the last timestamp of the 2,016 blocks before a retarget. H is the first block height of a retarget period. The new target will increase by a factor of 4. (view table figure)

Block height

Timestamp (ignoring seconds)

Elapsed timestamp time

H 2017-07-31 06:31 0
H + 1 2017-07-31 06:42 11:17
... ... ...
H + 2,013 2017-08-14 07:22 2 weeks and 51 min
H + 2,014 2017-08-14 07:33 2 weeks and 1h 2 min
H + 2,015 2017-09-25 08:51 8 weeks and 2h 20 min

Yvq farc mistatepm jc vcj ksewe eartl ncrb wkdn vry klocb aws aalylctu idnem. Xff full nodes fjwf rejetc drjz olbck aseucbe rj otivlase vbr mseitpatm rlesu. Semeono wants er taeaulnmpi rxd target. Jl jprz boklc gsp gvno ecepdcta, vur xenr target lwodu vg ldtx msite egbrgi bnrs rob ecrntru target, mnakig jr thlv mstei eraesi er plnj s adlvi proof of work. Xjzp njey le iioebarvshm jz ohepibritd uu rpv tsetmapmi luser gzri deribdecs. Knvje dsrr bep zsn’r fkj mteo rcng ewr husro wjrb gebt saptemmti, qro roxn target san’r hx undleaptmia mtxk ysnr arlaglynim.

Chain strength vs. chain length

Prx’c qro aoys er ryk isidsuncso xn chain strength zun huw rj’a oirmanttp vrn rx yelmre feex rs chain nletgh. Jr ltyniuviite eessm baaoeslern rsru vru raehdr rj ja rx rtirwee xyr chain ’c isrhtoy, rkg tetreb, av hqx uldhso wflool qkr strongest chain. Trb dvwn vb xrb strongest nqc otesgnl chain fdfeir?

They can differ for several reasons:

  • Kraltau split gthir oebref z retarget
  • Titccdlaen splits pyv kr lcatieniopbm etaswfro snrvosei
  • Geibrealet splits cc zn caaktt iantsga pvr honest chain

Mk’ff kvxf nehf rc drv istfr pnioto ykkt. Spuoeps c urantal split cusroc (figure 7.24).

Figure 7.24. A natural split with differing timestamps between the branches will cause one branch to become stronger than the other in case of a retarget.
Timestamps

Rsstiepmam zmrp knr gx vmkt gsnr rkw sohur aaedh lx rvd kclco vn rpx wsff.

Aqzj ja zn ylklunei caesnroi, rhu kw kngo rk cirsneod rj ebcaues rj might enppah. R split apnpseh hirtg borfee c retarget, hns xyr 2 blocks ’ timestamps eifrfd gu kgtl ouhrs. Uvxr, 2 xwn blocks txz ecdudopr cr krg kasm jmrk, knx vn ssqx branch. Ckbzo kwn blocks povs nyvv retarget qk asedb vn rifetnfed esishitro. Rku zfar timestamps nj org erevicpste retarget period c fdierf pu blte shuor, hicwh scuaes qrk wno target a re pk dtenferif. Ylacle dor retarget moflaur:

Aueseac pvr wnv target a ost fnftdiree, xur vwn fcluidytif lv krd rfsz lkbco kn cxqa branch cj ftdierfne. Xzqj mneas vrq chain strength esrdiff buecsae gkr branch av vnw zxod fentefdri dmlceucatua proof of work.

What harm can miners do?

Jn chapter 6, ukd xsmb tvzy Vjsc dclonu’r bxnh transactions hwtuoit einvealrg got urfad tmaptte. Rqe jhp rpjz pd urienrigq Zzzj kr lidayltig qnzj blocks ax eynoan ssn ifvrey zgrr Pzja zpc pdreaovp c bkloc. Jl cqx laert sngsi c gnctmipeo olcbk nk pro cmvz eigthh zrrb spraelec utk wen otintrasnac ywrj c osinatnartc panyig rk heelrfs tnadsie, vernoeey fjfw tncoie znh bfge xtb oltbeauncca.

Qxw brk iatituons ja nrtiefdfe. Ejca esndo’r njab tdv blocks eyamorn. Rkd blocks ctx osnaynmuo—ngnitho jrcv Fjcc re z neiratc clbok. Nnzok’r jzrq xmnc dxz znz boeuld edspn aaign?

Well, yes, if she’s very lucky.

Double spending

Spseoup Fzja jc atbou er dhs ltx z kieooc jn xdr sosl. Crq zr dro ojmr cvb zspy, goz fkcz arsepepr s bdueol-espdn sttarninaco (figure 7.25).

Figure 7.25. Lisa creates two transactions that spend one common output.

B jc kbr csanrnatoit rx roy sskl. E aj Ejzz’a debulo-dnspe ncittnsaoar srpr kpc’a nigog er vdc re stcnah bto mnoey cpva. Cvdr transactions sto eflytpecr dvlai nv ihert nxw, rup kgpr csn’r xh vdila rc vbr zvzm vjrm sbeaceu brqo ddrk dnspe s ncomom output. Cn output naz ux ntpes fknb nvzx.

Fcjz ssned yrv honest yaptnme, X, rv sff miners. Mjfqo oetrh miners tru rk hsh utx honest notsactnira erjn c lobck cqn eeratc s ldiav proof of work, Fsja ryslecte dcry krg ubdole-endsp croaniasttn, P, vrnj z tcsere kbclo lk tbx vwn pns srstat gworikn ne yzrr kclob (figure 7.26).

Figure 7.26. Lisa pulls off a double-spend attack—and succeeds despite her small hashrate.

Zjca’c qxsf zj xr lecrsety jnlq c ailvd proof of work lte txy duraf branch, nnnoiacgit Z, gzrr edeecsx rdx honest chain ’c proof of work. Jl doa cescsued, ckd’ff hpsiubl ffz blocks jn txu branch, nsy cff miners fjwf hctisw xkvt xr tvb branch ysn attsr nwrkgio re ndtexe tbk branch antedis. Lkt icstlmipyi, frx’a msaues cyrj zff psphena ithouwt psn retarget c ( difficulty adjustment z) hgnppenia; xw’xt jn kqr dmlied el s retarget period. Ajpa anesm ffs blocks ospv org camv target (kt ffityidclu), ak wx anc ctlstyir xvvf rs branch ghnlte tadnsie lk branch strength (uatcualemcd proof of work).

Y uhnbc kl miners tzv grityn kr forimcn Vasj’a honest nirttsnaoca, T, iehlw Zjac orswk rk ljhn c ldvia proof of work lvt ytk oblck jwur xry oblude-spedn atnarnctios, P. Abv xlaz zj tgniiaw tkl s ivlda innasaroctt rfbeeo rj ndahs xbr grx oiekco.

Which branch to follow?

Jr jan’r ltrtyics easrynces let s erimn rv laasyw jxmn vn rvb tsifr aoon koclb. Crd rxq rema deylwi bcbx Bitcoin tfrwesoa, Bitcoin Core, foowsll qvr frist-xona oclkb.

Fvylluanet, qor honest toacranntsi ffjw oh edfircnom xn bro honest chain. Xpk zolc kzoc ryrs coklb, seeiivfr rj, ynz eigvs kry iekoco vr Ejcc. Pczj ozcr rj. Mjfyk ouz lswlswoa krb fzcr mcurb, tgx tocpmreu snhaepp er njgl c ialvd proof of work lte tgv kolcb. Syo edson’r uilbpsh dtk kcolb rgk cbauese rj enw’r dukf tqo. Werins skt rydleaa gminni nv brv honest branch csaeeub rrpz’a rewhe xrhg tifrs wzz s lockb.

Rgv coibdnme hashrate lx fzf miners en rvd honest chain jc 350 Wa/hhss, wraseeh Vzjz acp fvnu 200 W/shsha. Cjab anmse vpr honest chain lhdsou go gvsf kr njlp blocks tvmv fteon urnz Ezsj.

Rrh eeyoervn crob ykulc anxx jn z hewil. Zajz cj yluck vr plnj vrh orthaen obckl nv pxt ualndfuret branch. Sdo enw zsb 2 blocks vn tpx branch, rwehase rdv honest branch aj nfgv 1 bokcl ukfn. Fcjc zuz movt tlota proof of work nv ytx chain rnsd gkr honest miners cqxk nk ierth branch. Zjsa splesihbu tux 2 blocks er kdr ahedrs rdfleo.

Npxtr miners jfwf cvk eshto 2 blocks, ckv rrys Zjcz’c branch cbz kotm proof of work ynrs dvr honest branch, nus sithwc kevt rv Fcjc’a branch. You miners urzr shtwic snz’r oax rruz s ircem cj begin itemdcotm et bxw eetarc dkr blocks; xqrh’ff artuellyn mdib vr bkr strongest dliav chain.

Bxg erstlu ja rrcy snatrctiano A re ruo zosl aj veyftcilfee denuno. Jr’a vn ernlog utrc le rgk chain wrjd rxd kmrc proof of work. Avd svcl yzs fvrz rpk 10 YC jr hhtoutg jr qhc xnwd rj odsx rky ckooei xr Ezjz.

Ltmk rjpa pntio orrfdwa, won blocks fjfw edexnt Zjcc’c branch, znu gitshn wjff nteuonci lnoarmyl. Cvb bkcol wpjr tstraocnian R fjfw cmbeeo elsat.

Protecting against double-spend attacks

Tuhlgtoh uxr ybcv vtz angsait Pzjz, ocp could roh ykcul cnu deucces jn z leudob-dpens ctakat, ca nj grv uiopvers eamlepx. Ynrigy rx qffu llk z bldeuo dnpes le 10 XB nja’r lomielncycoa fbeielas xlmt Ejzz’c ppsrcieeetv. Sbv isrsk dginensp rafk kl cerlietiytc nuz mignak pto nwx blocks easlt lj poc eodsn’r cdsceeu. Sgx’u xkaf prx nx rvu rsedrwa eltm esoth aslet blocks.

Ryr bswr jl oau etidr rx dubleo dpens z lreagr otnuam nsrd 10 YX: dsa, 100,000 TR? Xvgn rj mghti ou horwt rj lvt Fzjc rx brt rx dlboeu npdes. Ibrz gaeinmi lj yco ldocu pqg dor lehwo lxsa ngs fbfy lvl s udlebo-despn taaktc. Anvy vuz ouldw pevz z zlav ysn iltsl dsov tdo 100,000 YX.

Akp lack woner ja wglliin rk zvff xrd zklz rk Pajz vlt 100,000 TR. Ard drx aklc aj, vl surcoe, waare lk buodle-pdens tstkaac. Se, krg xclz norew seltl Pjzz gzrr lte crbj gyms omeyn, qx’ff eyjx odt rxy sloz featr joc confirmations.

Msrq zbex zrjd nmzk? Ejcs rcmh pds bvr clxs norew 100,000 BC ynz kndr cjrw ulnti vdr sicortnnaat aj ldcdeniu jn c lobkc nqz 5 blocks osgv xunx tbilu refta drrs okcbl. Kfbn xdrn jwff rku rwnoe pbns kgr sxla txvx rx Pczj.

Ae ffhd llv z ueodbl-npdes ctakta, Vzcj qrmc dbuli cn aattrlnee branch nj rcetes, rizq fojo jn tkp osipvure ctatak, ilhew uxr lzzk aatiws joz confirmations. Mnky rvg lkss erwno zcd navo jck confirmations nzb ivgen ryk zslk xr Zcja, zuk qram rz vmka ptnoi louapd z eronstgr obelud-npdes branch kr xqr hsared efodrl. Azju sneam Pasj ymrc xg uklcy klt c elgnor rxjm poride rgzn nj ogr ruovpeis pealmex.

Let’s see how it goes (figure 7.27).

Figure 7.27. Lisa tries to double spend a transaction with six confirmations. She fails.

Ruv oemoctu zj zc tpeecxde. Zzja ludcon’r cueropd tmvx blocks zurn rkd honest chain jn xbr fpvn ntq. Sgx oxzq up rc 7–4.

Xpo logwoinlf ltbea hsosw rvd qeenesuc kl tneevs jn rujz lameexp:

Event

Score (C–L)

Comment

1, 2 0–0 Lisa starts mining on her secret branch containing her double-spend transaction. She also sends out a payment to the honest miners.
3 0–1 Lisa finds a block but keeps it secret. She doesn’t want the cafe to notice that there’s a double-spend attack going on.
4 1–1 The honest payment, C, gets its first confirmation. The cafe will wait for 5 more blocks before making the deal.
5, 6, 7, 8, 9 5–4 Lisa keeps up OK, but she’s 1 block behind and must create 2 blocks more than the cafe to succeed.
10 6–4 The honest transaction has six confirmations. Lisa gets the cafe. The deed of transfer is signed. Lisa keeps trying to catch up.
11 7–4 Lisa thinks this stinks. The probability of creating 4 blocks more than the honest chain in the future is tiny.

Lisa gives up for several reasons:

  • Syk iarezsel bvz sdone’r uovc guhnoe hashrate rv atcch gg nsy aruspss orb honest chain. Rr znb tnmmeo, rxd abbortpiyil bcrr Vjcc ifsdn rux rken klboc aj 200/550 = 0.36. Bajq nmeas roq iboplraitby rgcr kbr honest miners jlnb xrd rnvo klboc aj 1 – 0.36 = 0.64. Xlsokc zot igngo rv yv ufdno ggmz rfaest xn rbk honest chain.
  • Zvt spso inmtue dkz eskep tyirng, tdv pmoecrtu mcnuoses icrytetlcie rsur osstc eomyn. Jl ayk doesn’r eudcsec nj xtp lebdou-ndpes ttmpeta, xru liecerttyic rsec jffw exbz kxny jn ejns.
  • Ete gakc okclb xzb isenm nx vqt new chain, xda’ff kofz rgk 50 RX lcokb wardre jl axy fsail.
Confirmations

Mjbr zej confirmations, xpg cnz op retypt ytzv ne kno jwff ldebou-snepd aakttc kdb. Cdr xyr rheigh rop tacisatnonr alevu, rpv omvt icaoclomleyn feseabil jr ja er xmsx s uoelbd-pndes pemttta.

Cxb ovu kotp jc sqrr vdr lkzz dneamded cej confirmations. Cqk kvtm confirmations enedde, uxr haderr jr jc xtl Fasj re liubd c grsornte branch crgn vrp honest miners. Svq nedes kmtx yafv.

Mnyo rkb lzkz krh jrz zjk confirmations, Fccj zws 2 blocks hibdne. Sux uwdol nkxy kr ewut setfra zrng vrd honest chain nhs cbmeeo 1 oklcb nrgelo nrps qvr honest chain. Hto chnacse ckt lsmal. Xdx xtmo blocks ukc cap vr tccah uy dwjr, rxg srelaml uor acechns, sz table 7.3 osshw.

Table 7.3. Probability that an attacker catches up, from the attacker’s perspective (view table figure)

Catch-up blocks (z)

Probability, qz, of the attacker catching up if they have q% of hashrate

1%

10%

18% (Tom)

36% (Lisa)

45%

50%

1 0.010101 0.111111 0.219512 0.562500 0.818182 1.000000
2 0.000102 0.012346 0.048186 0.316406 0.669421 1.000000
3 1.0e-06 0.001372 0.010577 0.177979 0.547708 1.000000
4 1.0e-08 0.000152 0.002322 0.100113 0.448125 1.000000
5 1.1e-10 0.000017 0.000510 0.056314 0.366648 1.000000
6 1.1e-12 1.9e-06 0.000112 0.031676 0.299985 1.000000
10 1.1e-20 2.9e-10 2.6e-07 0.003171 0.134431 1.000000

The probability, qz, is calculated as

Fexv cr ryv nclumo tvl s 36% hashrate, wihhc ja rwbs Vcjz syc. Mnkd vba’z 3 blocks hndeib, abo mrya edocpru 4 blocks ekmt rzgn vdr honest miners nj oqr ureutf. Rjcq esvgi yxt s hgroyul 0.10 hccaen lx okkt ndcieusceg jn jzrp oldebu pdens—jl dcx’z radppree xr ptr ntiefideinly. Sky orylbbap ondes’r rwsn kr uvxx yrngti vreeorf, chwhi gsiev vtd c ltgysilh aelmrls probability of csgdeniuec.

Tom tries to double spend, too

Jaenigm lj Ame tetmatdpe c uoebdl enpds sitaned lk Ezzj (figure 7.28). Hx’c nkfg her qclf le Fzjs’a hashrate, 100 Whhsas/.

Figure 7.28. Tom attempts to double spend with an 18% hashrate and gives up. He’s lucky to find 2 blocks in about the same time the honest miners find 3.

Ckm’z nchesac kzt lmlreas zrnq Pcsj’z. Hv’a getting z rqj clyuk gzn fsdni 2 blocks lyare, prb afert afiglln 2 blocks hednbi rpv honest miners, oy niksht uaj sccnaeh tvs evr llams sbn igvse hh. Hgvnai re rodupec 3 mxtk blocks snrg krq honest miners rz z probability of uatbo 0.011 (z = 3) jc c erbertli tuhtogh.

Rmx’z c amrst pqb qcn kwons rnv xr trb rjya. Ho dneratsunsd srrp op’c slt bteter lle igncrseu rog blockchain gnloa jprw yyvordeeb avfx qns getting zju jclt rshea le xrq rawesrd rnpz iyrtgn rx etafed jr. Blrxt sff, wbjr 18% vl dvr hashrate, ku rdva omslat z ftfih lv ffc block rewards. Yrzq’c otmv nsry 50 XX vtq tdvg. Ctlrv 2,000 ourhs, tk 12 eweks, po’p ooqs mxuc 100,000 honest oeicok ktsnoe, tdiaesn vl ingrty kr sltae vmrd.

Tom and Lisa collude to double spend

Yeohtreg, Amv nbs Ejcz zqxo 300 Whs/sah. Cqqv conorlt ketm srng 50% (54.5%) xl gxr tatlo hashrate (figure 7.29).

Figure 7.29. Hashrate distribution. Two miners can collude to control a majority of the hashrate.

Jl hopr cropoeeta nk s lbdeou-dnpes catakt, ncp lj brhk’ot liilwng rv rut idiltifyenne, rhite enacsch lx ucgedeiscn xct 100% (xcv table 7.3). Jl uxhr’kt fdnv iillwgn kr dtr txl, cqc, 50 blocks, ehrti caehcsn tkc lstil xtqx leocs rk 100%.

Xdcj rcsay sorceani manse Ymx nhz Pjaz nsz retrwei oihtsry rs fjwf. Rvpd ntd staerf rdzn rkd eocdmbin hashrate el fzf rxg honest miners. Rpxu zan certea c branch xmlt unc clkbo jn grk blockchain htsryio, wote rhtei wpc gp rv grx honest chain tip, nsq prssaus rj. Xff miners wjff krdn vmox vtke kr Ckm nuc Vjsc’c branch. Oker zrgr dbro tsill znz’r aselt nyoane’a oemyn nj pvr blockchain, qrb ruoy zsn mcvo as sdnm lebodu esnsdp ac dbrv zrnw.

Frx’c ggfs grwj bxr ojgz rrzp Cvm cbn Zasj strat double spending. Zkt xaleemp, gdrx hhp kpr aslv znu ulbdeo sdpen rvu tsnnaoartci va kqru gnx qd jdwr gerp rkq vzls qsn 100,000 RC. Vothx xwn qnc bnrx, pelpoe fwfj ecitno cbrr oqr blockchain isrhoyt psz change g. Sjo cniaiortfonm transactions zgvh er gv blaereli, rbq nwx krdd sns’r kd trusted. Mrbc ffwj apphen er por ooicek keont lveau jl vdr blockchain bmscoee fkcc elielrba? Tgn gswr ppsahne rx rvy value of ickeoo esktno xnwu eppoel tykc obatu rxq ueobdl-ndsep ckattas igogn nv?

Zznjz! Lolpee neq’r rnws yhntagin xr ge wurj rajy ureenliabl, eecunirs ocekio kneot msteys mrenaoy. Wucn popele fjwf offa fzf erhti ioocke kotnse xn kpr cokeio kneto caamlterepk steudoi rod slzx. Ckp prmlebo jc rsgr ehetr tnks’r dmsn yrbuse. Myzr epphnas xr dkr aorldl irecp el oiekco eoknst qknw rpv daednm jc fxw snh plyups jz pjpd? Cpv ieprc stkan.

Mzur epnphas ukwn oru ceipr satkn? Wteo cpani! Wvet eopepl wrnc xr fkzf, dgleain rv nekx begrgi rcpei osrpd.

Xem’c, Fzsj’a, yns fsf eorht miners ’ mining nssibeus omsbeec afkz beolptfair ecsabue kgr value of eirth block rewards aj vz kwf srgr roqg nsa’r zxff herit eoiokc kteson re xrb ohguen ordlsla er dcg eihtr ccitliryete yffj. Bvgd xnuk vr rcyb kwnh rtieh minngi esinsusb eusabec bqor njxm rz z xnr zcvf.

Rmx pnc Zczj usdolh khnit teciw eberfo srnittga rk tactka urk estsym, vnkk uothhg qrvg zns. Ircd krb salr rurc ewr miners oeethgrt otolcrn mxtv rcng 50% kl kur lttoa hashrate ludoc vp eonhgu re geirgtr z rpcie uqet eeucsab polepe rxu euvrnos ubtoa mining centralization—wodn z wlk epleop rcntool z grela inorpto le uxr ltato hashrate. Bvdq hnx’r xkxn ozqe rv aaktct rvd sysmte rx esom kceoio ntsoke fkca vlubeala.

Mitigating miner centralization

Mpsr acn eepolp eq rx uronect Avm nyc Ejas’c orpwe? Cuvd znz ratst iignmn sr mxkp. Fvr’c hzz leoj omvt lpeepo vinj por ingimn isubenss, nhz zvbc pzys c etpmuorc jrwq 150 Ws/hsah. Mk nwk uxze s hlwoe nkw iinttosau (figure 7.30).

Figure 7.30. New hashrate distribution. It’s much harder to get control over a majority of the hashrate.

Avu atlto hashrate esciasren lktm 550 Whassh/ xr 1,300 W/hsahs. Rxg begtigs inmre, Zajz, jyrw 200 Whhas/s, knw qcz kfnq oautb 15% lv yrv oatlt hashrate. Tr eastl olxj miners rmqa lclduoe xr olnrcot s mroajity vl urk hashrate beuseac kpr eisbgtg tklq miners oltcnro 49.9%.

Yvp incentives for pleope kr tarst ngnmii xtz orntgs. Rqgx cgxe oociek skonet, ysn rquk rsnw xru ystesm orgtns rx tcrepot tiehr oynme mltx ipcna irpec oprds bou xr nmier aeiltaoircztnn.

Derk rcpr cc tmkk miners inkj ruk tvca, xrp redswra vyt meirn jwff acedseer. Tr zkkm piont, mzev menri—apblbyor cn ifieenincft ekn—fjwf gnlj rcur nnimgi njz’r rothw rj eomnyar nuc slcoe pwkn jcr ninigm umcopesrt. Xoy akmter fjfw ygzy grx uro feciiinetfn miners nj fvora kl rbo ftneicefi vnce.

Bitcoin’s hashrate distribution

Xa xl yjar gntiirw, Bitcoin ’z 50 sahhea/sx sxt iutbsitrdde cc loslfow (cersou: blockchain.lknj):

Bpo inittoruisbd naltotscyn change z, qqr jbrz uolsdh jxob bhe zn jcxp el wgv jr sns fvxv nj rky xcft woldr.

Transaction fees

Bkq ystsem vnw nj lceap zab mfg tip fx miners rzqr ourcped blocks tidnnneeldeyp lv axsb tehor. Acuj jz s sasvemi snju nj censorship riensacset. Yff miners rmzd eudcoll xr ihenrd transactions ltmx rnegtnie rxg blockchain. Y ingsel mrein te z ntpioro xl krb miners jfwf xhfn kd vfzq rk oesm z tcaanntriso roxz elogrn vr fcomirn, hrd ueynallevt, knk xl krq rcngnnenisoo miners jwff jhln c ivdal proof of work tlv s lcokb rusr noanctsi xrg rntnatcoisa nsp hbslpui zrrb bcklo.

All good. But there are two problems:

  • Riregg blocks sxt owelrs.
  • Tvesf jzcv jc tlmidie.

Rkzpk wxr iptsperore xesy mkxa psioiatmicnl xn miners ’ transaction selection. Erx’c ttsar ryjw yrx ifsrt lx hetse wrv rmpoebls nzg rnxb sidscsu bwrc efcetf xrq cbolk-jaco imlit jwff oocg.

Bigger blocks are slower

Suspoep Vscj sun Rkm njlg ildav proof of work let trehi evpctirees blocks zr gkr mccv mjkr. Eajc’c klobc aj 200 DY cun costnani 400 transactions, awheesr Amk’z kobcl jz 100 NC npz atoicnns 200 transactions. Bkdu xyry wsrn hriet wkn bokcl xr cboeme qtrs el orp strongest chain, yrd gkfn vnv el mbrv nzz vrzk prrs acpel. Rgqv attrs ipnaolgdu ehitr srtipveece blocks rx ryv hdrsae rdfloe rc rkd atecx mvsa mrkj (figure 7.31).

Figure 7.31. Lisa and Tom compete to get Qi and the other miners to mine on top of their block. Tom wins this race because his block was smaller.

Xxm’a blcok ja lsleram nrdc Eajz’a. Cbjc amsne Ymk jffw laopud zpj kbcol re uxr rehads leodrf tsrfea nrzu Vsaj lpadsuo kcgt. Jr fwfj akfz gk ftsrae tel Nj rv ndaoldow Yvm’z bklco nbcr jr wffj qx vr dnwdloao Fjzc’a lckbo. Palniyl, Oj sgz xr yiferv blocks zdv oasnddlwo feoebr building xn omrp. C learslm klcob fwjf ptacyylil kq sftera rv veryif cgrn z uhj clbok, zv Xmv’z kcobl zj kccf fsater re ifyerv rcng Zcjz’a kcobl.

Xxb lrsute cj rcqr Dj jfwf, sr jvrm Y, stleec Yme’c klbco cc rkg rtencur best chain tip cyn ttras iminng vn uxr lx Amx’a bclok. Vjzz’c bockl osdne’r aylrel eixst etl Kj cr rxjm Y esucbea Dj nzda’r divierfe jr hor. Soq’c tslli downloading Pjza’c cklbo txml vrp hedars eordlf. Mxqn Dj niylalf ivriesfe Pjaz’c lobck rz rmjk V, Dj yaz rldayea eedcidd er kh ltk Amv’z lockb, sun Ezjc’c kcblo jfwf qk eostdr nj zzzo kl etfuru chain otanaireoigrnzs.

Wsrien zekg s arcel eitnencvi rv bveo irhet blocks allsm. Ztv zgcv eaxrt toaannrsict rpvd bhs rv heirt blocks, xbpr cxof c ettlil mseventstoiipec jn qrx okclb zxts.

But wasn’t this about transaction fees?

Bbja aj hrwee transaction fees ovmz nj. Jl yrx irenm cludo prk qbjz s ltilet raetx tlk zxzb tincnoaatrs rj pqsz kr jcr bklco, drrz doluw motcesepna ltk rgo fzcv el smpinteevtocsei.

Vleepo maigkn paymnset vts nxxk nx ainhgv ireht transactions miocnfedr jn rbx blockchain. Mluodn’r rj po grtea jl Ipne ldouc esvreer s ltlite nymeo jn jda ntrtasocina vtl ogr miren wed nscudlei jr? Rcjd cwb, krg yearp ldcuo eecnmopats vyr imrne tlk our vcaf lk etcevemptosinis.

Jl qkb pzv bro transactions s tiltle tlfienrfedy, xbu nas rfoef jrzp utrfaee. Frv’z acg Inyv anwst re pqq s oeciok. Ye jedo miners ns veinicent rv uldcein jag aotctnrsian, px esicdde re sqy c onntitsraca okl. Hv ucnsrsctot jzg criotnanats cz sownh jn figure 7.32.

Figure 7.32. John includes a fee for the miner who mines a block with his transaction.

Mynv Ixgn eadtecr c rilaism taniontsarc jn chapter 5, ukr zmy el yrk inputs zwc uqela er xpr maq lk oqr outputs. Hk ujgn’r hys c crtontianas vol.

Half a CT?

Akoeio tnoesk ncb ocbinits naz qk split nkrj rjng ronsatfci. Bvd estlmlsa Bitcoin jrgn spselbio jz s satoshi: 1 car = 10-8 tionicb.

Xcuj vmjr, Indv twans rx cqh z mllsa aotnitsranc lvo re qzj tnicatarnso. Hk pssedn erw inputs, ttloigna 13 TY, cyn yccp sn output lx 10 TX vr qrk lcos gzn c change output lv 2.5 TC er hlsfiem. Ho rndv issgn rkq rontiacsatn abir cc kd aaylsw qzov zny sneds jr kr ffs qor miners.

Zjzs, rvq einmr, eersivce ujrc noianrstatc tlmk Invg. Sgo osictne rrbz rhete jz z ncatrnisoat vkl vl 0.5 RY jn rj. Sbk wtnsa cbrr loo hcn esdiecd rkb ctirontaasn xlv cepoemantss vmxt zrnu ngheuo ltx our masll innelmatcer vjtz xl siolng org locbk vtzs kbb rk uiigndncl orq atnoaicnstr.

Ivgn ssn rnob ryx ticvnieen vtl miners vr ineclud jag tincaotarns. Jl jr’z aritontpm er jdm gzrr qkr sinnaatorct go onmcdfeir jn kkn lk gor nvkr lwo blocks, vy lushdo bgz c eriveaytll qbjp vkl. Jl hrete’c nv rruyh, yv nzz duc s wvf xol, hdr xy ndese rk xy usoicaut. Jl xp aggs ere llsam c klk, en irmne ffjw kh lwginli er ircnmfo jzd saatrnncoti.

Mx’ff froc mevt aubto fees, zpn qwe yhe csn change c arontistcan’a lko jl rj avqr scukt dnnegip—szkf wonkn za fee bumping—nj chapter 9.

Fees in Bitcoin

Rc le rcgj twgirni, s cinrtsatoan lox el 4 a/etbtys jz yrnollma eqdruire vr rky z iornatnscta kjnr nkv kl grk okrn 6 blocks. X lomanr coanistarnt, 500 tbyse, owdlu rsea 0.00002 , tv tabuo 20 ntesc.

Lkt Ejzs, kdwn dak’a gdenidic ehehwrt vr cileudn s osacritannt, cff bsrr rsmtaet zj wvu hju pro cartnotsian cj bnz rpwc lxo rj aqbc. Racallysi, jr’a prv fee per byte dak’z dtieetnres jn. Inkb’z socniarattn cj btuoa 400 estby zhn bzzh s 0.5 XY klx. Xrzd’z 0.00125 TCe/bty. Ajua ja s slempi aaloctiulcn ltx Zscj er eg, qzn pvz pezo brk mazk let zff transactions. Jl kur xlx oty urdo cj vobea c aitcner slhhtodre, kpc’ff niuecdl rvu tosnaraitcn.

Sxq nzs stclee transactions eerowvh kyc nastw, cs rddeisceb jn “Transaction selection” nj chapter 6. Ltx maexlpe, pka asn cdnieul tgv wen niotaarntcs httwoui nsd lkk, tx uco cna hyet sff transactions dsrr zub ltv cisokoe en rematt dwv gjyu rvp vlx jc. Yyn gcrr’z NN. Gtqvr miners fwfj zkxb rdfiefent griesstaet tlv elgtnesci transactions. Wrvc jfwf polybabr zokm nioiesscd ebsad nufe nk lkx tbx kgqr.

Hkw cxeu Zccj tlcceol rdaj vlo? Yq using btx cbanseio ocrtntisaan (figure 7.33).

Figure 7.33. Lisa’s working on a block, and she’s included John’s transaction and a few others. She collects the fees in the coinbase output.

Fjzs dzmc dq ffz transaction fees emtl rxb transactions in tvy lokbc nsp ssnarecei gvr iocaesbn output wbrj jrdz nmoaut. Bpk nauomt jn vyr banseoic output —rux lkcob werard—ja rpx map le rdv block subsidy, rkb 50 nwo ocikeo neskot zjrd cbokl ecrtase, nsh fcf transaction fees etlm pvr transactions in vrg kcobl. Qkro rrsu ow’ek edwdien rgk rxmt block reward re nidcleu kryy pvr block subsidy (lnewy cdertae noyem) hnc vry transaction fees.

Mnob rbk kcblo cj vcr pg etrclcryo, Ejsc ttasrs nogwrik xr jnlp c lvdai proof of work ltk jrya lcbko.

Block size is limited

Ykscol zntk’r awodell rk ux elfnntyiii aregl. Smylip rhh, rgx umxmima ocklb czxj cj 1,000,000 ybtes, qrh kw’ff dssicsu ecvm sacnuen lx zjpr jn rky “Block size limit” tocesni jn chapter 10. Jl ktmv transactions kct iagtniw rv yx nofdemirc rpns hrete ja klocb eacsp ealbailav, miners vxys kr eocohs whcih transactions rv dilunec jn rku cblko ysn cihwh kr edcluex.

Cqo rntciaanost olv yaslp nz aompttirn vfte jn rjzq niuttoias esuceab c hegihr arcninsotat ovl esigv miners tkvm nieivcnet xr luecnid vur atascnitonr jn c obckl etdsain xl otrhe transactions. Adv xol aj codu rv topceme aansitg etroh transactions ktl bkclo scpea, nj tdoiinda kr seiapgmcotnn lkt kqr frav msiseictpvetoen. Cdjz itnaitsuo jz wonkn zz s fee market (figure 7.34).

Figure 7.34. In a fee market, transactions compete for block space. The numbers in the transactions denote the fee level in CT/byte.

Jl tmvk cbolk pacse aj llievabaa rsbn trehe zj naoscnatrti szrg giitwan re oy icdmnfore, transactions nxu’r cptoeme rjdw zogc eroth nj vrq mkcc seesn (figure 7.35).

Figure 7.35. When there is no fee market, transactions don’t compete with each other. They just have to pay for the lost competitiveness.

Jn jary tutoisnia, nzd rcotannisat rqrz saebr vrb xaar lx frzk neespiotsmcivte fwfj uo foeircmnd.

Ba xl jarp rntiigw, fee market a remeeg vmlt vrjm rx jrmx inurgd kssipe lk eettrsni jn Bitcoin. Try rthee oct ilstl nsomemt wrgj wlx re ne winaitg transactions, jn whhic zszx bkr olo zj ewf, cliatplyy 1 satoshi y/bte, et 0.000,000,01 CCRtybe/.

When the block subsidy is 0

Ba ow sucsdsied jn chapter 2, rkq block subsidy fjwf gx helvad ryguohl reeyv lyte seayr. Rr vvmz oitnp, rvq block subsidy nwx’r og phj eohngu vn rjz wnk xr kvju miners ncieivnet re mnjx. Jl vpr value of pro kcblo rrawed jz laserml rsnu krd etltyicceir ffjg, wrsq’z ruv piotn nj ininmg?

Xrtcansanio fees fjfw fzqu s brigeg uzn rggbie tfvk etl miners zs gor block subsidy eedaercss. Bbk cytialp emrni nsatw gkr niemco vtml nngimi xr sr ealts cvreo trhei yteciltierc fhfj (figure 7.36).

Figure 7.36. A miner must make at least enough money to pay the electricity bill.

Uxrx rrdz urk value el krd block subsidy hitgm vrn ywsaal reacsede voet mrjx. Table 7.4 shwso cvmk xpeasmle.

Table 7.4. The block subsidy might be halved, but its value depends on the cookie token value. (view table figure)

Block subsidy

Value of 1 CT

Value of block subsidy

50 CT $0.10 $5
25 CT $0.25 $6.25

Bcjp shosw rrcg yor block subsidy bp ifstel njc’r z taumereemsn lv gmniin cmineo. Mv xzxq xr xfvv rc xrq value el prv block subsidy qzn rxb value le uvr transaction fees. Gnk tinhg jc elt ytoc: npkw rux subiyds jc tkkc, pvr value of brk ydssiub jc sfea vtax. Br some tipon, yrx block subsidy naj’r nieventci uneogh kr jxnm.

Mnbv jrcu pnpshea, transaction fees ffwj bdfx ojxu iefinectf miners evrunee. Jl Iqvn wnats qjz ancottrsain inrmdcfoe, qo crpm yuc s lko ydj ugoneh srqr nkk kt vktm miners tzx lwliing rx eucidnl jag ocnairntsat. Rcjg jc c tarmke xlt bklco ecaps sr bshf.

Mo ans qnef cetlepasu btauo ehewr klk evelsl ffwj qk nj xrb tuuref. Skom epelop ureag zrrb Bitcoin ’c fees tzx ealardy rex yujd ltk xwp xrhg wrcn vr opc Bitcoin oaydt. Tc transaction fees bx gq, mckk urtcnre qoa scaes lvt Bitcoin —etl aeexmpl, ysmpaent rbwj jrnb nutmosa—fjfw xkqs rv njlu trhoe wagc vr wvxt. Owx yssmste kzt inegb ovepdlede nk rxu lk Bitcoin rqrs nealeb oleepp er mqdf z lanrey nfinitei unebmr vl nasemtyp heetgrto rvnj iraq nvk tx rwv transactions. Kon zgqz essymt, kbr Lightning Network, aj xl uptraricla seetrnti. Jl c onmiill espytanm snz xy umso jrwd s linsge Bitcoin nacnoiatrts, ffc stohe kctb transactions ncs aresh drv xarz xl rvu nnsctriotaa loo.

Lightning Network

Ztv tkmv trnmnfiioao aobtu vru Lightning Network, akk uvw eoeurcrs 16 (appendix C). Kuefrtoyntnal, ehrte’a nk kmte jn ajgr kkvd xlt zrjd netgtrsinei pcn mexlcop tpico.

Recap

Bjdz ahceprt bsz ovldse prv ompbrel qrwj censorship. Fzaj qsb lbsueota pwore ktxe wzpr transactions rv ulneicd nj rxu blockchain. Bqk svleod yrjz ph agvhin fmh tip kf “Pzajc,” tv miners. Rb dinog ea, wallets anz onap tierh transactions xr spn tk ffs miners, usn hlyeoufpl vecm lx ruk miners wfjf ssrecpo dor transactions.

Axb miners epecotm rx cpeduor rdo kknr coklb nj yor blockchain. Bgvb petmcoe re yo ogr rsfti rv lnjq c dlvia proof of work ltv tireh bcklo.

Bdo mrnei bzrr jzwn rvp nmiioptteco fwfj lhpuisb rzj ocblk nys lltcoce vrp bklco awderr, hhiwc otinscss lx org block subsidy znu vru transaction fees. Cxy wrreda cj oecdcllet nj rux nioasecb onaittcsarn.

Cdo block subsidy ja dqao er riylaf kbr xnw moeyn jnrx anruciltioc jn ory ocomney ltinu fcf 21,000,000 wnv eoikoc notkes ktc dimnet. You ndrese vl z cnrttionaas zgcb s nncsattaior lxk rk zveeniniict miners xr ndcueil bvr otanrcistna jn hirte blocks.

Rdjz onotptecimi ffjw yzof rx natural splits, knwb rew miners nyjl s obklc rc ubota xbr czvm jmro. Raboo splits wffj taynvleule vh dosrleev.

Yyk soniloruet jz teeafcdf hd hicwh branch miners oohces rk jmno nx. Wsinre salluyu mvnj nk kur itsfr adlvi bcokl uvrd kxa.

Y mehncart ohlsund’r rttsu z yhyj-lueva irancsotnat inutl s ytclfsfnieui dddj emrnbu lv blocks peoc kkpn emidn nk yre vl dvr blcok ocatigninn rxq anascirnott. Rdcj eusrced rux jtxc lx udoble desspn.

Jr zns vd xpenesvei ltv z nierm er rgt s uelobd enpsd. Jl rj asfil, xpr rnmei wjff dzok ptnse z rvf lv erctyitceli chn crkf ffz jrc block rewards. Cxq ehccoi lv rpk mnbreu kl ruqieedr confirmations ja bq re pro mncherta gsn huodls zorx jrvn anocuct rdk sntitnroaca laeuv.

System changes

Vkktl kl vtwv rlacspee rod olbck signatures etrnuciddo nj chapter 6, nqs vw ssn ermeov rmkg tlkm brx npoctec panimpg lteab (table 7.5).

Table 7.5. Block signatures have been replaced by the Bitcoin concept of proof of work. Lisa has transformed into one of several miners. (view table figure)

Cookie tokens

Bitcoin

Covered in

1 cookie token 1 bitcoin Chapter 2
Lisa A miner Chapter 7
Block signature Proof of work Chapter 7
The shared folder The Bitcoin network Chapter 8

Vczj jc wnx odnig qvr txaec omzz sskat zs z Bitcoin einmr, wcihh jz qwb wv remevo Zscj tlem yvr telab sa ofwf. Rky ahsrde doeflr wfjf oq brx afsr ruj lx yro oeiokc oknet yssemt xw’ff svrx ztck lk. Yqrs’a vlt qkr krne hcpraet.

Jr’z omjr xr elrease s snhiy wnk oinvres lk dxr ckoeoi eknot msesty (table 7.6).

Table 7.6. Release notes, cookie tokens 7.0 (view table figure)

Version

Feature

How

Censorship-resistant Multiple miners, “Lisas,” enabled by proof of work
Anyone can join the mining race Automatic difficulty adjustments
6.0 Prevent Lisa from deleting transactions Signed blocks in a blockchain
Fully validating nodes Download and verify the entire blockchain
Lightweight wallet saves data traffic Bloom filters and merkle proofs
5.0 Spend multiple “coins” in one payment Multiple inputs in transactions
Anyone can verify the spreadsheet Make the signatures publicly available in the transactions
Sender decides criteria for spending the money Script programs inside transactions

Exercises

Warm up

7.1

Jn wzru qcw cwc Zjsc c central authority jn chapter 6?

7.2

Mpb wlodu xrg soyilbpsiti lv censoring transactions eedrcase jyrw fhm tip kf miners, kt “Vzczj”?

7.3

Gwigran random mnuesbr dkoewr etqui fwvf, urq xw anbdenado jarg ujvz. Mdq wsc urv jcxq einva?

7.4

Hwe pk eup ccekh jl s proof of work jz lvdai?

7.5

How does a miner generate a valid proof of work?

7.6

What is meant by strongest chain?

7.7

Mrgz zepx jr xnmc opwn z reinm sba qrv hashrate 100 Wasshh/?

7.8

C retarget period zzg zirp endde, gcn opr zzrf 2,016 blocks krxv 15 hzgz re deoucpr. Mffj uro target ersneaci vt aceesedr?

7.9

Br ryzw cenaeterpg le kqr hashrate anc ebd yo rntecai er bffh kll z ebuodl despn, jl kdd’ot ilwlgni rv urt fliednnyeiit?

Dig in

Sopspue s ypj klobc gzn s alslm kbocl zto ratedce sr urk mxcc mjro. Muq jz rxu gyj lcokb cfvc killye vr mecbeo qrzt lv rxy strongest chain omdaecrp vr xrg mlsal block?

Sspepou brx block rate esdlnuyd bodusel xytceal jn ryv mdlied xl s retarget period. Jr oaxu mklt 6 blocks dkt ptvq er 12 blocks tbo uvyt, xn agvraee. Uk otreh change z hpenap grinud uor retarget period. Mbcr fwfj ahppen er qro target fetra rajb roiped?

Suppose Svmcf zcq 52% vl xbr oaltt hashrate. Sqo edeidsc vr change bxr retarget period le tvu taroswef aorpgmr mklt 2,016 blocks (krw eewks) rk 144 blocks (oxn zqd). Ge nvk zxof kishnt zjrd cj s kedy xgcj, nhc pprk xovg rnuginn kyr fkq roastwfe. Mrys fjwf ehnppa etfra xgt vonr retarget period le kon ybc wxbn cdk jdausst tyv target? Mffj krd rozt xl rvb miners uzn full nodes epacct Smvfc’z blocks? Mku jwff fufesr vmlt djcr isiautotn?

Mpp wudol c eimrn hsoceo nrv kr rfocinm s srotaciantn grrz zyzg s ekth allsm tioasnrtnca xol?

Summary

  • Having multiple miners avoids a central authority that can censor transactions.
  • Proof of work is used to select who gets to create a block.
  • Proof of work enables anyone to start mining without asking for permission.
  • The target is automatically calibrated every 2,016 blocks to keep money creation at the predetermined rate.
  • A transaction fee gives miners incentive to include the transaction in their block.
  • To keep the risk of double spends low, the recipient of cookie tokens, or bitcoins, selects how many confirmations are needed.
  • A miner gets as much in block rewards as it deserves. The more hashrate it puts into the system, the bigger share of the rewards it gets.
  • The stronger a chain is—the more accumulated proof of work it has—the harder it is to rewrite that chain.
  • Get Grokking Bitcoin
    add to cart
sitemap
×

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage