SlideShare a Scribd company logo
Outsmarting Smart
Contracts
Damian Rusinek
CONFidence, 5th of June 2018
damian.rusinek@securing.pl
@drdr_zz
drdr_zz
Blockchain and smart contracts are secure…
Ethereum.org
https://www.coindesk.com/blockchains-personal-data-protection-regulations-explained/
drdr_zz
…or is it?
Damian Rusinek
@drdr_zz
damianrusinek @ github
Security Researcher & Pentester
Assistant Professor
How come blockchains and smart contracts have such
serious security flaws when they are so highly secured?
drdr_zz
How I could steal tokens
(worth thousands of $) from
crypto exchange.
drdr_zz
BLOCKCHAIN 101
drdr_zz
Blockchain 101
D
U
D
E
Distributed
Unmodifiable
Database
Engine
drdr_zz
Do I need blockchain?
Do I need blockchain?
No
Single point of failure?
NO
Single point of authority?
NO
But really?
Modifiable data?
NO
drdr_zz
The analogy
Tor
Private
Communication
Blockchain
Unmodifiable
Storage
drdr_zz
The analogy
Tor
Private
Communication
Blockchain
Unmodifiable
Storage
drdr_zz
EPISODE I – SMART CONTRACTS
drdr_zz
Executable Smart contract
drdr_zz
Ethereum
„Ethereum is literally a computer that spans
the entire world.”
Ethereum White Paper
drdr_zz
What program could we
run as smart contract?
• eVoting
• Assets Management
(transfering ownership)
Why smart contracts?
• No single authority
• Trustless
• Allows public
verification
drdr_zz
How to verify the contract?
https://etherscan.io
drdr_zz
How to execute smart contract?
0x2b30ea3a000000000000000000000000000
0000000000000000000000000000000000000
drdr_zz
How to verify the execution?
drdr_zz
-
EPISODE II – SMART CONTRACTS
SECURITY
Fact I - All your data is public
drdr_zz
Fact I – All your data is public
Variables
drdr_zz
Fact I – All your data is public
Variables
drdr_zz
Fact I – All your data is public
Preview votes
in transactions.
drdr_zz
Fact I – All your data is public
Functions
• Public functions can be executed by anyone.
• Can anyone execute maliciousFunction2() ?
drdr_zz
Fact I – All your data is public
Functions
• Public functions can be executed by anyone.
• Can anyone execute maliciousFunction2() ?
Functions are public by default!
drdr_zz
• Public function which changes the owner.
Parity Hack worth 30 mln $
https://www.coindesk.com/30-million-ether-reported-stolen-parity-wallet-breach/
drdr_zz
• Public function which changes the owner.
Parity Hack worth 30 mln $
https://www.coindesk.com/30-million-ether-reported-stolen-parity-wallet-breach/
The race!
30 mln $ 80 mln $
worth today
90 mln $ 240 mln $
drdr_zz
• Set visibility type to all functions.
• Do not keep secret data as plaintext in smart contract.
• Examples:
• Rock Paper Scissors
• Blind Auctions
• Use blind commitments.
Fact I – All your data is public
Hash of Value
Real Value
drdr_zz
-
EPISODE II – SMART CONTRACTS
SECURITY
Fact II - Smart contract is
a program
drdr_zz
Fact II – Smart contract is a program
Integer Overflow
• Ethereum Tokens – your own
cryptocurrency on Ethereum.
The attack: empty victim’s wallet.
drdr_zz
Fact II – Smart contract is a program
Integer Overflow
1. Balances:
• Victim -> (MAXUINT-9) tokens (e.g. founder of contract).
• Attacker -> 10 tokens.
2. Attacker transfers 10 tokens to victim.
3. Both have zero tokens.
drdr_zz
Fact II – Smart contract is a program
Insecure libraries
drdr_zz
Fact II – Smart contract is a program
Insecure libraries
• Delete library used by mln $ worth contracts.
drdr_zz
Fact II – Smart contract is a program
Insecure libraries
• Delete library used by mln $ worth contracts.
https://www.trustnodes.com/2017/11/07/ether
eums-parity-hacked-half-million-eth-frozen
drdr_zz
• Use open source libraries that handle typical errors (e.g.
SafeMath for overflows).
• Write tests for boundary conditions.
• Verify the correctness and test libraries that you plan to
use.
Fact II - Smart contract is a program
drdr_zz
-
EPISODE II – SMART CONTRACTS
SECURITY
Fact III - Smart contracts have
limitations
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit
• All transactions are given some gas.
• All operations cost some gas.
• Transaction is rejected if gas limit is exceded.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit
• All transactions are given some gas.
• All operations cost some gas.
• Transaction is rejected if gas limit is exceded.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit
• All transactions are given some gas.
• All operations cost some gas.
• Transaction is rejected if gas limit is exceded.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit
• All transactions are given some gas.
• All operations cost some gas.
• Transaction is rejected if gas limit is exceded.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit
• All transactions are given some gas.
• All operations cost some gas.
• Transaction is rejected if gas limit is exceded.
The attack: DoS the contract.
The idea: to prevent infinite loops.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit – DoS on auction contract
BID
Auction
0 ETH
1 ETH
BIDBID
100
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit – DoS on auction contract
BID
Auction
2 ETH
BID
2 ETH
BIDBID
100
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit – DoS on auction contract
BID
Auction
3 ETH
3 ETH
BIDBIDBID
100
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit – DoS on auction contract
BID
Auction
3 ETH
4 ETH
BIDBIDBID
100
Further bids are blocked.
drdr_zz
Fact III – Smart contracts have limitations
Gas Limit – DoS on auction contract
Auction
3 ETH
Further bids are blocked.
WINNER!
drdr_zz
• Learn the limitations of Ethereum (gas, randomness,
etc.).
• Learn the way of handling these limitations.
• Write tests for handling limitations.
Fact III - Smart contracts have limitations
drdr_zz
-
EPISODE II – SMART CONTRACTS
SECURITY
Fact IV - Smart contracts have specific
vulns
drdr_zz
Fact IV – Smart contracts have specific vulns
Re-entrancy
• Unintended recurrence in smart contracts.
withdrawBalance
drdr_zz
Fact IV – Smart contracts have specific vulns
Re-entrancy
• Unintended recurrence in smart contracts.
withdrawBalance
send Ether
drdr_zz
Fact IV – Smart contracts have specific vulns
Re-entrancy
• Unintended recurrence in smart contracts.
withdrawBalance
send Ether
drdr_zz
Fact IV – Smart contracts have specific vulns
Re-entrancy
• Unintended recurrence in smart contracts.
withdrawBalance
withdrawBalance
withdrawBalance
send Ether
drdr_zz
Online
• Remix
• Securify
• SmartCheck
How to test smart contracts?
Offline
• Solhint
• Oyente
• Myhtril
Best practices
• ConsenSys
drdr_zz
EPISODE II – SMART CONTRACTS
INTEGRATION
drdr_zz
• Online wallets
• Crypto exchanges
• Games
• ICOs
Popular webapps integrated with smart contracts
Attack webapp and generate
malicious transaction.
Let’s steal some tokens from the exchange.
drdr_zz
Typical withdrawal transaction
50 GTN
Receiver address
Function Address Parameter Value Parameter
drdr_zz
Not a bug, it’s a feature
Let’s use to short address.
Function Address Value
Function Short address ValueValue
drdr_zz
Not a bug, it’s a feature
Let’s use to short address.
Function Address Value
Function Short address ValueModified address Value
drdr_zz
Not a bug, it’s a feature
Let’s use to short address.
Function Address Value
Function Short address ValueModified address Value
drdr_zz
Not a bug, it’s a feature
Let’s use to short address.
000
Function Address Value
Function Short address ValueModified address Value
drdr_zz
A little misunderstanding
What user tried to do:
Send 2399.99 GNT to
the 0x79735 address.
What Ethereum understood:
Send approx. 2 * 1045 GNT to the
0x079735000000000000000000000000
0000000000 address.
0000000000000000000000000000000000
Func Short address Value
Func Padded address Shifted (padded) value
drdr_zz
• Deposit 1 Ethereum Token.
• Generate Ethereum address with zero-byte suffix (a
matter of seconds).
• Withdraw 1 Ethereum Token and
send address without last byte.
• Receive 256 Ethereum Tokens.
How to attack exchange?
drdr_zz
How I have stolen tokens from exchange?
Func Short address Value
Func Padded address Shifted (padded) value
00
• Deposited 0.47 GTN
• Withdrew approx. 120 GTN (256 times more)
drdr_zz
• But to whom?
• No information about the owner on exchange
website!
• Be like Sherlock and find him.
• Time is running!
Let’s report the vulnerability
drdr_zz
• How to responsibly disclosure the vulnerability in
smart contract?
• How to inform the owner of smart contract?
• Would you steal crypto and the look for the owner?
That is general problem
Send him an encrypted
message kept on Ethereum.
drdr_zz
Responsible Disclosure Ethereum Messenger
My idea
Online: https://securing.github.io/eth-rd-messenger/
GitHub: https://github.com/securing/eth-rd-messenger
This tool is used to:
• send a secret message to the owner of a personal or contract
Ethereum address, encypted with its owner ECC public key,
• decrypt the message sent to the personal address or
contract's owner.
drdr_zz
DEMO
https://www.youtube.com/watch?v=
8AmpXCJRwzQ&feature=youtu.be
drdr_zz
Vulnerabilities
Similar to classic programs
• Overflows and underflows
• Unauthorized access to
functions
• Insecure libraries
• Business logic vulns
Specific for smart contracts
• Related to Ethereum limitations
(gas limit, randomness, etc.)
• Re-entrancy
• and more
drdr_zz
Top10 recommendations
1. Remember that all data is public in blockchain.
2. Do not keep secret data as plaintext in smart contract.
3. Use blind commitments.
4. Set visibility type to all functions.
5. Learn the limitations of Ethereum and how to handle them.
6. Write tests for handling limitations and for boundary conditions.
7. Verify the libraries than you plan to use.
8. Use the best security practices.
9. Consider threats from apps integrating with blockchain.
10. Test your contracts and blockchain applications.
drdr_zz
Keep Calm
And
Hack Smart Contracts!
SecuRing Smart Contracts Contest!
Follow us on Twitter:
@SecuRingPL
@drdr_zz
Thank you!
Damian Rusinek (@drdr_zz)
damian.rusinek@securing.pl
Questions?

