SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
Title: Blockchain and smart contractsWhat they are and why you should really care about ad developer
Author: @maeste, Stefano Maestri
CODEMOTION MILAN - SPECIAL EDITION
10 – 11 NOVEMBER 2017
Who is Stefano?
● A young enthusiast open source developer
● Red Hat Principal software engineer
● https://www.linkedin.com/in/maeste/
● https://twitter.com/maeste
● https://github.com/maeste/
● http://www.onchain.it/
My matching pairs game: Java & JBoss, Open Source & Red Hat,
Blockchain & Ethereum
Who is Stefano?
● A young enthusiast open source developer
● Red Hat Principal software engineer
● https://www.linkedin.com/in/maeste/
● https://twitter.com/maeste
● https://github.com/maeste/
● http://www.onchain.it/
My matching pairs game: Java & JBoss, Open Source & Red Hat,
Blockchain & Ethereum
Today’s Agenda
● Brief introduction to blockchain concepts
● Cryptocurrencies and why they have monetary value
● Smart contracts and why you should care about
● Developing smart contracts on ethereum blockchain
What is the block chain?
The Guardian: Blockchain is a digital ledger that provides a
secure way of making and recording transactions,
agreements and contracts – anything that needs to be
recorded and verified as having taken place.
Wikipedia: A blockchain is a continuously growing list of records,
called blocks, which are linked and secured using cryptography.
Each block typically contains a hash pointer as a link to a previous
block, a timestamp and transaction data. By design, blockchains
are inherently resistant to modification of the data. A blockchain
can serve as "an open, distributed ledger that can record
transactions between two parties efficiently and in a verifiable and
permanent way."
What is a blockchain...a nice bullet list
● It’s a ledger of transactions and datas
● It’s persistent, secure and unmodifiable
● It’s based on computational trust
● It’s distributed and unstoppable
● Transaction parties are anonymous, but tx are public and verifiable
● It’s transactions could be about values (cryptocurrency)
● It’s trustless about nodes and users
What is a blockchain...a nice bullet list
● It’s a ledger of transactions and datas
● It’s persistent, secure and unmodifiable
● It’s based on computational trust
● It’s distributed and unstoppable
● Transaction parties are anonymous, but tx are public and verifiable
● It’s transactions could be about values (cryptocurrency)
● It’s trustless about nodes and users
Live Demo
It’s distributed and unstoppable
It’s distributed and unstoppable
It’s distributed and unstoppable
Has those cryptocurrencies a real economic
value? And why?
In economy “intrinsic value” concept doesn’t exist at all. We give value to money
by convention, and more general anything gain value almost for 3 reasons (not
strictly needed, but true in almost cases at least)
● It’s rare
● It’s hard to reproduce
● It could be exchanged
● Someone want to buy it (law of supply and demand)
Has those cryptocurrencies a real economic
value? And why?
In economy “intrinsic value” concept doesn’t exist at all. We give value to money
by convention, and more general anything gain value almost for 3 reasons (not
strictly needed, but true in almost cases at least)
● It’s rare
● It’s hard to reproduce
● It could be exchanged
● Someone want to buy it (law of supply and demand)
1 Euro
Fontana’s paint ~ 8M Euro
~ 7K Euro Manzoni’s artist's shit: ~275K Euro
Traditional payments
Traditional payments
And isn’t ok to simply trust in a Bank?
What could happen?
Lehman Brothers…..
Traditional payments
And isn’t ok to simply trust in a Bank?
What could happen?
Lehman Brothers…..
So...what is the solution?
Grandmum solution?
So...what is the solution?
Grandmum solution?
Could be at least unpractical...
The solution is the blockchain
● It’s a ledger of transactions and datas
● It’s persistent and secure
● It’s based on computational trust
● It’s distributed and unstoppable
● Transaction parties are anonymous, but transactions are public
● It’s transactions could be about values (cryptocurrency)
● It’s trustless about nodes and users
The solution is the blockchain
● It’s a ledger of transactions and datas
● It’s persistent and secure
● It’s based on computational trust
● It’s distributed and unstoppable
● Transaction parties are anonymous, but transactions are public
● It’s transactions could be about values (cryptocurrency)
● It’s trustless about nodes and users
Am I going to transfer my money without trusting anyone?
What does trustless mean?
You are not trusting in peers of transaction or even in nodes of the network, you
are trusting in the protocol itself. In other words you are trusting blockchain and
cryptocurrency itself and not people owning them….moreover they are
anonymous…
Does it recall anything you well known and use everyday?
What does trustless mean?
You are not trusting in peers of transaction or even in nodes of the network, you
are trusting in the protocol itself. In other words you are trusting blockchain and
cryptocurrency itself and not people owning them….moreover they are
anonymous…
Does it recall anything you well known and use everyday?
What does trustless mean?
You are not trusting in peers of transaction or even in nodes of the network, you
are trusting in the protocol itself. In other words you are trusting blockchain and
cryptocurrency itself and not people owning them….moreover they are
anonymous…
Does it recall anything you well known and use everyday?
Smart Contracts
What is a smart contract?
A contract is a voluntary arrangement between two or more
parties that is enforceable by law as a binding legal
agreement
A smart contract is a computer protocol intended to facilitate,
verify, or enforce the negotiation or performance of a
contract.
Real world smart contracts
With the present implementations]
"smart contract" is
general purpose computation that takes place on a
blockchain
Smart contracts: unstoppable Dapp
● Distributed
● Can transfer money/assets
● Unmodifiable state history
Ethereum: a blockchain for smart contracts
● Every node run a built in Virtual Machine (EVM)
● It provide a compiler from high level languages to EVM
● 2 different kind of accounts:
○ Externally owned account (EOAs), controlled by
private keys
○ Contract accounts, controlled by code
Ethereum Virtual Machine
Internals
● TURING COMPLETE VM
● Stack based byte code (push,
jump)
● Memory
● Storage
● Environment variables
● Logs
● Sub-calling
High level languages
● Solidity (c-like)
● Viper (python like)
● LLL (lisp inspired)
● Bamboo (experimental
morphing language influenced
by Erlang)
Everyone compiling to EVM code
EVM code execution
● Transaction sent to a contract address
● Every full node of ethereum run the code at this address
and store the state
● Smart contract code can:
○ Could run any program (turing complete machine)
○ Read/write state
○ Call another contract
○ Send ETH to other address (both EOA and contract)
Ethereum GAS
Halting problem: determine if the program will finish running or continue to run
forever. Classic NP-hard problem
Ethereum solution: GAS, a fee per computational step
GAS is not a currency is just a unit of measurement of computational step
In Tx you have “maximum GAS” you would give to the miner and “GAS price” to
determine how much you will actually pay.
If Tx complete successfully you pay just for effective GAS used.
It the Tx would consume all GAS the TX will be revert, but you still pay for GAS
Ethereum hasn’t block size limit, but Gas Limit (6.7M currently, but voted by miners)
Solidity
● C/Java-like syntax
● Statically typed
● Support inheritance (multiple)
● Complex user defined types (struct)
● Polymorphism
● Overriding
● …..
http://solidity.readthedocs.io/en/develop/index.html#
Our development environment
● testRPC (local in memory ethereum blockchain)
● Truffle (maven-like tool to compile and deploy contract)
● A bit of javascript (npm) for some raw Dapp interface
● Metamask to inject ethereum protocol in our
html/javascript Dapp
● Intellij to edit solidity and javascript
More info: http://truffleframework.com/
SmartNotary
● The easiest contract notarizing a document
● Receiving document hash and owner name It will write them in the
blockchain state
● Giving the hash it will return the owner name
● It’s a pet project just to play with code
Talk is cheap….show me the f****ing code (Linus Torvalds)
https://github.com/onchainit/SmartNotary/tree/baseExample
SmartNotary 1.1: using EOA
We are using current EOA (from metamask) as owner.
It will give us the opportunity to play a bit with metamask
https://github.com/onchainit/SmartNotary/tree/baseExample
SmartNotary 2.0: paying for notarization
We are adding money transfer.
Basically the user will pay in ether the service of
notarization.
The ethers are stored in contract balance, and only contract
creator could withdraw them in his EOA
https://github.com/onchainit/SmartNotary/tree/pay4Notarization
Contract security - reentrancy attack
// INSECURE
mapping (address => uint) private userBalances;
function withdrawBalance() public {
uint amountToWithdraw = userBalances[msg.sender];
require(msg.sender.call.value(amountToWithdraw)());
// At this point, the caller's code is executed, and can call withdrawBalance again
userBalances[msg.sender] = 0;
}
https://consensys.github.io/smart-contract-best-practices/
Contract security - reentrancy attack
// VERY SIMPLIFIED MALICIOUS CODE (WOULD NEED CONSIDERATION ON BLOCK MAXIMUM GAS)
function() payable {
vulnerable.withDraw();
}
Contract security -reentrancy attack solution
mapping (address => uint) private userBalances;
function withdrawBalance() public {
uint amountToWithdraw = userBalances[msg.sender];
userBalances[msg.sender] = 0;
require(msg.sender.call.value(amountToWithdraw)());
// The user's balance is already 0, so future invocations won't withdraw anything
}
Or just using primitive send() instead of .call.value which limit gas to 2300 (pure
transfer)
https://consensys.github.io/smart-contract-best-practices/
SmartNotary 3.0: paying for notarization and
notarized document market
A bit more complex example
More money transfer
Blind auction
https://github.com/onchainit/SmartNotary/tree/marketplace
Who is behind ethereum?
A Very young….extremely focused guy
Who is behind ethereum?
A Very young….extremely focused guy
Don’t you recall another very young
extremely focused guy?
Who is behind ethereum?
Thanks for coming
0x41a6021A6Dc82cbB0cd7ee0E3855654D225F48C6
I’ll use ethers only for beers :)
● https://www.linkedin.com/in/maeste/
● https://twitter.com/maeste
● https://github.com/maeste/
● http://www.onchain.it/

