Top Banner
Byzan&ne Fault Tolerance
45

Byzan&ne Fault Tolerance

Feb 07, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Byzan&ne Fault Tolerance

Byzan&neFaultTolerance

Page 2: Byzan&ne Fault Tolerance

FaultTolerance

• Wehavesofarassumed“fail-stop”failures(e.g.,powerfailuresorsystemcrashes)

• Inotherwords,iftheserverisup,itfollowstheprotocol

• Hardenough:

• difficulttodis&nguishbetweencrashvs.networkdown

• difficulttodealwithnetworkpar&&on

Page 3: Byzan&ne Fault Tolerance

LargerClassofFailures

• Canonehandlealargerclassoffailures?

• Buggyserversthatcomputeincorrectlyratherthanstopping

• ServersthathavebeenmodifiedbyanaOacker

• ReferredtoasByzan&nefaults

Page 4: Byzan&ne Fault Tolerance

Model

• Provideareplicatedstatemachineabstrac&on

• Assume2f+1of3f+1nodesarenon-faulty

• Inotherwords,oneneeds3f+1replicastohandleffaults

• Asynchronoussystem,unreliablechannels

• Usecryptography(bothpublic-keyandsecret-keycrypto)

Page 5: Byzan&ne Fault Tolerance

GeneralIdea

• Primary-backupplusquorumsystem

• Execu&onsaresequencesofviews

• Clientssendsignedcommandstoprimaryofcurrentview

• Primaryassignssequencenumbertoclient’scommand

• Primarycommitstoaquorum

Page 6: Byzan&ne Fault Tolerance

AOacker’sPowers

• Worstcase:asingleaOackercontrolstheffaultyreplicas

• Suppliesthecodethatfaultyreplicasrun

• Knowsthecodethenon-faultyreplicasarerunning

• Knowsthefaultyreplicas’cryptokeys

• Canreadnetworkmessages

Page 7: Byzan&ne Fault Tolerance

Whatfaultscannothappen?

• Nomorethanfoutof3f+1replicascanbefaulty

• Noclientfailure--clientscanneverdoanythingbad(orrathersuchbehaviorcanbedetectedusingstandardtechniques)

• Noguessingofcryptokeysorbreakingofcryptography

Page 8: Byzan&ne Fault Tolerance

• Ques&on:inaPaxosRSMseang,whatcouldtheaOackersorbyzan&nenodesdotofoiltheprotocol?

Page 9: Byzan&ne Fault Tolerance

Whatcouldgowrong?

• Primarycouldbefaulty!

• Couldignorecommands;assignsamesequencenumbertodifferentrequests;skipsequencenumbers;etc.

• Canequivocateorliedifferentlytodifferentnodes

• Backupscouldbefaulty!

• Couldincorrectlystorecommandsforwardedbyacorrectprimary

• Faultyreplicascouldincorrectlyrespondtotheclient!

Page 10: Byzan&ne Fault Tolerance

ExampleUseScenario

• Arvind:

echoA>grade

echoB>grade

tellKaiyuan"thegradefileisready"

• Kaiyuan:

catgrade

Page 11: Byzan&ne Fault Tolerance

Design1

• client,nservers

• clientsendsrequesttoallofthem

• waitsforallntoreply

• onlyproceedsifallnagree

• whatiswrongwiththisdesign?

Page 12: Byzan&ne Fault Tolerance

Design2

• letushavereplicasvote

• 2f+1servers,assumenomorethanfarefaulty

• clientwaitsforf+1matchingreplies

• ifonlyfarefaulty,andnetworkworkseventually,mustgetthem!

• whatiswrongwithdesign2?

Page 13: Byzan&ne Fault Tolerance

IssueswithDesign2

• f+1matchingrepliesmightbefbadnodes&1good

• somaybeonlyonegoodnodegottheopera&on!

• nextopera&onalsowaitsforf+1

• mightnotincludethatonegoodnodethatsawop1

• example:S1S2S3(S1isbad)

• everyonehearsandrepliestowrite("A")

• S1andS2replytowrite("B"),butS3missesit

• clientcan'twaitforS3sinceitmaybetheonefaultyserver

• S1andS3replytoread(),butS2missesit;read()yields"A"

• result:clienttrickedintoaccep&ngout-of-datestate

Page 14: Byzan&ne Fault Tolerance

Design3

• 3f+1servers,ofwhichatmostfarefaulty

• clientwaitsfor2f+1matchingreplies

• fbadnodesplusamajorityofthegoodnodes

• soallsetsof2f+1overlapinatleastonegoodnode

• doesdesign3haveeverythingweneed?

Page 15: Byzan&ne Fault Tolerance

RefinedApproach

