SlideShare a Scribd company logo
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

More Related Content

What's hot (20)

PDF
Blockchain
Soichiro Takagi
 
PPTX
Bitcoin, Blockchain and the Crypto Contracts - Part 2
Prithwis Mukerjee
 
PPTX
Block chain by harsh biltu agarwal
N V Jagadeesh Kumar
 
PPTX
The Blockchain and JavaScript
Portia Burton
 
PDF
Boolberry reduces blockchain bloat
boolberry
 
PPTX
Tutorial blockchain technical overview-ss
Howard Anglin
 
PDF
Block Chain Technology Report
DeveshKumar221
 
PDF
Introduction to Ethereum
Terek Judi
 
PPTX
BitCoin Protocol
Consulthinkspa
 
PDF
Bitcoin, Blockchain and Crypto Contracts - Part 3
Prithwis Mukerjee
 
PDF
Introduction to Blockchain Development
Lightstreams
 
PPTX
Ethereum Intro
Dejan Radic
 
PPTX
Introduction to Blockchain
subbul
 
PPTX
Blockchain Corporate Style
Narendranath Reddy
 
PDF
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
Paperchain
 
PDF
Blockchain Programming
Rhea Myers
 
PPTX
BLOCKCHAIN TECHNOLOGY
garishma bhatia
 
PDF
Build your first blockchain
Đoàn Thái Thiên Lộc
 
PPTX
Blockchain Technology
PalakGulati10
 
PDF
Bitcoins Math
Akram El-Korashy
 
Blockchain
Soichiro Takagi
 
Bitcoin, Blockchain and the Crypto Contracts - Part 2
Prithwis Mukerjee
 
Block chain by harsh biltu agarwal
N V Jagadeesh Kumar
 
The Blockchain and JavaScript
Portia Burton
 
Boolberry reduces blockchain bloat
boolberry
 
Tutorial blockchain technical overview-ss
Howard Anglin
 
Block Chain Technology Report
DeveshKumar221
 
Introduction to Ethereum
Terek Judi
 
BitCoin Protocol
Consulthinkspa
 
Bitcoin, Blockchain and Crypto Contracts - Part 3
Prithwis Mukerjee
 
Introduction to Blockchain Development
Lightstreams
 
Ethereum Intro
Dejan Radic
 
Introduction to Blockchain
subbul
 
Blockchain Corporate Style
Narendranath Reddy
 
201811 Bitcoin, Blockchain and the Technology behind Cryptocurrencies
Paperchain
 
Blockchain Programming
Rhea Myers
 
BLOCKCHAIN TECHNOLOGY
garishma bhatia
 
Build your first blockchain
Đoàn Thái Thiên Lộc
 
Blockchain Technology
PalakGulati10
 
Bitcoins Math
Akram El-Korashy
 

Similar to Best practices to build secure smart contracts (20)

PDF
Security in the blockchain
Bellaj Badr
 
PDF
Blockchain School 2019 - Security of Smart Contracts.pdf
Davide Carboni
 
PDF
Smart Contract Security
Sadegh Dorri N.
 
PDF
Blockchain and smart contracts, what they are and why you should really care ...
maeste
 
PPTX
Blockchain for Developers
Shimi Bandiel
 
PPTX
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
hacktivity
 
PPTX
Explain Ethereum smart contract hacking like i am a five
Zoltan Balazs
 
PDF
Smart Contarct Vulnerabilities and Attack Prevention
prasannabhalerao22
 
PPTX
Deja vu Security - Blockchain Security Summit - Adam Cecchetti
Scott Strang
 
PDF
Security Model of Blockchain
saficus
 
PDF
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
PDF
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
PDF
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP
 
PDF
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
SecuRing
 
PPTX
EthereumBlockchainMarch3 (1).pptx
WijdenBenothmen1
 
PPTX
Kriptovaluták, hashbányászat és okoscicák
hackersuli
 
PDF
“Create your own cryptocurrency in an hour” - Sandip Pandey
EIT Digital Alumni
 
PPTX
01 what is blockchain
BastianBlankenburg
 
PDF
CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blo...
PROIDEA
 
ODP
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Codemotion
 
Security in the blockchain
Bellaj Badr
 
Blockchain School 2019 - Security of Smart Contracts.pdf
Davide Carboni
 
Smart Contract Security
Sadegh Dorri N.
 
Blockchain and smart contracts, what they are and why you should really care ...
maeste
 
Blockchain for Developers
Shimi Bandiel
 
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
hacktivity
 
Explain Ethereum smart contract hacking like i am a five
Zoltan Balazs
 
Smart Contarct Vulnerabilities and Attack Prevention
prasannabhalerao22
 
Deja vu Security - Blockchain Security Summit - Adam Cecchetti
Scott Strang
 
Security Model of Blockchain
saficus
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
Jerome de Tychey - Building Web3.0 with Ethereum - Codemotion Berlin 2018
Codemotion
 
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP
 
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
SecuRing
 
EthereumBlockchainMarch3 (1).pptx
WijdenBenothmen1
 
Kriptovaluták, hashbányászat és okoscicák
hackersuli
 
“Create your own cryptocurrency in an hour” - Sandip Pandey
EIT Digital Alumni
 
01 what is blockchain
BastianBlankenburg
 
CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blo...
PROIDEA
 
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Codemotion
 
Ad

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Ad

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 [email protected] 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