Contenu connexe

Tendances

Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...Codemotion
 
Discovering Applications in Blockchain .edu
Discovering Applications in Blockchain .eduDiscovering Applications in Blockchain .edu
Discovering Applications in Blockchain .eduRizal Mohd Nor
 
Basic techniques in cryptography
Basic techniques in cryptographyBasic techniques in cryptography
Basic techniques in cryptographyShraddha Gupta
 
Analyzing Cryptocurrencies with Python
Analyzing Cryptocurrencies with PythonAnalyzing Cryptocurrencies with Python
Analyzing Cryptocurrencies with PythonPortia Burton
 
Definition of Cryptocurrency
Definition of CryptocurrencyDefinition of Cryptocurrency
Definition of Cryptocurrencyterihagh
 
Decentralized: Blockchain & Cryptocurrency Laws in Canada
Decentralized: Blockchain & Cryptocurrency Laws in CanadaDecentralized: Blockchain & Cryptocurrency Laws in Canada
Decentralized: Blockchain & Cryptocurrency Laws in CanadaAlexander Davis
 
Daniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's ThesisDaniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's ThesisDaniel Connelly
 
Are blockchain and crypto interchangeable terms
Are blockchain and crypto interchangeable terms Are blockchain and crypto interchangeable terms
Are blockchain and crypto interchangeable terms Blockchain Council
 
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Codemotion
 
