SlideShare une entreprise Scribd logo
1  sur  30
Developer Weekly #1
LetsBuildEOS | Blockchain Developer Community
Best practices to build secure
smart contracts
August 2, 2018
Gautam ANAND
me@gautamanand.i
n
About Gautam ANAND
“Non-Blockchain Tech (Microservices/AI)”
● 5 Years of FullStack Software Development
● Software Architecture Design (Microservices) - Build & Scale
● JavaScript ES6 (Node.js), C++ (EOSIO Smart Contracts) and Python
(Scikit-Learn & TensorFlow)
● DevOps (Docker/Kubernetes/Serverless)
● Databases (Mongo, Redis and PostgresQL)
● Machine Learning Models to Cloud Agnostic APIs
● Code Reviews
About Gautam ANAND
“Blockchain Tech”
● Won 3 Blockchain Hackathons in June 2018 (Hong Kong & Singapore)
● Invited to compete for EOS Hackathon Finals (~500K USD +
Funding/EOSVC)
● Built two EOSIO based projects (SmartCitySteriods & ReliefChain),
continuing working on them.
● Part of Global EOS Community.
● Participating in IBM CallforCode Hackathon (ReliefChain, ~200K USD
Cash Prize)
● Mentoring “Advanced Blockchain Programming Fellowship” at
Blockfellows.io (Solidity Programming)
The Blockchain Ecosystem
Developers
(15%)
Investors
(40%)
Speculators (45%)
(not users)
Blockchain
The Crisis Situation
“You can run a blockchain company without a product,
just need to have a good ICO for your cryptocurrency”
● Speculators are not “Users” (Let's agree, they are in for the hype)
● Users help build profitable businesses
● Speculators help build profitable cryptocurrencies
● Startups misuse ICO (Initial Coin Offerings) to raise funds during seed
rounds without delivering a proof-of-concept. Beware of “Scam projects”
Now this trend is moving towards building “Sustainable Profitable
Products”, but do we have the technology to do?
About Blockchain Technology
How developers see it?
● Decentralized Database running on millions of computer
● Public chain (You don’t the location); Private Chain (Your defined
network)
● Data entry is one way i.e. NO UPDATE and NO Delete. Only Create and
READ is allowed.
In nutshell,
1. Data (Transactions) is immutable
2. Network as a secure model
About Blockchain Technology
“Bitcoin vs Ethereum vs EOSIO”
● Blockchain 1.0 - Bitcoin
● Blockchain 2.0 - ETHEREUM
● Blockchain 3.0 – EOSIO and more
https://eos.io
About Blockchain Technology
“Bitcoin vs Ethereum vs EOSIO”
● Block Time per request:
Bitcoin (600K milliseconds) vs ETH (15K milliseconds) vs EOSIO (500 milliseconds)
● Transactions per Second:
Bitcoin (7 tps) vs ETH (50 tps) vs EOSIO (>3000 tps, July 2018)
● Transactions Fee:
Bitcoin (~1 USD) vs ETH (~5.5 USD) vs EOSIO (Free)
Block time and tps metrics reference: https://bitinfocharts.com/comparison/bitcoin-confirmationtime.html
How transactions are free?: https://bytemaster.github.io/article/2016/02/10/How-to-build-a-decentralized-application-without-fees/
About Blockchain Technology
“Building Payment Gateway on Public Chain”
● Average 6 steps for any payment gateway backend request
Bitcoin (~60 mins, 1.38 USD)
ETH (~1.5 mins, 36 USD)
EOSIO (~ 3 seconds, 0 USD), this may be competitive with centralized
payment solutions such as VISA/Mastercard etc?
For the very first time, blockchain solutions can be as good as regular
centralized solutions, maybe profitable.
Security
In
Blockchain
● Security Mindset
● 3 Solidity Code Vulnerabilities
● 5 Attack Scenarios
● 4 Design Patterns
● 2 Major Hacks (~100 million
USD)
Your
Security
Mindset
● Centralised: Database
(server) is hidden behind a
client (mobile app, browser
etc).
● Decentralised: Blockchain
database (server) is public and
exposed to all vulnerabilities
you can ever imagine.
3 Solidity Code Vulnerabilities
Integer
Underflow ● Solidity can handle 256 bit
numbers
● Underflow: Token holder has
100 tokens but attempts to
spend 101
Bad pattern:
https://ethfiddle.com/IGJ2w0vPsX
Good pattern:
https://github.com/OpenZeppelin/op
enzeppelin-
solidity/blob/master/contracts/math/
SafeMath.sol
Protect
your
Functions
● Public: Anyone can access it.
● External: Other smart
contracts can access it.
● If anyone can execute your
functions from public, they can
steal all your tokens. Use
Private or Internal functions.
Example: https://ethfiddle.com/1q-
YzAPV9W
Fallbacks &
DelegateCALL
● Fallback: Every smart contract
can have exactly one unnamed
function. This will execute if
none functions are found. It
only has msg.data to retrieve
any payload.
● DelegatedCALL: It is identical
to a message call (internal
transaction) apart from the fact
that the code at target address
is executed in the context of
the calling contract and
msg.sender and msg.value do
not change their values
Example:
https://ethfiddle.com/G3W7FEdrWj
5 Attack Scenarios
Parity Attack
● Contract A has a public
function titled “myproject” that
implements DelegatedCALL. It
holds all 100k Tokens.
● Contract B is a hacker exploit,
that tries to call
ContractA.myproject(). Since
this is public authority, contract
B steals all the tokens.
DAO Attack
(Decentralised
Autonomous
Organisation)
● Check my account balance in
the starting ONCE.
● Second time onwards, ignore
balance check and initiate
transfer request.
# Fix
- Reduce senders balance
before making transfer.
- require(msg.sender.transfer(_value))
Example:
https://ethfiddle.com/VDH-hqXQZ_
SelfDestruct
● Mechanism to delete smart
contract
● Contract’s fund is sent to the
target address
● Accidently create scenarios
that it can be triggered
Example:
https://ethfiddle.com/dmsDZVYcBX
Denial of
Service
● Take ownership of the smart
contract by sending enough
ethers to insecure contract.
● The attacker knows the
transaction will fail and will be
refunded. This will block the
service.
Example:
https://ethfiddle.com/jJNl3ILO-Z
Shortest
Address
Attack
● Attackers abuse ERC-20
transfer function to withdraw a
large amount thatn he/she is
allowed to.
● Culprit: The input address has
no trailing zeros, the exchange
doesn’t do input validation. The
EVM corrects this and the
balance is increased.
● Exchanges are the biggest
victims here
Details:
https://vessenes.com/the-erc20-
short-address-attack-explained/
4 Design Patterns
Avoid
External
Calls
● Avoid a call from one contract
to another untrusted contract or
account.
● delegatecall, callcode, call
● Types of attacks: The Dao
hack, The Parity multisignature
wallet hack
● Use .send() and .transfer() over
.call.value()
Use
Assert(),
Require() &
Revert()
● require(condition) for input
validation
● assert(condition) for internal
error check
● revert() returns unused gas
● throw() will continue to
consume all gas
Test
Driven
development
● Smart contract once deployed
cannot be improved. No
version control.
● Do Unit Testing
● Do Test coverage
● Simulate on testnet.
Offline contracts
shouldn’t be
paid
● Contract A sends to Contract
B, 1000 Tokens.
● Contract B is dead
● Contract A lost money
2 Major Hacks (~100 million
USD)
ETHEREUM
DAO was
hacked for
70 million USD
(ETH Classic is born)
https://www.coindesk.com/underst
anding-dao-hack-journalists/
● Attacker was able to ask the
smart contract (DAO) to give
the ether back multiple times
before the smart contract could
update its own balance.
● Ethereum Classic was forked
and all transactions before
attack were reverted.
Parity Client
vulnerability
costed
30 million USD
(Check this is real?)
The code that did this:
https://github.com/paritytech/parity
-ethereum/pull/6102/files
● Parity is a ETH Client used by
many people. You can call it
from smart contracts.
● Three ICO (Edgeless casino,
Swarm City and aeternity) were
using parity client v.15, to
check balance for raised funds.
● The function in wallet smart
contract was Public
DelegatedCALL, that let
attackers steal the tokens.
Thanks, Stay in touch!
Telegram Linkedin

Contenu connexe

Tendances

Bitcoin, Blockchain and the Crypto Contracts - Part 2
Bitcoin, Blockchain and the Crypto Contracts - Part 2Bitcoin, Blockchain and the Crypto Contracts - Part 2
Bitcoin, Blockchain and the Crypto Contracts - Part 2Prithwis Mukerjee
 
Block chain by harsh biltu agarwal
Block chain by harsh biltu agarwalBlock chain by harsh biltu agarwal
Block chain by harsh biltu agarwalN V Jagadeesh Kumar
 
The Blockchain and JavaScript
The Blockchain and JavaScriptThe Blockchain and JavaScript
The Blockchain and JavaScriptPortia Burton
 
Boolberry reduces blockchain bloat
Boolberry reduces blockchain bloatBoolberry reduces blockchain bloat
Boolberry reduces blockchain bloatboolberry
 
Tutorial blockchain technical overview-ss
Tutorial blockchain technical overview-ssTutorial blockchain technical overview-ss
Tutorial blockchain technical overview-ssHoward Anglin
 
Block Chain Technology Report
Block Chain Technology ReportBlock Chain Technology Report
Block Chain Technology ReportDeveshKumar221
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to EthereumTerek Judi
 
Bitcoin, Blockchain and Crypto Contracts - Part 3
Bitcoin, Blockchain and Crypto Contracts - Part 3Bitcoin, Blockchain and Crypto Contracts - Part 3
Bitcoin, Blockchain and Crypto Contracts - Part 3Prithwis Mukerjee
 
Introduction to Blockchain Development
Introduction to Blockchain DevelopmentIntroduction to Blockchain Development
Introduction to Blockchain DevelopmentLightstreams
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchainsubbul
 
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind CryptocurrenciesPaperchain
 
Blockchain Programming
Blockchain ProgrammingBlockchain Programming
Blockchain ProgrammingRhea Myers
 
Blockchain Technology
Blockchain TechnologyBlockchain Technology
Blockchain TechnologyPalakGulati10
 

Tendances (20)

Blockchain
BlockchainBlockchain
Blockchain
 
Bitcoin, Blockchain and the Crypto Contracts - Part 2
Bitcoin, Blockchain and the Crypto Contracts - Part 2Bitcoin, Blockchain and the Crypto Contracts - Part 2
Bitcoin, Blockchain and the Crypto Contracts - Part 2
 
Block chain by harsh biltu agarwal
Block chain by harsh biltu agarwalBlock chain by harsh biltu agarwal
Block chain by harsh biltu agarwal
 
The Blockchain and JavaScript
The Blockchain and JavaScriptThe Blockchain and JavaScript
The Blockchain and JavaScript
 
Boolberry reduces blockchain bloat
Boolberry reduces blockchain bloatBoolberry reduces blockchain bloat
Boolberry reduces blockchain bloat
 
Tutorial blockchain technical overview-ss
Tutorial blockchain technical overview-ssTutorial blockchain technical overview-ss
Tutorial blockchain technical overview-ss
 
Block Chain Technology Report
Block Chain Technology ReportBlock Chain Technology Report
Block Chain Technology Report
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to Ethereum
 
BitCoin Protocol
BitCoin ProtocolBitCoin Protocol
BitCoin Protocol
 
Bitcoin, Blockchain and Crypto Contracts - Part 3
Bitcoin, Blockchain and Crypto Contracts - Part 3Bitcoin, Blockchain and Crypto Contracts - Part 3
Bitcoin, Blockchain and Crypto Contracts - Part 3
 
Introduction to Blockchain Development
Introduction to Blockchain DevelopmentIntroduction to Blockchain Development
Introduction to Blockchain Development
 
Ethereum Intro
Ethereum IntroEthereum Intro
Ethereum Intro
 
Introduction to Blockchain
Introduction to BlockchainIntroduction to Blockchain
Introduction to Blockchain
 
Blockchain Corporate Style
Blockchain Corporate StyleBlockchain Corporate Style
Blockchain Corporate Style
 
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
 
Blockchain Programming
Blockchain ProgrammingBlockchain Programming
Blockchain Programming
 
BLOCKCHAIN TECHNOLOGY
BLOCKCHAIN TECHNOLOGYBLOCKCHAIN TECHNOLOGY
BLOCKCHAIN TECHNOLOGY
 
Build your first blockchain
Build your first blockchainBuild your first blockchain
Build your first blockchain
 
Blockchain Technology
Blockchain TechnologyBlockchain Technology
Blockchain Technology
 
Bitcoins Math
Bitcoins MathBitcoins Math
Bitcoins Math
 

Similaire à Best practices to build secure smart contracts

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
 
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
 
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
 
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
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroTal Shmueli
 
Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currencyPeter Lawrey
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchainBellaj Badr
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts ArcBlock
 
Bitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the HoodBitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the HoodGalin Dinkov
 
Blockchain Autopsies - Analyzing Ethereum Smart Contract Deaths
Blockchain Autopsies - Analyzing Ethereum Smart Contract DeathsBlockchain Autopsies - Analyzing Ethereum Smart Contract Deaths
Blockchain Autopsies - Analyzing Ethereum Smart Contract DeathsPriyanka Aash
 
Blockchain Development
Blockchain DevelopmentBlockchain Development
Blockchain Developmentpreetikumara
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.jsFelix Crisan
 
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)Alex Chepurnoy
 
