Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a...

47
Experimental Insights into Smart Contracts Dr . habil. Radu State [email protected] http://wwwfr.uni.lu/snt/research/sedan

Transcript of Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a...

Page 1: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Experimental Insights into Smart Contracts

[email protected]

http://wwwfr.uni.lu/snt/research/sedan

Page 2: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

• MasterofScience,JohnsHopkinsUniversity,USA(ComputationalBiology),1998

• Ph.D,INRIA,France(NetworkSecurityandManagement),2001

• Habilitation,Université deLorraine,France,2008• SeniorResearcheratINRIA,France• ProfessorofComputerScience,TelecomNancy,

France• SeniorScientistatSnT,UniversityofLuxembourg

RaduState,SeniorResearchScientist

Page 3: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Overview

• Smartcontractsandblockchain 101• Programmingframeworksanddeployment• Differentviewpointsforlookingatsmartcontracts

• Graphmodeling• Tensormodeling• Holographicvisualizations

• Security• Conclusions

Page 4: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

NickSzabo’sdefinitionfrom1994

• “A smart contract is a computerized transaction protocol thatexecutes the terms of a contract.

• The general objectives are to satisfy common contractual conditions(such as payment terms, liens, confidentiality, and even enforcement),minimize exceptions both malicious and accidental, and minimize theneed for trusted intermediaries.

• Related economic goals include lowering fraud loss, arbitrations andenforcement costs, and other transaction costs”

Page 5: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Whatisconsensusandwhydoweneedblockchain(s)?

• StateMachineandtransactions

• Trustbydistributedanddecentralizedcomputing

• Consensusshoulddealwith• Failures• Censorship

PermissionedNonPermissionedDL

Page 6: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Encodingstateontheblockchain

• thestatelessUTXOmodel,accountbalancesareencodedintopasttransactionrecords

• accountmodel,whereaccountbalancesarekeptinstatestoragespaceontheledger.

Page 7: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Whatdoyouneedtowriteasmartcontract?

• Aprogramminglanguage inwhichtowriteyourcode• Acompilerwhichtranslatesasmartcontractintobytecode• Avirtualmachinethatexecutesthesmartcontract• Atrustedinfrastructurewhichexecutesthevirtualmachine

Page 8: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

WritingasmartcontractinGolang (HyperLedger)

• Asimpleprogramthatreceivesthreeinputnumbersa,b,xandupdateswitha=a-xandb=b+x

• Example:Ifa=10,b=7,x=4thenaftertheexecutionweget:a=6,b=11• InPythonthislookslike:

1. a=input('Enterfirstnumber:')2. b =input('Entersecondnumber:')3. x=input('Enterthirdnumber:')4. new_a=a-x5. new_b=b+x6. print('Thestatusof{0}and{1}is{4}and{5}'.format(a,b,new_a,new_b))

Page 9: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Initializingthechain…..

1. a=input('Enterfirstnumber:')2. b=input('Entersecondnumber:')

Page 10: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Initializingthechain…..

Writingdatatotheblockchain

Page 11: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Doingtwoarithmeticoperations…

Readingdatafromtheblockchain

Page 12: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Doingtwoarithmeticoperations…

new_a=a-xnew_b=b+x

print('Thestatusof{0}and{1}is{4}and{5}'.format(a,b,new_a,new_b))

Page 13: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Callingafunction….

Page 14: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Andstartingthechain….

Additionalcodenotshownbutcompleteexamplecanbefoundathttps://github.com/IBM-Blockchain/example02/blob/v2.0/chaincode/chaincode_example02.go

Page 15: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

WhatisDocker?

git clonehttps://github.com/yeasy/docker-compose-filescddocker-compose-files/hyperledgerdocker-composeup

Page 16: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Cloudreadyservices(IBMBluemix)

Page 17: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

ResearchatSEDAN@SnT onSmartContracts

• Canwemodelcomplexfinancialprocesseswithsmartcontracts?

• Howcanweanalyzedeployedsmartcontracts?• AMLusage• Eco-environmentinsights?

• Canwepredictactivitiesforsmartcontracts?

• Canwesecuredeployedsmartcontracts• Withoutchangingtheconsensusalgorithm

Page 18: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Sender ReceiverBlockchain

Database

SmartContract

Zakaah App

DistributeZakaah

Register

BuyZakaahCoins

RegisterManual

Automatic

SupportforEthereum andHyperledger

EthicalFinanceandfulltraceability

Page 19: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Canwelabelasmartcontractjustbylookingatitbytecode?