Tutorial on Cryptography
Tutorial on CryptographyTutorial on Cryptography
Tutorial on Cryptographykenluck2001
 
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)Igalia
 
Cryptography & network security
Cryptography & network securityCryptography & network security
Cryptography & network securitysathu30
 

Tendances (15)

Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
 
Discovering Applications in Blockchain .edu
Discovering Applications in Blockchain .eduDiscovering Applications in Blockchain .edu
Discovering Applications in Blockchain .edu
 
Basic techniques in cryptography
Basic techniques in cryptographyBasic techniques in cryptography
Basic techniques in cryptography
 
Fintech Workshop
Fintech WorkshopFintech Workshop
Fintech Workshop
 
Analyzing Cryptocurrencies with Python
Analyzing Cryptocurrencies with PythonAnalyzing Cryptocurrencies with Python
Analyzing Cryptocurrencies with Python
 
Definition of Cryptocurrency
Definition of CryptocurrencyDefinition of Cryptocurrency
Definition of Cryptocurrency
 
Decentralized: Blockchain & Cryptocurrency Laws in Canada
Decentralized: Blockchain & Cryptocurrency Laws in CanadaDecentralized: Blockchain & Cryptocurrency Laws in Canada
Decentralized: Blockchain & Cryptocurrency Laws in Canada
 
Daniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's ThesisDaniel Connelly Ethereum Smart Contract Master's Thesis
Daniel Connelly Ethereum Smart Contract Master's Thesis
 
Are blockchain and crypto interchangeable terms
Are blockchain and crypto interchangeable terms Are blockchain and crypto interchangeable terms
Are blockchain and crypto interchangeable terms
 
INTRO TO BLOCKCHAINS AND CRYPTOCURRENCY
INTRO TO BLOCKCHAINS AND CRYPTOCURRENCYINTRO TO BLOCKCHAINS AND CRYPTOCURRENCY
INTRO TO BLOCKCHAINS AND CRYPTOCURRENCY
 
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
 
Tutorial on Cryptography
Tutorial on CryptographyTutorial on Cryptography
Tutorial on Cryptography
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)
BigDecimal: Avoid rounding errors on decimals in JavaScript (Node.TLV 2020)
 
Cryptography & network security
Cryptography & network securityCryptography & network security
Cryptography & network security
 

Similaire à Blockchain and smart contracts, what they are and why you should really care about as a developer

Seun - Breaking into Protocol Engineering (1).pptx
Seun - Breaking into Protocol Engineering (1).pptxSeun - Breaking into Protocol Engineering (1).pptx
Seun - Breaking into Protocol Engineering (1).pptxSeunLanLege1
 
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute BeginnersHessan Adnani
 
Introduction to Blockchains
Introduction to BlockchainsIntroduction to Blockchains
Introduction to BlockchainsKnoldus Inc.
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contractsGautam Anand
 
Distributed, immutable, secure...
Distributed, immutable, secure...Distributed, immutable, secure...
Distributed, immutable, secure...Espeo Software
 
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency app
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency appDylan Butler & Oliver Hager - Building a cross platform cryptocurrency app
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency appDevCamp Campinas
 
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...Codemotion
 
gething started - ethereum & using the geth golang client
gething started - ethereum & using the geth golang clientgething started - ethereum & using the geth golang client
gething started - ethereum & using the geth golang clientSathish VJ
 
How to run your own blockchain pilot
How to run your own blockchain pilotHow to run your own blockchain pilot
How to run your own blockchain pilotSimon Wilson
 
Whats, Whys and Hows of NFTs?
Whats, Whys and Hows of NFTs?Whats, Whys and Hows of NFTs?
Whats, Whys and Hows of NFTs?Abhinav Gupta
 
Dumb Smart Contracts (TBBUG).pdf
Dumb Smart Contracts (TBBUG).pdfDumb Smart Contracts (TBBUG).pdf
Dumb Smart Contracts (TBBUG).pdfParesh Yadav
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitTal Be'ery
 
From Crypto Kitties to non fungible token to ERC721 standard
From Crypto Kitties to non fungible token to ERC721 standardFrom Crypto Kitties to non fungible token to ERC721 standard
From Crypto Kitties to non fungible token to ERC721 standardmaeste
 
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...Codemotion
 
Blockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptxBlockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptxsaiproject
 

Similaire à Blockchain and smart contracts, what they are and why you should really care about as a developer (20)

Seun - Breaking into Protocol Engineering (1).pptx
Seun - Breaking into Protocol Engineering (1).pptxSeun - Breaking into Protocol Engineering (1).pptx
Seun - Breaking into Protocol Engineering (1).pptx
 
Blockchain and Cryptocurrency for Dummies
Blockchain and Cryptocurrency for DummiesBlockchain and Cryptocurrency for Dummies
Blockchain and Cryptocurrency for Dummies
 
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners
[Workshop] Getting Started with Cryptos, NFTs & Web 3.0 for Absolute Beginners
 