Fluent destry saul
Fluent destry saulFluent destry saul
Fluent destry saulDestry Saul
 
Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in SolidityFelix Crisan
 
Intro to Blockchain Slides
Intro to Blockchain SlidesIntro to Blockchain Slides
Intro to Blockchain SlidesShannon Wells
 

Similaire à Best practices to build secure smart contracts (20)

Ethereum
EthereumEthereum
Ethereum
 
Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum) Ethereum-Cryptocurrency (All about Ethereum)
Ethereum-Cryptocurrency (All about Ethereum)
 
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
 
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
 
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
 
Programming Decentralized Application
Programming Decentralized ApplicationProgramming Decentralized Application
Programming Decentralized Application
 
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...
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies Intro
 
Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currency
 
Ergo Hong Kong meetup
Ergo Hong Kong meetupErgo Hong Kong meetup
Ergo Hong Kong meetup
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchain
 
Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts Introduction to Ethereum Smart Contracts
Introduction to Ethereum Smart Contracts
 
Bitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the HoodBitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the Hood
 
Blockchain Autopsies - Analyzing Ethereum Smart Contract Deaths
Blockchain Autopsies - Analyzing Ethereum Smart Contract DeathsBlockchain Autopsies - Analyzing Ethereum Smart Contract Deaths
Blockchain Autopsies - Analyzing Ethereum Smart Contract Deaths
 