0x6060604052361561003d576000357c010000000000000000000000000000000000000000000000000000000090048063a2e620451461013d5761003d565b61013b5b600060149054906101000a900460ff1615156100605761005f610151565b5b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051809050600060405180830381858888f1935050505015610133577f23919512b2162ddc59b67a65e3b03c419d4105366f7d4a632f5d3c3bee9b1cff600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1610138565b610002565b5b565b005b346100025761014f6004805050610151565b005b6000600060006000732bd2326c993dfaef84f696526064ff22eba5b36273ffffffffffffffffffffffffffffffffffffffff166316c72721600060405160200152604051817c0100000000000000000000000000000000000000000000000000000000028152600401809050602060405180830381600087803b156100025760325a03f11561000257505050604051805190602001509350839250600060149054906101000a900460ff1615801561020c5750622595184310155b156102455760009150600090505a9150315a9050601b8183031415925082506001600060146101000a81548160ff021916908302179055505b83156102da578215610295577332be343b94f860124dc4fee278fdcbd38c102d88600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055506102d5565b733b5c1ad02d408d7752ec589be440582c79c4a527600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b610365565b82156103245773029a6b91931c768a3762ac9b2f0b25212d13d37a600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690830217905550610364565b73c0d332838f14ef42fcde1cf2518c427ddb676729600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b5b5b5050505056

Page 20: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Canwelabelasmartcontractjustbylookingatitopcode?PUSH10x60PUSH10x40MSTORECALLDATASIZEISZEROPUSH20x003dJUMPIPUSH10x00CALLDATALOAD……DDMSTOREPUSH10x40MLOADDUP2PUSH290x0100000000000000000000000000000000000000000000000000000000MULDUP2MSTOREPUSH10x04ADDDUP1SWAP1

Page 21: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Canwelabelasmartcontractjustbycommentsforums?

Page 22: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Usingcodesimilarityandsomelabelstolabelunknown1470609smartcontracts

Extracted998verifiedcontractsfrometherscan.io

Work/TokenextractionBytecodehashingusing

contexttriggeredpiecewisehash

ClusteringusingK-medoids andaffinity

propagation

Page 23: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Whatlabelsdoweget?

Page 24: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

ManualinspectionoftheclustersContract ClusterCenter

label1 label2 label3

Presale presale tokenContest contest votingWithdrawDAO dao withdrawfairandeasy dice pyramid simpleProtectTheCastle dice tokenDouble dice

andadvancedvisualization

Page 25: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Aloveforgraphs….

WemapEthereum accountstonodes

Transactionaremappedtoedges

Page 26: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Metricsongraphs

Page 27: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Long,mediumandshorthistorygraphs

Page 28: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Centrality

Page 29: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Address Comments Additional Information

0x32be343b94f860124dc4fee278fdcbd38c102d88 Poloniex HotWallet Poloniex isapurecryptotocryptoexchangebasedintheUnitedStatesandthelargesttraderofEther.

0x9e6316f44baeeee5d41a1070516cc5fa47baf227 shapeshift.io, platformthatallowsuserstoexchangedigitalcurrencieswithoutanyregistration.

0xaa1a6e3e6ef20068f7f8d8c835d2d22fd5116444 ReplaySafeSpolit transitiontothehardfork. Currency dividedbetweenETH(chainfollowedbytheFoundation)andtheETC(thecommunityefforttocontinuetheno-forkchain). Itisthe4thintermsofnumberoftransactionswithatotalof184743edges.

0x120a270bbc009644e35f0bb6ab13f95b8199c4ad: shapeshift.io, shapeshiftexchangeasanintermediateaddressfortradingBitcoinswithEther.

0xbfc39b6f805a9e40e77291aff27aee3c96915bdd Poloniex syncanyaccountsthatwouldhavelostETHduringthehardfork.

0xbb9bc244d798123fde783fcc1c72d3bb8c189413 TheDAO Initiallyraisingahugecapital and victimofanattackleading tothehardforkintheEthereumBlockchain.

0x18a672E11D637fffADccc99B152F4895Da06960 Rouleth Classicalcasinoroulette.

Page 30: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

FindingCommunitiesontheEthereum ledger

Communitiesaregroupsofnodesthatareheavilyconnectedamongthemselves.

Sparselyconnectedtotherestofthenetwork.

Page 31: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

PuttingAlgebratowork:tensormodeling

• RepresentingSmartContractsasTensors

• UseTensordecompositiontoidentifystructure

• Predictinteractionsamongcontracts

Page 32: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Presentationofthetensors• Atensorisamultidimensionalarray

• Canbeathreedimensionalcube• Orevena“cube”inhigherdimensionsuchas5,6,7,…

• Extensionofmulti-dimensionalarrayusinglinearalgebra• Differenttheoremsandmathematicaloperationsaredefinedfortensormanipulation

• Sumandmultiplicationbetweensamesizetensorcanbeachieved

• Matricization:transformationofatensorinamatrix(2dimensionstable)

• Multiplicationbetweenmatrixandtensors

• Allowsthemodelingofinteractionsbetweendifferentinputswithoutanysizelimitation

• Abilitytoperformlinearalgebraonlargescaledatatodiscoverlatentvariables

𝒳 ∈ ℝ$×&×' is athree-way tensor

Possibleslicesofathree-way tensor

Page 33: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