Introduction to Blockchains
Introduction to BlockchainsIntroduction to Blockchains
Introduction to Blockchains
 
Programming Decentralized Application
Programming Decentralized ApplicationProgramming Decentralized Application
Programming Decentralized Application
 
Ethereum
EthereumEthereum
Ethereum
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
 
Distributed, immutable, secure...
Distributed, immutable, secure...Distributed, immutable, secure...
Distributed, immutable, secure...
 
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency app
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency appDylan Butler & Oliver Hager - Building a cross platform cryptocurrency app
Dylan Butler & Oliver Hager - Building a cross platform cryptocurrency app
 
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...
Stefano Maestri - Why Ethereum and other blockchains are going to Proof of St...
 
gething started - ethereum & using the geth golang client
gething started - ethereum & using the geth golang clientgething started - ethereum & using the geth golang client
gething started - ethereum & using the geth golang client
 
How to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contractHow to design, code, deploy and execute a smart contract
How to design, code, deploy and execute a smart contract
 
Ethereum
EthereumEthereum
Ethereum
 
How to run your own blockchain pilot
How to run your own blockchain pilotHow to run your own blockchain pilot
How to run your own blockchain pilot
 
Whats, Whys and Hows of NFTs?
Whats, Whys and Hows of NFTs?Whats, Whys and Hows of NFTs?
Whats, Whys and Hows of NFTs?
 
Dumb Smart Contracts (TBBUG).pdf
Dumb Smart Contracts (TBBUG).pdfDumb Smart Contracts (TBBUG).pdf
Dumb Smart Contracts (TBBUG).pdf
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
 
From Crypto Kitties to non fungible token to ERC721 standard
From Crypto Kitties to non fungible token to ERC721 standardFrom Crypto Kitties to non fungible token to ERC721 standard
From Crypto Kitties to non fungible token to ERC721 standard
 
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...
Webinar: From Crypto Kitties to non fungible token to ERC721 standard - Stefa...
 
Blockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptxBlockchain Experiments 1-11.pptx
Blockchain Experiments 1-11.pptx
 