More Related Content

PDF
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
DOC
DOCS ON NETWORK SECURITY
PDF
Crypto hlug
PDF
[ETHCon Korea 2019] Jung woohyun 정우현
PDF
[CONFidence 2016] Marco Ortisi - Recover a RSA private key from a TLS session...
PDF
Ethereum Blockchain and DApps - Workshop at Software University
PDF
DEFCON 23 - Eijah - crypto for hackers
PDF
Cryptography For The Average Developer - Sunshine PHP
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
DOCS ON NETWORK SECURITY
Crypto hlug
[ETHCon Korea 2019] Jung woohyun 정우현
[CONFidence 2016] Marco Ortisi - Recover a RSA private key from a TLS session...
Ethereum Blockchain and DApps - Workshop at Software University
DEFCON 23 - Eijah - crypto for hackers
Cryptography For The Average Developer - Sunshine PHP

What's hot (9)

PDF
Applied Cryptography
PDF
OpenCard hack (projekt chameleon)
PPTX
A research-oriented introduction to the cryptographic currencies (starting wi...
PPSX
Cryptography
PPT
Rothke Info Security Canada 2007 Final
PDF
Cryptography in PHP: use cases
PDF
Cybercrime in the Deep Web (BHEU 2015)
PPTX
Basic concept of pki
PDF
A Robust Cryptographic System using Neighborhood-Generated Keys
Applied Cryptography
OpenCard hack (projekt chameleon)
A research-oriented introduction to the cryptographic currencies (starting wi...
Cryptography
Rothke Info Security Canada 2007 Final
Cryptography in PHP: use cases
Cybercrime in the Deep Web (BHEU 2015)
Basic concept of pki
A Robust Cryptographic System using Neighborhood-Generated Keys
Ad

Similar to CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blockchain security minefields (Damian Rusinek) (20)

PDF
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
PDF
Blockchain School 2019 - Security of Smart Contracts.pdf
PDF
Smart Contarct Vulnerabilities and Attack Prevention
PPTX
Kriptovaluták, hashbányászat és okoscicák
PDF
Sarwar sayeed , hector marco gisbert, tom caira ieee
PPTX
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
PPTX
Explain Ethereum smart contract hacking like i am a five
PDF
Security in the blockchain
PDF
Security challenges in Ethereum smart contract programming
ODP
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
PPTX
Smart contract honeypots for profit (and fun) - bha
PDF
Daniel Connelly Ethereum Smart Contract Master's Thesis
PDF
Blockchain and smart contracts, what they are and why you should really care ...
PPTX
Ethereum
 
PPTX
Best practices to build secure smart contracts
PPTX
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
PDF
Security challenges in Ethereum smart contract programming (ver. 2)
PPTX
Blockchain for Developers
PDF
You May Have Paid more than you imagine: Replay Attacks on Ethereum Smart Con...
PDF
“Create your own cryptocurrency in an hour” - Sandip Pandey
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
Blockchain School 2019 - Security of Smart Contracts.pdf
Smart Contarct Vulnerabilities and Attack Prevention
Kriptovaluták, hashbányászat és okoscicák
Sarwar sayeed , hector marco gisbert, tom caira ieee
Zoltán Balázs - Ethereum Smart Contract Hacking Explained like I’m Five
Explain Ethereum smart contract hacking like i am a five
Security in the blockchain
Security challenges in Ethereum smart contract programming
Stefano Maestri - Blockchain and smart contracts, what they are and why you s...
Smart contract honeypots for profit (and fun) - bha
Daniel Connelly Ethereum Smart Contract Master's Thesis
Blockchain and smart contracts, what they are and why you should really care ...
Ethereum
 
Best practices to build secure smart contracts
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Security challenges in Ethereum smart contract programming (ver. 2)
Blockchain for Developers
You May Have Paid more than you imagine: Replay Attacks on Ethereum Smart Con...
“Create your own cryptocurrency in an hour” - Sandip Pandey
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Tartificialntelligence_presentation.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Getting Started with Data Integration: FME Form 101
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Chapter 5: Probability Theory and Statistics
PDF
August Patch Tuesday
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
WOOl fibre morphology and structure.pdf for textiles
Zenith AI: Advanced Artificial Intelligence
Tartificialntelligence_presentation.pptx
Hindi spoken digit analysis for native and non-native speakers
cloud_computing_Infrastucture_as_cloud_p
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Getting Started with Data Integration: FME Form 101
A comparative analysis of optical character recognition models for extracting...
Web App vs Mobile App What Should You Build First.pdf
Enhancing emotion recognition model for a student engagement use case through...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Heart disease approach using modified random forest and particle swarm optimi...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
A Presentation on Artificial Intelligence
Assigned Numbers - 2025 - Bluetooth® Document
Chapter 5: Probability Theory and Statistics
August Patch Tuesday

CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blockchain security minefields (Damian Rusinek)

  • 1. Outsmarting Smart Contracts Damian Rusinek CONFidence, 5th of June 2018 damian.rusinek@securing.pl @drdr_zz
  • 2. drdr_zz Blockchain and smart contracts are secure… Ethereum.org https://www.coindesk.com/blockchains-personal-data-protection-regulations-explained/
  • 4. Damian Rusinek @drdr_zz damianrusinek @ github Security Researcher & Pentester Assistant Professor How come blockchains and smart contracts have such serious security flaws when they are so highly secured?
  • 5. drdr_zz How I could steal tokens (worth thousands of $) from crypto exchange.
  • 8. drdr_zz Do I need blockchain? Do I need blockchain? No Single point of failure? NO Single point of authority? NO But really? Modifiable data? NO
  • 11. drdr_zz EPISODE I – SMART CONTRACTS
  • 13. drdr_zz Ethereum „Ethereum is literally a computer that spans the entire world.” Ethereum White Paper
  • 14. drdr_zz What program could we run as smart contract? • eVoting • Assets Management (transfering ownership) Why smart contracts? • No single authority • Trustless • Allows public verification
  • 15. drdr_zz How to verify the contract? https://etherscan.io
  • 16. drdr_zz How to execute smart contract? 0x2b30ea3a000000000000000000000000000 0000000000000000000000000000000000000
  • 17. drdr_zz How to verify the execution?
  • 18. drdr_zz - EPISODE II – SMART CONTRACTS SECURITY Fact I - All your data is public
  • 19. drdr_zz Fact I – All your data is public Variables
  • 20. drdr_zz Fact I – All your data is public Variables
  • 21. drdr_zz Fact I – All your data is public Preview votes in transactions.
  • 22. drdr_zz Fact I – All your data is public Functions • Public functions can be executed by anyone. • Can anyone execute maliciousFunction2() ?
  • 23. drdr_zz Fact I – All your data is public Functions • Public functions can be executed by anyone. • Can anyone execute maliciousFunction2() ? Functions are public by default!
  • 24. drdr_zz • Public function which changes the owner. Parity Hack worth 30 mln $ https://www.coindesk.com/30-million-ether-reported-stolen-parity-wallet-breach/
  • 25. drdr_zz • Public function which changes the owner. Parity Hack worth 30 mln $ https://www.coindesk.com/30-million-ether-reported-stolen-parity-wallet-breach/ The race! 30 mln $ 80 mln $ worth today 90 mln $ 240 mln $
  • 26. drdr_zz • Set visibility type to all functions. • Do not keep secret data as plaintext in smart contract. • Examples: • Rock Paper Scissors • Blind Auctions • Use blind commitments. Fact I – All your data is public Hash of Value Real Value
  • 27. drdr_zz - EPISODE II – SMART CONTRACTS SECURITY Fact II - Smart contract is a program
  • 28. drdr_zz Fact II – Smart contract is a program Integer Overflow • Ethereum Tokens – your own cryptocurrency on Ethereum. The attack: empty victim’s wallet.
  • 29. drdr_zz Fact II – Smart contract is a program Integer Overflow 1. Balances: • Victim -> (MAXUINT-9) tokens (e.g. founder of contract). • Attacker -> 10 tokens. 2. Attacker transfers 10 tokens to victim. 3. Both have zero tokens.
  • 30. drdr_zz Fact II – Smart contract is a program Insecure libraries
  • 31. drdr_zz Fact II – Smart contract is a program Insecure libraries • Delete library used by mln $ worth contracts.
  • 32. drdr_zz Fact II – Smart contract is a program Insecure libraries • Delete library used by mln $ worth contracts. https://www.trustnodes.com/2017/11/07/ether eums-parity-hacked-half-million-eth-frozen
  • 33. drdr_zz • Use open source libraries that handle typical errors (e.g. SafeMath for overflows). • Write tests for boundary conditions. • Verify the correctness and test libraries that you plan to use. Fact II - Smart contract is a program
  • 34. drdr_zz - EPISODE II – SMART CONTRACTS SECURITY Fact III - Smart contracts have limitations
  • 35. drdr_zz Fact III – Smart contracts have limitations Gas Limit • All transactions are given some gas. • All operations cost some gas. • Transaction is rejected if gas limit is exceded.
  • 36. drdr_zz Fact III – Smart contracts have limitations Gas Limit • All transactions are given some gas. • All operations cost some gas. • Transaction is rejected if gas limit is exceded.
  • 37. drdr_zz Fact III – Smart contracts have limitations Gas Limit • All transactions are given some gas. • All operations cost some gas. • Transaction is rejected if gas limit is exceded.
  • 38. drdr_zz Fact III – Smart contracts have limitations Gas Limit • All transactions are given some gas. • All operations cost some gas. • Transaction is rejected if gas limit is exceded.
  • 39. drdr_zz Fact III – Smart contracts have limitations Gas Limit • All transactions are given some gas. • All operations cost some gas. • Transaction is rejected if gas limit is exceded. The attack: DoS the contract. The idea: to prevent infinite loops.
  • 40. drdr_zz Fact III – Smart contracts have limitations Gas Limit – DoS on auction contract BID Auction 0 ETH 1 ETH BIDBID 100
  • 41. drdr_zz Fact III – Smart contracts have limitations Gas Limit – DoS on auction contract BID Auction 2 ETH BID 2 ETH BIDBID 100
  • 42. drdr_zz Fact III – Smart contracts have limitations Gas Limit – DoS on auction contract BID Auction 3 ETH 3 ETH BIDBIDBID 100
  • 43. drdr_zz Fact III – Smart contracts have limitations Gas Limit – DoS on auction contract BID Auction 3 ETH 4 ETH BIDBIDBID 100 Further bids are blocked.
  • 44. drdr_zz Fact III – Smart contracts have limitations Gas Limit – DoS on auction contract Auction 3 ETH Further bids are blocked. WINNER!
  • 45. drdr_zz • Learn the limitations of Ethereum (gas, randomness, etc.). • Learn the way of handling these limitations. • Write tests for handling limitations. Fact III - Smart contracts have limitations
  • 46. drdr_zz - EPISODE II – SMART CONTRACTS SECURITY Fact IV - Smart contracts have specific vulns
  • 47. drdr_zz Fact IV – Smart contracts have specific vulns Re-entrancy • Unintended recurrence in smart contracts. withdrawBalance
  • 48. drdr_zz Fact IV – Smart contracts have specific vulns Re-entrancy • Unintended recurrence in smart contracts. withdrawBalance send Ether
  • 49. drdr_zz Fact IV – Smart contracts have specific vulns Re-entrancy • Unintended recurrence in smart contracts. withdrawBalance send Ether
  • 50. drdr_zz Fact IV – Smart contracts have specific vulns Re-entrancy • Unintended recurrence in smart contracts. withdrawBalance withdrawBalance withdrawBalance send Ether
  • 51. drdr_zz Online • Remix • Securify • SmartCheck How to test smart contracts? Offline • Solhint • Oyente • Myhtril Best practices • ConsenSys
  • 52. drdr_zz EPISODE II – SMART CONTRACTS INTEGRATION
  • 53. drdr_zz • Online wallets • Crypto exchanges • Games • ICOs Popular webapps integrated with smart contracts Attack webapp and generate malicious transaction. Let’s steal some tokens from the exchange.
  • 54. drdr_zz Typical withdrawal transaction 50 GTN Receiver address Function Address Parameter Value Parameter
  • 55. drdr_zz Not a bug, it’s a feature Let’s use to short address. Function Address Value Function Short address ValueValue
  • 56. drdr_zz Not a bug, it’s a feature Let’s use to short address. Function Address Value Function Short address ValueModified address Value
  • 57. drdr_zz Not a bug, it’s a feature Let’s use to short address. Function Address Value Function Short address ValueModified address Value
  • 58. drdr_zz Not a bug, it’s a feature Let’s use to short address. 000 Function Address Value Function Short address ValueModified address Value
  • 59. drdr_zz A little misunderstanding What user tried to do: Send 2399.99 GNT to the 0x79735 address. What Ethereum understood: Send approx. 2 * 1045 GNT to the 0x079735000000000000000000000000 0000000000 address. 0000000000000000000000000000000000 Func Short address Value Func Padded address Shifted (padded) value
  • 60. drdr_zz • Deposit 1 Ethereum Token. • Generate Ethereum address with zero-byte suffix (a matter of seconds). • Withdraw 1 Ethereum Token and send address without last byte. • Receive 256 Ethereum Tokens. How to attack exchange?
  • 61. drdr_zz How I have stolen tokens from exchange? Func Short address Value Func Padded address Shifted (padded) value 00 • Deposited 0.47 GTN • Withdrew approx. 120 GTN (256 times more)
  • 62. drdr_zz • But to whom? • No information about the owner on exchange website! • Be like Sherlock and find him. • Time is running! Let’s report the vulnerability
  • 63. drdr_zz • How to responsibly disclosure the vulnerability in smart contract? • How to inform the owner of smart contract? • Would you steal crypto and the look for the owner? That is general problem Send him an encrypted message kept on Ethereum.
  • 64. drdr_zz Responsible Disclosure Ethereum Messenger My idea Online: https://securing.github.io/eth-rd-messenger/ GitHub: https://github.com/securing/eth-rd-messenger This tool is used to: • send a secret message to the owner of a personal or contract Ethereum address, encypted with its owner ECC public key, • decrypt the message sent to the personal address or contract's owner.
  • 66. drdr_zz Vulnerabilities Similar to classic programs • Overflows and underflows • Unauthorized access to functions • Insecure libraries • Business logic vulns Specific for smart contracts • Related to Ethereum limitations (gas limit, randomness, etc.) • Re-entrancy • and more
  • 67. drdr_zz Top10 recommendations 1. Remember that all data is public in blockchain. 2. Do not keep secret data as plaintext in smart contract. 3. Use blind commitments. 4. Set visibility type to all functions. 5. Learn the limitations of Ethereum and how to handle them. 6. Write tests for handling limitations and for boundary conditions. 7. Verify the libraries than you plan to use. 8. Use the best security practices. 9. Consider threats from apps integrating with blockchain. 10. Test your contracts and blockchain applications.
  • 68. drdr_zz Keep Calm And Hack Smart Contracts! SecuRing Smart Contracts Contest! Follow us on Twitter: @SecuRingPL @drdr_zz
  • 69. Thank you! Damian Rusinek (@drdr_zz) damian.rusinek@securing.pl Questions?