CANDECOMP/PARAFAC(CP)Decomposition• Introducedin1970byHarshman andCarrollandChang• Factorizationoftheinitialtensorasasumofcomponentofrank-onetensors

• Arankofathree-waytensorisdefinedastheouterproductofthreedifferentvectors

• ResolutionusingAlternatingLeastSquaresmethod• Notoocomplextoimplement• Goodcompromisebetweenspeedandresultsaccuracy

• Eachrank-onetensorisassociatedtoacommunitywithinthedataset

• Eachdimensionoftherank-onetensorscanbetreatedseparately

• Visualizationtool• Seriessimulation

• Onetensordimensionisveryoftenrelatedtotimedimensiontoobserveevolutionovertime

Three-waytensordecomposedinRcomponentsUsingCPdecomposition

Page 34: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

SmartContractsActivitiesModeling• DatasetextractedfromEthereum,• Identificationcodeforsenderandreceiversmartcontracts

• AmountofEtherexchanged• Blockheight convertedtotimeperiods

• Objective:estimateaprobabilityofEtherexchangebetweentwospecifiedsmartcontractsfordifferenttimehorizon

• Factorizationoftheinitialtensorasasumofcomponentofrank-onetensorsusingCPdecomposition

• ResolutionusingAlternatingLeastSquaresmethod• Notoocomplextoimplement• Goodcompromisebetweenspeedandresultsaccuracy• Scalabilityforhighertensordimensions

• Eachrank-onetensorisassociatedtoacommunitywithinthedataset• Eachrank-onetensorisusedasinputofalog-normal-mean-reverting

stochasticprocessforactivitiesmodelingandprobabilitiesestimation Descriptionofthedimensionsrelatedtotensordecomposition.Theresultsofthetensordecompositionaretheinputsofthe

stochasticmodel.

Page 35: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

ResultsofSmartContractsActivitiesPrediction• Objective:estimateaprobabilityofEtherexchangebetweentwosmartcontractsfora

timehorizon• Betterunderstandingoftheactivitiesbetweenthesmartcontracts• Abilitytoestimateprobabilityoffutureexchangeswhichcouldbeusedforsmartcontractspricingor

forinvestmentstrategy

• Threedifferenttimehorizonhavebeendefinedfortheexperiments• 5timesteps• 10timesteps• 26timesteps

• Forthestochasticsimulation,randomselectionon1%mostactivecontracts• Processforprobabilitiescalculation

• Parameterscalibration• Historicalcalibrationofthelog-normalparameters• HistoricalcalibrationofthemeanrevertingprocessusingEonia ratesduetoshorttimehorizonofthesimulation• EWMAhistoricalcorrelation

• 1,000,000Monte-Carlosimulation• Estimationoftheprobabilitiesusingadigitalfunction

• 𝑆) isthesimulatedprocess• 𝐾 istheamplitudeoftheEtherexchange

• Resultsdiscussion• Digitalvalue(exchangeprobability)offersappropriateguidanceforfutureEtherexchangesevenfor

longertimestephorizons

• Outcomes• AccurateprobabilitiespredictionofEtherexchangeforsmartcontracts• Openthepossibilitytoconsidersmartcontractforinvestmentstrategy• Innovativeapproach usingtensordecompositionandstochasticprocesses

AmplitudeofExchangeamountforonesendertoallreceiversamongtime

DigitalvalueinrelationwiththeseriesevolutionandEtheramplitudeexchangelevelK

RelationbetweentimepaymentmagnitudeandEtherexchangeprobability

Page 36: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Protecting Smart Contracts – BlockchainDefender

• Protectthenetworkandserviceplatform

• FlexibleSoftwareDefinedNetworkcomponentforthe

InfraChain project

• OpenSource Codedevelopment

• Supportformultiplepermissionedblockchains

– Multichain,Hyperledger

• Nomodificationofblockchain nodes andnocensoring

– Useblockchain nodesastheyare

Page 37: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

SDNnetworkandcomponents

Page 38: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Controllercomponents

Page 39: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Controllercomponents

Page 40: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Lists

Page 41: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Demo- SystemSetup

Page 42: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Demo- AuthorizedUser

Page 43: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Demo- AuthorizedUser

Page 44: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Demo- UnauthorizedUser

Page 45: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Demo- UnauthorizedUser

Page 46: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

AdditionalReadings

Page 47: Dr. habil. Radu State Radu.state@uni · Presentation of the tensors •A tensor is a multidimensional array •Can be a three dimensional cube •Or even a “cube” in higher dimension

Acknowledgments

• JeremyCharlier,PhDstudentinpartnershipprojectwiththeBCEEandco-supervided byDr.JeanHilger

• MathisSteichen,BeltranPontiveros andthepartnershipprojectwithTelindus

• NidaKhan,PhDcandidateinSnT partnershipwithEEthiq

• RobertNorvill,UniversityofBrandford.• Sofiane Lagraa,INRIAFrance