• letushaveaprimarytopickorderforconcurrentclientrequests

• useaquorumof2f+1outof3f+1nodes

• haveamechanismtodealwithfaultyprimary

• clientsno&fyreplicasofeachopera&on,aswellasprimary;ifnoprogress,forcechangeofprimary

• replicasexchangeinfoaboutopssentbyprimary

• replicassendresultsdirectlytoclient

Page 16: Byzan&ne Fault Tolerance

PBFT:Overview

• Normalopera&on:howtheprotocolworksintheabsenceoffailures

• Viewchanges:howtodeposeafaultyprimaryandelectanewone

• Garbagecollec&on:howtoreclaimthestorageusedtokeepvariouscer&ficates

Page 17: Byzan&ne Fault Tolerance

NormalOpera&on

• Threephases:

• Pre-prepare:assignssequencenumbertorequest

• Prepare:ensuresfault-tolerantconsistentorderingofrequestswithinviews

• Commit:ensuresfault-tolerantconsistentorderingofrequestsacrossviews

• Eachreplicamaintainsthefollowingstate:

• Servicestate

• Messagelogwithallmessagessent/received

• Integerrepresen&ngthecurrentviewnumber

Page 18: Byzan&ne Fault Tolerance

Clientissuesrequest

• o:statemachineopera&on

• t:&mestamp

• c:clientid

Page 19: Byzan&ne Fault Tolerance

Pre-prepare

• v:view

• n:sequencenumber

• d:digestofm

• m:client’srequest

Page 20: Byzan&ne Fault Tolerance

Pre-prepareReceipt

Page 21: Byzan&ne Fault Tolerance

Pre-prepareLogging

Page 22: Byzan&ne Fault Tolerance

Prepare

Page 23: Byzan&ne Fault Tolerance

Prepare

Page 24: Byzan&ne Fault Tolerance

PrepareCer&ficate

• P-cer&ficatesensuretotalorderwithinviews

• ReplicaproducesP-cer&ficate(m,v,n)iffitslogholds:

• Therequestm

• APRE-PREPAREforminviewvwithsequencenumbern

• 2fPREPAREsfromdifferentbackupsthatmatchthepre-prepare

• AP-cer&ficate(m,v,n)meansthataquorumagreeswithassigningsequencenumberntominviewv

• Notwonon-faultyreplicaswithP-cer&ficate(m1,v,n)andP-cer&ficate(m2,v,n)

Page 25: Byzan&ne Fault Tolerance

P-cer&ficatesarenotenough

• AP-cer&ficateprovesthatamajorityofcorrectreplicashasagreedonasequencenumberforaclient’srequest

• Yetthatordercouldbemodifiedbyanewleaderelectedinaviewchange

Page 26: Byzan&ne Fault Tolerance

Commit

Page 27: Byzan&ne Fault Tolerance

CommitCer&ficate

• C-cer&ficatesensuretotalorderacrossviews

• can’tmissP-cer&ficateduringaviewchange

• AreplicahasaC-cer&ficate(m,v,n)if:

• ithadaP-cer&ficate(m,v,n)

• logcontains2f+1matchingCOMMITfromdifferentreplicas(includingitself)

• ReplicaexecutesarequestaoeritgetsaC-cer&ficateforit,andhasclearedallrequestswithsmallersequencenumbers

Page 28: Byzan&ne Fault Tolerance

Reply

Page 29: Byzan&ne Fault Tolerance

BFTDiscussion

• IsPBFTprac&cal?

• Doesitaddresstheconcernsthatenterpriseuserswouldliketobeaddressed?

Page 30: Byzan&ne Fault Tolerance

Bitcoin

• adigitalcurrency

• apublicledgertopreventdouble-spending

• nocentralizedtrustormechanism<--thisishard!

Page 31: Byzan&ne Fault Tolerance

Whydigitalcurrency?

• mightmakeonlinepaymentseasier

• creditcardshaveworkedwellbutaren'tperfect

• insecure->fraud->fees,restric&ons,reversals

• recordofallyourpurchases

Page 32: Byzan&ne Fault Tolerance

Whatishardtechnically?

• forgery

• doublespending

• theo

Page 33: Byzan&ne Fault Tolerance

Idea

• Signedsequenceoftransac&ons

• thereareabunchofcoins,eachownedbysomeone

• everycoinhasasequenceoftransac&onrecords

• oneforeach&methiscoinwastransferredaspayment

• acoin'slatesttransac&onindicateswhoownsitnow

Page 34: Byzan&ne Fault Tolerance

Transac&onRecord

• pub(user1):publickeyofnewowner

• hash(prev):hashofthiscoin'sprevioustransac&onrecord

• sig(user2):signatureovertransac&onbypreviousowner'sprivatekey