Blockchain Development
Blockchain DevelopmentBlockchain Development
Blockchain Development
 
Smart contracts using web3.js
Smart contracts using web3.jsSmart contracts using web3.js
Smart contracts using web3.js
 
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)
Blockchain For Developers (Talk at Innopolis Blockchain Hackathon 2016)
 
Fluent destry saul
Fluent destry saulFluent destry saul
Fluent destry saul
 
Smart contracts in Solidity
Smart contracts in SoliditySmart contracts in Solidity
Smart contracts in Solidity
 
Intro to Blockchain Slides
Intro to Blockchain SlidesIntro to Blockchain Slides
Intro to Blockchain Slides
 

Dernier

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Dernier (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Best practices to build secure smart contracts

  • 1. Developer Weekly #1 LetsBuildEOS | Blockchain Developer Community Best practices to build secure smart contracts August 2, 2018 Gautam ANAND me@gautamanand.i n
  • 2. About Gautam ANAND “Non-Blockchain Tech (Microservices/AI)” ● 5 Years of FullStack Software Development ● Software Architecture Design (Microservices) - Build & Scale ● JavaScript ES6 (Node.js), C++ (EOSIO Smart Contracts) and Python (Scikit-Learn & TensorFlow) ● DevOps (Docker/Kubernetes/Serverless) ● Databases (Mongo, Redis and PostgresQL) ● Machine Learning Models to Cloud Agnostic APIs ● Code Reviews
  • 3. About Gautam ANAND “Blockchain Tech” ● Won 3 Blockchain Hackathons in June 2018 (Hong Kong & Singapore) ● Invited to compete for EOS Hackathon Finals (~500K USD + Funding/EOSVC) ● Built two EOSIO based projects (SmartCitySteriods & ReliefChain), continuing working on them. ● Part of Global EOS Community. ● Participating in IBM CallforCode Hackathon (ReliefChain, ~200K USD Cash Prize) ● Mentoring “Advanced Blockchain Programming Fellowship” at Blockfellows.io (Solidity Programming)
  • 5. The Crisis Situation “You can run a blockchain company without a product, just need to have a good ICO for your cryptocurrency” ● Speculators are not “Users” (Let's agree, they are in for the hype) ● Users help build profitable businesses ● Speculators help build profitable cryptocurrencies ● Startups misuse ICO (Initial Coin Offerings) to raise funds during seed rounds without delivering a proof-of-concept. Beware of “Scam projects” Now this trend is moving towards building “Sustainable Profitable Products”, but do we have the technology to do?
  • 6. About Blockchain Technology How developers see it? ● Decentralized Database running on millions of computer ● Public chain (You don’t the location); Private Chain (Your defined network) ● Data entry is one way i.e. NO UPDATE and NO Delete. Only Create and READ is allowed. In nutshell, 1. Data (Transactions) is immutable 2. Network as a secure model
  • 7. About Blockchain Technology “Bitcoin vs Ethereum vs EOSIO” ● Blockchain 1.0 - Bitcoin ● Blockchain 2.0 - ETHEREUM ● Blockchain 3.0 – EOSIO and more https://eos.io
  • 8. About Blockchain Technology “Bitcoin vs Ethereum vs EOSIO” ● Block Time per request: Bitcoin (600K milliseconds) vs ETH (15K milliseconds) vs EOSIO (500 milliseconds) ● Transactions per Second: Bitcoin (7 tps) vs ETH (50 tps) vs EOSIO (>3000 tps, July 2018) ● Transactions Fee: Bitcoin (~1 USD) vs ETH (~5.5 USD) vs EOSIO (Free) Block time and tps metrics reference: https://bitinfocharts.com/comparison/bitcoin-confirmationtime.html How transactions are free?: https://bytemaster.github.io/article/2016/02/10/How-to-build-a-decentralized-application-without-fees/
  • 9. About Blockchain Technology “Building Payment Gateway on Public Chain” ● Average 6 steps for any payment gateway backend request Bitcoin (~60 mins, 1.38 USD) ETH (~1.5 mins, 36 USD) EOSIO (~ 3 seconds, 0 USD), this may be competitive with centralized payment solutions such as VISA/Mastercard etc? For the very first time, blockchain solutions can be as good as regular centralized solutions, maybe profitable.
  • 10. Security In Blockchain ● Security Mindset ● 3 Solidity Code Vulnerabilities ● 5 Attack Scenarios ● 4 Design Patterns ● 2 Major Hacks (~100 million USD)
  • 11. Your Security Mindset ● Centralised: Database (server) is hidden behind a client (mobile app, browser etc). ● Decentralised: Blockchain database (server) is public and exposed to all vulnerabilities you can ever imagine.
  • 12. 3 Solidity Code Vulnerabilities
  • 13. Integer Underflow ● Solidity can handle 256 bit numbers ● Underflow: Token holder has 100 tokens but attempts to spend 101 Bad pattern: https://ethfiddle.com/IGJ2w0vPsX Good pattern: https://github.com/OpenZeppelin/op enzeppelin- solidity/blob/master/contracts/math/ SafeMath.sol
  • 14. Protect your Functions ● Public: Anyone can access it. ● External: Other smart contracts can access it. ● If anyone can execute your functions from public, they can steal all your tokens. Use Private or Internal functions. Example: https://ethfiddle.com/1q- YzAPV9W
  • 15. Fallbacks & DelegateCALL ● Fallback: Every smart contract can have exactly one unnamed function. This will execute if none functions are found. It only has msg.data to retrieve any payload. ● DelegatedCALL: It is identical to a message call (internal transaction) apart from the fact that the code at target address is executed in the context of the calling contract and msg.sender and msg.value do not change their values Example: https://ethfiddle.com/G3W7FEdrWj
  • 17. Parity Attack ● Contract A has a public function titled “myproject” that implements DelegatedCALL. It holds all 100k Tokens. ● Contract B is a hacker exploit, that tries to call ContractA.myproject(). Since this is public authority, contract B steals all the tokens.
  • 18. DAO Attack (Decentralised Autonomous Organisation) ● Check my account balance in the starting ONCE. ● Second time onwards, ignore balance check and initiate transfer request. # Fix - Reduce senders balance before making transfer. - require(msg.sender.transfer(_value)) Example: https://ethfiddle.com/VDH-hqXQZ_
  • 19. SelfDestruct ● Mechanism to delete smart contract ● Contract’s fund is sent to the target address ● Accidently create scenarios that it can be triggered Example: https://ethfiddle.com/dmsDZVYcBX
  • 20. Denial of Service ● Take ownership of the smart contract by sending enough ethers to insecure contract. ● The attacker knows the transaction will fail and will be refunded. This will block the service. Example: https://ethfiddle.com/jJNl3ILO-Z
  • 21. Shortest Address Attack ● Attackers abuse ERC-20 transfer function to withdraw a large amount thatn he/she is allowed to. ● Culprit: The input address has no trailing zeros, the exchange doesn’t do input validation. The EVM corrects this and the balance is increased. ● Exchanges are the biggest victims here Details: https://vessenes.com/the-erc20- short-address-attack-explained/
  • 23. Avoid External Calls ● Avoid a call from one contract to another untrusted contract or account. ● delegatecall, callcode, call ● Types of attacks: The Dao hack, The Parity multisignature wallet hack ● Use .send() and .transfer() over .call.value()
  • 24. Use Assert(), Require() & Revert() ● require(condition) for input validation ● assert(condition) for internal error check ● revert() returns unused gas ● throw() will continue to consume all gas
  • 25. Test Driven development ● Smart contract once deployed cannot be improved. No version control. ● Do Unit Testing ● Do Test coverage ● Simulate on testnet.
  • 26. Offline contracts shouldn’t be paid ● Contract A sends to Contract B, 1000 Tokens. ● Contract B is dead ● Contract A lost money
  • 27. 2 Major Hacks (~100 million USD)
  • 28. ETHEREUM DAO was hacked for 70 million USD (ETH Classic is born) https://www.coindesk.com/underst anding-dao-hack-journalists/ ● Attacker was able to ask the smart contract (DAO) to give the ether back multiple times before the smart contract could update its own balance. ● Ethereum Classic was forked and all transactions before attack were reverted.
  • 29. Parity Client vulnerability costed 30 million USD (Check this is real?) The code that did this: https://github.com/paritytech/parity -ethereum/pull/6102/files ● Parity is a ETH Client used by many people. You can call it from smart contracts. ● Three ICO (Edgeless casino, Swarm City and aeternity) were using parity client v.15, to check balance for raised funds. ● The function in wallet smart contract was Public DelegatedCALL, that let attackers steal the tokens.
  • 30. Thanks, Stay in touch! Telegram Linkedin