Dernier

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Blockchain and smart contracts, what they are and why you should really care about as a developer

  • 1. Title: Blockchain and smart contractsWhat they are and why you should really care about ad developer Author: @maeste, Stefano Maestri CODEMOTION MILAN - SPECIAL EDITION 10 – 11 NOVEMBER 2017
  • 2. Who is Stefano? ● A young enthusiast open source developer ● Red Hat Principal software engineer ● https://www.linkedin.com/in/maeste/ ● https://twitter.com/maeste ● https://github.com/maeste/ ● http://www.onchain.it/ My matching pairs game: Java & JBoss, Open Source & Red Hat, Blockchain & Ethereum
  • 3. Who is Stefano? ● A young enthusiast open source developer ● Red Hat Principal software engineer ● https://www.linkedin.com/in/maeste/ ● https://twitter.com/maeste ● https://github.com/maeste/ ● http://www.onchain.it/ My matching pairs game: Java & JBoss, Open Source & Red Hat, Blockchain & Ethereum
  • 4. Today’s Agenda ● Brief introduction to blockchain concepts ● Cryptocurrencies and why they have monetary value ● Smart contracts and why you should care about ● Developing smart contracts on ethereum blockchain
  • 5. What is the block chain? The Guardian: Blockchain is a digital ledger that provides a secure way of making and recording transactions, agreements and contracts – anything that needs to be recorded and verified as having taken place. Wikipedia: A blockchain is a continuously growing list of records, called blocks, which are linked and secured using cryptography. Each block typically contains a hash pointer as a link to a previous block, a timestamp and transaction data. By design, blockchains are inherently resistant to modification of the data. A blockchain can serve as "an open, distributed ledger that can record transactions between two parties efficiently and in a verifiable and permanent way."
  • 6. What is a blockchain...a nice bullet list ● It’s a ledger of transactions and datas ● It’s persistent, secure and unmodifiable ● It’s based on computational trust ● It’s distributed and unstoppable ● Transaction parties are anonymous, but tx are public and verifiable ● It’s transactions could be about values (cryptocurrency) ● It’s trustless about nodes and users
  • 7. What is a blockchain...a nice bullet list ● It’s a ledger of transactions and datas ● It’s persistent, secure and unmodifiable ● It’s based on computational trust ● It’s distributed and unstoppable ● Transaction parties are anonymous, but tx are public and verifiable ● It’s transactions could be about values (cryptocurrency) ● It’s trustless about nodes and users Live Demo
  • 10. It’s distributed and unstoppable
  • 11. Has those cryptocurrencies a real economic value? And why? In economy “intrinsic value” concept doesn’t exist at all. We give value to money by convention, and more general anything gain value almost for 3 reasons (not strictly needed, but true in almost cases at least) ● It’s rare ● It’s hard to reproduce ● It could be exchanged ● Someone want to buy it (law of supply and demand)
  • 12. Has those cryptocurrencies a real economic value? And why? In economy “intrinsic value” concept doesn’t exist at all. We give value to money by convention, and more general anything gain value almost for 3 reasons (not strictly needed, but true in almost cases at least) ● It’s rare ● It’s hard to reproduce ● It could be exchanged ● Someone want to buy it (law of supply and demand) 1 Euro Fontana’s paint ~ 8M Euro ~ 7K Euro Manzoni’s artist's shit: ~275K Euro
  • 14. Traditional payments And isn’t ok to simply trust in a Bank? What could happen? Lehman Brothers…..
  • 15. Traditional payments And isn’t ok to simply trust in a Bank? What could happen? Lehman Brothers…..
  • 16. So...what is the solution? Grandmum solution?
  • 17. So...what is the solution? Grandmum solution? Could be at least unpractical...
  • 18. The solution is the blockchain ● It’s a ledger of transactions and datas ● It’s persistent and secure ● It’s based on computational trust ● It’s distributed and unstoppable ● Transaction parties are anonymous, but transactions are public ● It’s transactions could be about values (cryptocurrency) ● It’s trustless about nodes and users
  • 19. The solution is the blockchain ● It’s a ledger of transactions and datas ● It’s persistent and secure ● It’s based on computational trust ● It’s distributed and unstoppable ● Transaction parties are anonymous, but transactions are public ● It’s transactions could be about values (cryptocurrency) ● It’s trustless about nodes and users Am I going to transfer my money without trusting anyone?
  • 20. What does trustless mean? You are not trusting in peers of transaction or even in nodes of the network, you are trusting in the protocol itself. In other words you are trusting blockchain and cryptocurrency itself and not people owning them….moreover they are anonymous… Does it recall anything you well known and use everyday?
  • 21. What does trustless mean? You are not trusting in peers of transaction or even in nodes of the network, you are trusting in the protocol itself. In other words you are trusting blockchain and cryptocurrency itself and not people owning them….moreover they are anonymous… Does it recall anything you well known and use everyday?
  • 22. What does trustless mean? You are not trusting in peers of transaction or even in nodes of the network, you are trusting in the protocol itself. In other words you are trusting blockchain and cryptocurrency itself and not people owning them….moreover they are anonymous… Does it recall anything you well known and use everyday?
  • 24. What is a smart contract? A contract is a voluntary arrangement between two or more parties that is enforceable by law as a binding legal agreement A smart contract is a computer protocol intended to facilitate, verify, or enforce the negotiation or performance of a contract.
  • 25. Real world smart contracts With the present implementations] "smart contract" is general purpose computation that takes place on a blockchain
  • 26. Smart contracts: unstoppable Dapp ● Distributed ● Can transfer money/assets ● Unmodifiable state history
  • 27. Ethereum: a blockchain for smart contracts ● Every node run a built in Virtual Machine (EVM) ● It provide a compiler from high level languages to EVM ● 2 different kind of accounts: ○ Externally owned account (EOAs), controlled by private keys ○ Contract accounts, controlled by code
  • 28. Ethereum Virtual Machine Internals ● TURING COMPLETE VM ● Stack based byte code (push, jump) ● Memory ● Storage ● Environment variables ● Logs ● Sub-calling High level languages ● Solidity (c-like) ● Viper (python like) ● LLL (lisp inspired) ● Bamboo (experimental morphing language influenced by Erlang) Everyone compiling to EVM code
  • 29. EVM code execution ● Transaction sent to a contract address ● Every full node of ethereum run the code at this address and store the state ● Smart contract code can: ○ Could run any program (turing complete machine) ○ Read/write state ○ Call another contract ○ Send ETH to other address (both EOA and contract)
  • 30. Ethereum GAS Halting problem: determine if the program will finish running or continue to run forever. Classic NP-hard problem Ethereum solution: GAS, a fee per computational step GAS is not a currency is just a unit of measurement of computational step In Tx you have “maximum GAS” you would give to the miner and “GAS price” to determine how much you will actually pay. If Tx complete successfully you pay just for effective GAS used. It the Tx would consume all GAS the TX will be revert, but you still pay for GAS Ethereum hasn’t block size limit, but Gas Limit (6.7M currently, but voted by miners)
  • 31. Solidity ● C/Java-like syntax ● Statically typed ● Support inheritance (multiple) ● Complex user defined types (struct) ● Polymorphism ● Overriding ● ….. http://solidity.readthedocs.io/en/develop/index.html#
  • 32. Our development environment ● testRPC (local in memory ethereum blockchain) ● Truffle (maven-like tool to compile and deploy contract) ● A bit of javascript (npm) for some raw Dapp interface ● Metamask to inject ethereum protocol in our html/javascript Dapp ● Intellij to edit solidity and javascript More info: http://truffleframework.com/
  • 33. SmartNotary ● The easiest contract notarizing a document ● Receiving document hash and owner name It will write them in the blockchain state ● Giving the hash it will return the owner name ● It’s a pet project just to play with code Talk is cheap….show me the f****ing code (Linus Torvalds) https://github.com/onchainit/SmartNotary/tree/baseExample
  • 34. SmartNotary 1.1: using EOA We are using current EOA (from metamask) as owner. It will give us the opportunity to play a bit with metamask https://github.com/onchainit/SmartNotary/tree/baseExample
  • 35. SmartNotary 2.0: paying for notarization We are adding money transfer. Basically the user will pay in ether the service of notarization. The ethers are stored in contract balance, and only contract creator could withdraw them in his EOA https://github.com/onchainit/SmartNotary/tree/pay4Notarization
  • 36. Contract security - reentrancy attack // INSECURE mapping (address => uint) private userBalances; function withdrawBalance() public { uint amountToWithdraw = userBalances[msg.sender]; require(msg.sender.call.value(amountToWithdraw)()); // At this point, the caller's code is executed, and can call withdrawBalance again userBalances[msg.sender] = 0; } https://consensys.github.io/smart-contract-best-practices/
  • 37. Contract security - reentrancy attack // VERY SIMPLIFIED MALICIOUS CODE (WOULD NEED CONSIDERATION ON BLOCK MAXIMUM GAS) function() payable { vulnerable.withDraw(); }
  • 38. Contract security -reentrancy attack solution mapping (address => uint) private userBalances; function withdrawBalance() public { uint amountToWithdraw = userBalances[msg.sender]; userBalances[msg.sender] = 0; require(msg.sender.call.value(amountToWithdraw)()); // The user's balance is already 0, so future invocations won't withdraw anything } Or just using primitive send() instead of .call.value which limit gas to 2300 (pure transfer) https://consensys.github.io/smart-contract-best-practices/
  • 39. SmartNotary 3.0: paying for notarization and notarized document market A bit more complex example More money transfer Blind auction https://github.com/onchainit/SmartNotary/tree/marketplace
  • 40. Who is behind ethereum? A Very young….extremely focused guy
  • 41. Who is behind ethereum? A Very young….extremely focused guy Don’t you recall another very young extremely focused guy?
  • 42. Who is behind ethereum?
  • 43. Thanks for coming 0x41a6021A6Dc82cbB0cd7ee0E3855654D225F48C6 I’ll use ethers only for beers :) ● https://www.linkedin.com/in/maeste/ ● https://twitter.com/maeste ● https://github.com/maeste/ ● http://www.onchain.it/