• BitCoinhasmorecomplexity:amount(frac&onal),mul&plein/out,...

Page 35: Byzan&ne Fault Tolerance

Transac&onExample

1. Yownsacoin,previouslygiventoitbyX:

• T7:pub(Y),hash(T6),sig(X)

2. YbuysahamburgerfromZandpayswiththiscoin

• ZsendspublickeytoY

• Ycreatesanewtransac&onandsignsit

• T8:pub(Z),hash(T7),sig(Y)

3. Ysendstransac&onrecordtoZ

4. Zverifies:T8'ssig()correspondstoT7'spub()

5. ZgiveshamburgertoY

Page 36: Byzan&ne Fault Tolerance

DoubleSpending

• Ycreatestwotransac&onsforsamecoin:Y->Z,Y->Q

• bothwithhash(T7)

• Yshowsdifferenttransac&onstoZandQ

• bothtransac&onslookgood,includingsignaturesandhash

• nowbothZandQwillgivehamburgerstoY

Page 37: Byzan&ne Fault Tolerance

Defense

• publishlogofalltransac&onstoeveryone,insameorder

• soQknowsaboutY->Z,andwillrejectY->Q

• a"publicledger"

• ensureYcan'tun-publishatransac&on

Page 38: Byzan&ne Fault Tolerance

StrawmanSolu&on

• Assumeap2pnetwork

• Peersfloodnewtransac&onsover“overlay”

• Transac&onisacceptableonlyifmajorityofpeersthinkitisvalid

• Whataretheissueswiththisscheme?

Page 39: Byzan&ne Fault Tolerance

BitCoinBlockChain

• theblockchaincontainstransac&onsonallcoins

• manypeers,eachwithacompletecopyofthechain

• proposedtransac&onsfloodedtoallpeers

• newblocksfloodedtoallpeers

• eachblock:hash(prevblock),setoftransac&ons,nonce,currentwallclock&mestamp

• newblockabout~10minutescontainingnewxac&ons

• payeedoesn'tverifyun&lxac&onisintheblockchain

Page 40: Byzan&ne Fault Tolerance

“Mining”Blocks

• requirement:hash(block)hasNleadingzeros

• eachpeertriesnoncevaluesun&lthisworksout

• tryingonenonceisfast,butmostnonceswon'twork

• miningablocknotaspecificfixedamountofwork

• onenodecantakemonthstocreateoneblock

• butthousandsofpeersareworkingonit

• suchthatexpected&metofirsttofindisabout10minutes

• thewinnerfloodsthenewblocktoallpeers

• thereisanincen&vetomineablock—12.5bc

Page 41: Byzan&ne Fault Tolerance

Timing

• start:allpeersknow&llB5

• andareworkingonB6(tryingdifferentnonces)

• YsendsY->Ztransac&ontopeers,whichfloodit

• peersbufferthetransac&onun&lB6iscomputed

• peersthatheardY->Zincludeitinnextblock

• soeventuallyblockchainis:B5,B6,B7,whereB7includesY->Z

Page 42: Byzan&ne Fault Tolerance

DoubleSpending

• whatifYsendsoutY->ZandY->Qatthesame&me?

• nocorrectpeerwillacceptboth

• ablockwillhaveonebutnotboth

• buttherecouldbeafork:B6<-BZandB6<-BQ

Page 43: Byzan&ne Fault Tolerance

ForkedChain

• eachpeerbelieveswhicheverofBZ/BQitsawfirst

• triestocreateasuccessor

• ifmanymoresawBZthanBQ,morewillmineforBZ

• soBZsuccessorlikelytobecreatedfirst

• evenotherwiseonewillbeextendedfirstgivensignificantvarianceinminingsuccess&me

• peersalwaysswitchtominingthelongestfork,reinforcingagreement

Page 44: Byzan&ne Fault Tolerance

DoubleSpendingDefense

• waitforenoughblockstobeminted

• ifafewblockshavebeenminted,unlikelythatadifferentforkwillwin

• ifsellingahigh-valueitem,thenwaitforafewblocksbeforeshipping

• couldaOackerstartaforkfromanoldblock?

• yes--butforkmustbelongerinorderforpeerstoacceptit

• iftheaOackerhas1000sofCPUs--morethanallthehonestbitcoinpeers--thentheaOackercancreatethelongestfork

• systemworksonlyifnoen&tycontrolsamajorityofnodes

Page 45: Byzan&ne Fault Tolerance

BitCoinSummary

• Keyidea:blockchain

• Publicledgerisagreatidea

• Decentraliza&onmightbegood

• MiningisacleverwaytoavoidsybilaOacks

• Ques&on:WillBitCoinscalewell?