SlideShare a Scribd company logo
OWASP FOUNDATION
®
Attacking
Ethereum Smart Contracts
a deep dive after ~9 years of deployment
Simone Onofri
OWASP Italy Day 2023
Politecnico of Milan - 11th September 2023
OWASP FOUNDATION owasp.org
Introduction
Open: Everything at OWASP is radically
transparent from our finances to our
code.
Innovative: We encourage and support
innovation and experiments for
solutions to software security
challenges.
Global: Anyone around the world is
encouraged to participate in the OWASP
community.
Integrity: Our community is respectful,
supportive, truthful, and vendor neutral
OWASP FOUNDATION owasp.org
• What are Smart Contracts?
• What are the most common
vulnerabilities?
• Conclusions
Agenda
Open: Everything at OWASP is radically
transparent from our finances to our
code.
Innovative: We encourage and support
innovation and experiments for
solutions to software security
challenges.
Global: Anyone around the world is
encouraged to participate in the OWASP
community.
Integrity: Our community is respectful,
supportive, truthful, and vendor neutral
OWASP FOUNDATION owasp.org
• What are Smart Contracts?
• What are the most common
vulnerabilities?
• Conclusions
Agenda
OWASP FOUNDATION owasp.org
What are Smart Contracts?
Are simply programs that runs on the Ethereum blockchain. It’s a
collection of code (its functions) and data (its state) that resides
at a specific address on the Ethereum blockchain.
https://ethereum.org/en/developers/docs/smart-contracts/
OWASP FOUNDATION owasp.org
How are Smart Contracts written?
Turing-complete programming language that can be used to
create “contracts” that can be used to encode arbitrary state
transition functions [...]. The code in Ethereum contracts is
written in a low-level, stack-based bytecode language, referred
to as “Ethereum virtual machine code” or “EVM code”. The code
consists of a series of bytes, where each byte represents an
operation
https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
OWASP FOUNDATION owasp.org
What can be done with Smart Contracts?
systems which automatically move digital assets according to
arbitrary pre-specified rules. For example, one might have a
treasury contract of the form "A can withdraw up to X currency
units per day, B can withdraw up to Y per day, A and B together can
withdraw anything, and A can shut off B's ability to withdraw".
[…]
https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
What can be done with Smart Contracts?
[…]
The logical extension of this is decentralized autonomous
organizations (DAOs) - long-term smart contracts that contain
the assets and encode the bylaws of an entire organization
https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
Screenshot dell’attaccco
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
What are Blockchain characteristics and
how do they impact security?
● Immutable: Transactions are irreversible, meaning they can’t be undone
once an action has been taken.
● Public: Both contracts and transactions are publicly accessible through
the blockchain.
● Deterministic: The execution of a smart contract must yield the same
result on any node.
● Limited: Smart contracts cannot call upon external resources unless
they use Oracles.
● Permissionless: Everyone can publish and interact with contracts.
Open: Everything at OWASP is radically
transparent from our finances to our
code.
Innovative: We encourage and support
innovation and experiments for
solutions to software security
challenges.
Global: Anyone around the world is
encouraged to participate in the OWASP
community.
Integrity: Our community is respectful,
supportive, truthful, and vendor neutral
OWASP FOUNDATION owasp.org
• What are Smart Contracts?
• What are the most common
vulnerabilities?
• Conclusions
Agenda
OWASP FOUNDATION owasp.org
OWASP Smart Contract Top 10 (2023)
• Reentrancy Attacks
• Integer Overflow and Underflow
• Timestamp Dependence
• Access Control Vulnerabilities
• Front-running Attacks
• Denial of Service (DoS) Attacks
• Logic Errors
• Insecure Randomness
• Gas Limit Vulnerabilities
• Unchecked External Calls
OWASP FOUNDATION owasp.org
OWASP Smart Contract Top 10 (2023)
• Reentrancy Attacks
• Integer Overflow and Underflow
• Timestamp Dependence
• Access Control Vulnerabilities
• Front-running Attacks
• Denial of Service (DoS) Attacks
• Logic Errors
• Insecure Randomness
• Gas Limit Vulnerabilities
• Unchecked External Calls
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
Vulnerable Contract
0x6060604052361561008a576000357c0100000000000000000000000000000000000000000000000000000000900480
63095ea7b3146100b857806318160ddd146100ed57806323b872dd146101105780632e1a7d4d1461014e57806370a082
311461017a578063a9059cbb146101a6578063d0e30db0146101db578063dd62ed3e146101fe5761008a565b6100a25b
6000610098610887565b905061009f565b90565b6040518082815260200191505060405180910390f35b6100d7600480
803590602001909190803590602001909190505061061a565b6040518082815260200191505060405180910390f35b61
00fa6004805050610757565b6040518082815260200191505060405180910390f35b6101386004808035906020019091
9080359060200190919080359060200190919050506103df565b6040518082815260200191505060405180910390f35b
610164600480803590602001909190505061077b565b6040518082815260200191505060405180910390f35b61019060
04808035906020019091905050610233565b6040518082815260200191505060405180910390f35b6101c56004808035
906020019091908035906020019091905050610271565b6040518082815260200191505060405180910390f35b6101e8
6004805050610887565b6040518082815260200191505060405180910390f35b61021d60048080359060200190919080
359060200190919050506106ee565b6040518082815260200191505060405180910390f35b6000600060005060008373
ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054905061026c565b9190
50565b600081600060005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160
00206000505410156102af57610002565b6102e8600060005060008573ffffffffffffffffffffffffffffffffffffff
ff168152602001908152602001600020600050548361091f565b15156102f357610002565b81600060005060003373ff
ffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508[…]
https://etherscan.io/address/0xd654bDD32FC99471455e86C2E7f7D7b6437e9179
Opcodes:
0x60: PUSH1 EVM opcode
0x60: The free memory pointer
0x60: PUSH1 EVM opcode
0x40: Memory position for the free memory pointer
MSTORE : EVM opcode is 0x52
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
Decompiled withdraw function
https://etherscan.io/address/0xd654bDD32FC99471455e86C2E7f7D7b6437e9179
OWASP FOUNDATION owasp.org
Attacker Contract by Nikolai Mushegian
Decompiled
https://etherscan.io/address/0x4AfB544Eb87265cF7Fc8fdB843c81d34F7E2A369
OWASP FOUNDATION owasp.org
Attack Proof of Concept
OWASP FOUNDATION owasp.org
OWASP Smart Contract Top 10 (2023)
• Reentrancy Attacks
• Integer Overflow and Underflow
• Timestamp Dependence
• Access Control Vulnerabilities
• Front-running Attacks
• Denial of Service (DoS) Attacks
• Logic Errors
• Insecure Randomness
• Gas Limit Vulnerabilities
• Unchecked External Calls
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
Vulnerable Contract
OWASP FOUNDATION owasp.org
Integer Overflow and Underflow
An integer overflow occurs when an integer value is
incremented to a value that is too large to store in
the associated representation. When this occurs,
the value may wrap to become a very small or
negative number.
https://cwe.mitre.org/data/definitions/190.html
OWASP FOUNDATION owasp.org
Increment uint8 (2^8-1) in Solidity
0+1=1
1+1=2
2+1=3
[…]
253+1=254
254+1= 255
255 + 1 = 0
OWASP FOUNDATION owasp.org
Attack Contract and PoC
OWASP FOUNDATION owasp.org
OWASP Smart Contract Top 10 (2023)
• Reentrancy Attacks
• Integer Overflow and Underflow
• Timestamp Dependence
• Access Control Vulnerabilities
• Front-running Attacks
• Denial of Service (DoS) Attacks
• Logic Errors
• Insecure Randomness
• Gas Limit Vulnerabilities
• Unchecked External Calls
OWASP FOUNDATION owasp.org
Abritrage CTF
Admin has gifted you 5e18
Btokens on your birthday.
Using A,B,C,D,E token
pairs on swap contracts,
increase your BTokens.
Interface to Uniswap v2
https://quillctf.super.site/challenges/quillctf-x-quickswap/arbitrage
OWASP FOUNDATION owasp.org
Vulnerability Description
Arbitrage arises when price discrepancies exist across
different markets, trading pairs or Liquidity Pools for the
same asset.
However, trading fees, gas fees, and slippage must be
considered.
To evaluate arbitrage opportunities it is possible to
evaluate the indirect and circular trade “paths”, starting
from B and ending with B when the exchange rate is
calculated from the quantity of different tokens present
in each pool.
B -> A -> C -> B
B -> A -> D -> B
B -> A -> E -> B
B -> C -> A -> B
B -> C -> D -> B
B -> C -> E -> B
B -> D -> A -> B
B -> D -> C -> B
B -> D -> E -> B
B -> E -> A -> B
B -> E -> C -> B
B -> E -> D -> B
https://docs.uniswap.org/contracts/v2/concepts/core-concepts/pools
OWASP FOUNDATION owasp.org
Attack Contract and PoC
Open: Everything at OWASP is radically
transparent from our finances to our
code.
Innovative: We encourage and support
innovation and experiments for
solutions to software security
challenges.
Global: Anyone around the world is
encouraged to participate in the OWASP
community.
Integrity: Our community is respectful,
supportive, truthful, and vendor neutral
OWASP FOUNDATION owasp.org
• What are Smart Contracts?
• What are the most common
vulnerabilities?
• Conclusions
Agenda
OWASP FOUNDATION owasp.org
Conclusions
Smart Contract security is a composite problem that can be
derived from:
• Programming issues (e.g., arithmetic vulnerabilities).
• Features of the blockchain (e.g., access control, weak sources
of randomness).
• Feature of the Platform (e.g., reentrancy, time dependence,
frontrunning).
But the main point is to understand the Business Logic of the
Smart Contract we’re auditing.
OWASP FOUNDATION owasp.org
OWASP FOUNDATION owasp.org
Thank you to our sponsors
Attacking Ethereum Smart Contracts  a deep dive after ~9 years of deployment

More Related Content

PPTX
Introduction to Blockchain and Smart Contracts
PPTX
Blockchain Technology.pptx
PPTX
Blockchain Technology
PPTX
Bitcoin, Ethereum, Smart Contract & Blockchain
PDF
Blockchain Presentation
PDF
Tokenization
PDF
Ethereum Blockchain explained
Introduction to Blockchain and Smart Contracts
Blockchain Technology.pptx
Blockchain Technology
Bitcoin, Ethereum, Smart Contract & Blockchain
Blockchain Presentation
Tokenization
Ethereum Blockchain explained

What's hot (20)

PDF
Blockchain
PPTX
Blockchain
PDF
Blockchain: The New Technology and Its Applications for Libraries
PPTX
What is tokenization in blockchain?
PPSX
Cryptocurrency
PDF
An Introduction to Blockchain
PDF
Blockchain in Banking, Business and Beyond
PDF
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
PDF
Blockchain
PPTX
digital signature ppt
PDF
Understanding Blockchain: Distributed Ledger Technology
PPTX
Blockchain concepts
PDF
Blockchain and Cryptocurrency for Dummies
PDF
Ethereum-Cryptocurrency (All about Ethereum)
PPTX
Blockchain technology
PPTX
Smart contract
PDF
Blockchain Technology Fundamentals
PPTX
Blockchain technology
PPTX
Blockchain Technology Powerpoint
PPTX
Blockchain
Blockchain
Blockchain
Blockchain: The New Technology and Its Applications for Libraries
What is tokenization in blockchain?
Cryptocurrency
An Introduction to Blockchain
Blockchain in Banking, Business and Beyond
Understanding Proof of Work (PoW) and Proof of Stake (PoS) Algorithms
Blockchain
digital signature ppt
Understanding Blockchain: Distributed Ledger Technology
Blockchain concepts
Blockchain and Cryptocurrency for Dummies
Ethereum-Cryptocurrency (All about Ethereum)
Blockchain technology
Smart contract
Blockchain Technology Fundamentals
Blockchain technology
Blockchain Technology Powerpoint
Blockchain
Ad

Similar to Attacking Ethereum Smart Contracts a deep dive after ~9 years of deployment (20)

PDF
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
PDF
Getting Started in Blockchain Security and Smart Contract Auditing
PPTX
A Look Into Emerging Security Issues Within Cryptocurrency Ecosystems
PDF
A Look Into Emerging Security Issues Within Cryptocurrency Ecosystems
PDF
Smart Contarct Vulnerabilities and Attack Prevention
PPTX
Practical Challenges for Public Blockchains
PPTX
Practical Challenges for Public Blockchains
PDF
Dumb Smart Contracts (TBBUG).pdf
PDF
Blockchain School 2019 - Security of Smart Contracts.pdf
PDF
Web3 Security: The Blockchain is Your SIEM
PDF
CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blo...
PDF
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
PDF
An introduction to blockchain and hyperledger v ru
PDF
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
PPTX
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
PDF
All watched over machines of loving grace amsterdam
PDF
Introduction into blockchains and cryptocurrencies
PDF
Distributed Ledger Security in the Enterprise Environment
PDF
Security in the blockchain
PPTX
Wallets and Transactions #1
Attacking and Exploiting Ethereum Smart Contracts: Auditing 101
Getting Started in Blockchain Security and Smart Contract Auditing
A Look Into Emerging Security Issues Within Cryptocurrency Ecosystems
A Look Into Emerging Security Issues Within Cryptocurrency Ecosystems
Smart Contarct Vulnerabilities and Attack Prevention
Practical Challenges for Public Blockchains
Practical Challenges for Public Blockchains
Dumb Smart Contracts (TBBUG).pdf
Blockchain School 2019 - Security of Smart Contracts.pdf
Web3 Security: The Blockchain is Your SIEM
CONFidence 2018: Outsmarting smart contracts - an essential walkthrough a blo...
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
An introduction to blockchain and hyperledger v ru
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
All watched over machines of loving grace amsterdam
Introduction into blockchains and cryptocurrencies
Distributed Ledger Security in the Enterprise Environment
Security in the blockchain
Wallets and Transactions #1
Ad

More from Simone Onofri (20)

PDF
Threat Modeling Connect (TMC) Barcelona Meetup - Threat Modeling @ W3C - Age...
PDF
Serverless Meetup Barcelona - Attacking and Exploiting Modern Web Applications
PDF
Attacking IoT Devices from a Web Perspective - Linux Day
PDF
Linux Day 2018 Roma - Web Application Penetration Test (WAPT) con Linux
PDF
Agile Lean Conference 2017 - Leadership e facilitazione
PDF
Agile Business Consortium - LEGO SERIOUS PLAY e i Principi di Agile Project M...
PDF
Agile Project Framework
PDF
Agile nei servizi di cyber security (Security Summit Edition)
PDF
Security Project Management - Agile nei servizi di Cyber Security
PDF
Cyber Defense - How to find and manage zero-days
PDF
Cyber Defense - How to be prepared to APT
PDF
ISACA - Gestire progetti di Ethical Hacking secondo le best practices
PDF
OWASP AppSec EU 2016 - Security Project Management - How to be Agile in Secu...
PPTX
Mamma, da grande voglio essere un Penetration Tester HackInBo 2016 Winter
PDF
Penetration Testing con Python - Network Sniffer
PDF
ORM Injection
PDF
Agile e Lean Management
PDF
Nuove minacce nella Cyber Security, come proteggersi
PDF
Hackers vs Developers - Cross Site Scripting (XSS) Attacco e difesa
PDF
Agile Lean Management - MoSCoW, Timeboxing e Kanban
Threat Modeling Connect (TMC) Barcelona Meetup - Threat Modeling @ W3C - Age...
Serverless Meetup Barcelona - Attacking and Exploiting Modern Web Applications
Attacking IoT Devices from a Web Perspective - Linux Day
Linux Day 2018 Roma - Web Application Penetration Test (WAPT) con Linux
Agile Lean Conference 2017 - Leadership e facilitazione
Agile Business Consortium - LEGO SERIOUS PLAY e i Principi di Agile Project M...
Agile Project Framework
Agile nei servizi di cyber security (Security Summit Edition)
Security Project Management - Agile nei servizi di Cyber Security
Cyber Defense - How to find and manage zero-days
Cyber Defense - How to be prepared to APT
ISACA - Gestire progetti di Ethical Hacking secondo le best practices
OWASP AppSec EU 2016 - Security Project Management - How to be Agile in Secu...
Mamma, da grande voglio essere un Penetration Tester HackInBo 2016 Winter
Penetration Testing con Python - Network Sniffer
ORM Injection
Agile e Lean Management
Nuove minacce nella Cyber Security, come proteggersi
Hackers vs Developers - Cross Site Scripting (XSS) Attacco e difesa
Agile Lean Management - MoSCoW, Timeboxing e Kanban

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.

Attacking Ethereum Smart Contracts a deep dive after ~9 years of deployment

  • 1. OWASP FOUNDATION ® Attacking Ethereum Smart Contracts a deep dive after ~9 years of deployment Simone Onofri OWASP Italy Day 2023 Politecnico of Milan - 11th September 2023
  • 3. Open: Everything at OWASP is radically transparent from our finances to our code. Innovative: We encourage and support innovation and experiments for solutions to software security challenges. Global: Anyone around the world is encouraged to participate in the OWASP community. Integrity: Our community is respectful, supportive, truthful, and vendor neutral OWASP FOUNDATION owasp.org • What are Smart Contracts? • What are the most common vulnerabilities? • Conclusions Agenda
  • 4. Open: Everything at OWASP is radically transparent from our finances to our code. Innovative: We encourage and support innovation and experiments for solutions to software security challenges. Global: Anyone around the world is encouraged to participate in the OWASP community. Integrity: Our community is respectful, supportive, truthful, and vendor neutral OWASP FOUNDATION owasp.org • What are Smart Contracts? • What are the most common vulnerabilities? • Conclusions Agenda
  • 5. OWASP FOUNDATION owasp.org What are Smart Contracts? Are simply programs that runs on the Ethereum blockchain. It’s a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. https://ethereum.org/en/developers/docs/smart-contracts/
  • 6. OWASP FOUNDATION owasp.org How are Smart Contracts written? Turing-complete programming language that can be used to create “contracts” that can be used to encode arbitrary state transition functions [...]. The code in Ethereum contracts is written in a low-level, stack-based bytecode language, referred to as “Ethereum virtual machine code” or “EVM code”. The code consists of a series of bytes, where each byte represents an operation https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
  • 7. OWASP FOUNDATION owasp.org What can be done with Smart Contracts? systems which automatically move digital assets according to arbitrary pre-specified rules. For example, one might have a treasury contract of the form "A can withdraw up to X currency units per day, B can withdraw up to Y per day, A and B together can withdraw anything, and A can shut off B's ability to withdraw". […] https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
  • 10. OWASP FOUNDATION owasp.org What can be done with Smart Contracts? […] The logical extension of this is decentralized autonomous organizations (DAOs) - long-term smart contracts that contain the assets and encode the bylaws of an entire organization https://ethereum.org/669c9e2e2027310b6b3cdce6e1c52962/Ethereum_Whitepaper_-_Buterin_2014.pdf
  • 15. OWASP FOUNDATION owasp.org What are Blockchain characteristics and how do they impact security? ● Immutable: Transactions are irreversible, meaning they can’t be undone once an action has been taken. ● Public: Both contracts and transactions are publicly accessible through the blockchain. ● Deterministic: The execution of a smart contract must yield the same result on any node. ● Limited: Smart contracts cannot call upon external resources unless they use Oracles. ● Permissionless: Everyone can publish and interact with contracts.
  • 16. Open: Everything at OWASP is radically transparent from our finances to our code. Innovative: We encourage and support innovation and experiments for solutions to software security challenges. Global: Anyone around the world is encouraged to participate in the OWASP community. Integrity: Our community is respectful, supportive, truthful, and vendor neutral OWASP FOUNDATION owasp.org • What are Smart Contracts? • What are the most common vulnerabilities? • Conclusions Agenda
  • 17. OWASP FOUNDATION owasp.org OWASP Smart Contract Top 10 (2023) • Reentrancy Attacks • Integer Overflow and Underflow • Timestamp Dependence • Access Control Vulnerabilities • Front-running Attacks • Denial of Service (DoS) Attacks • Logic Errors • Insecure Randomness • Gas Limit Vulnerabilities • Unchecked External Calls
  • 18. OWASP FOUNDATION owasp.org OWASP Smart Contract Top 10 (2023) • Reentrancy Attacks • Integer Overflow and Underflow • Timestamp Dependence • Access Control Vulnerabilities • Front-running Attacks • Denial of Service (DoS) Attacks • Logic Errors • Insecure Randomness • Gas Limit Vulnerabilities • Unchecked External Calls
  • 20. OWASP FOUNDATION owasp.org Vulnerable Contract 0x6060604052361561008a576000357c0100000000000000000000000000000000000000000000000000000000900480 63095ea7b3146100b857806318160ddd146100ed57806323b872dd146101105780632e1a7d4d1461014e57806370a082 311461017a578063a9059cbb146101a6578063d0e30db0146101db578063dd62ed3e146101fe5761008a565b6100a25b 6000610098610887565b905061009f565b90565b6040518082815260200191505060405180910390f35b6100d7600480 803590602001909190803590602001909190505061061a565b6040518082815260200191505060405180910390f35b61 00fa6004805050610757565b6040518082815260200191505060405180910390f35b6101386004808035906020019091 9080359060200190919080359060200190919050506103df565b6040518082815260200191505060405180910390f35b 610164600480803590602001909190505061077b565b6040518082815260200191505060405180910390f35b61019060 04808035906020019091905050610233565b6040518082815260200191505060405180910390f35b6101c56004808035 906020019091908035906020019091905050610271565b6040518082815260200191505060405180910390f35b6101e8 6004805050610887565b6040518082815260200191505060405180910390f35b61021d60048080359060200190919080 359060200190919050506106ee565b6040518082815260200191505060405180910390f35b6000600060005060008373 ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060005054905061026c565b9190 50565b600081600060005060003373ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160 00206000505410156102af57610002565b6102e8600060005060008573ffffffffffffffffffffffffffffffffffffff ff168152602001908152602001600020600050548361091f565b15156102f357610002565b81600060005060003373ff ffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282825054039250508[…] https://etherscan.io/address/0xd654bDD32FC99471455e86C2E7f7D7b6437e9179 Opcodes: 0x60: PUSH1 EVM opcode 0x60: The free memory pointer 0x60: PUSH1 EVM opcode 0x40: Memory position for the free memory pointer MSTORE : EVM opcode is 0x52
  • 22. OWASP FOUNDATION owasp.org Decompiled withdraw function https://etherscan.io/address/0xd654bDD32FC99471455e86C2E7f7D7b6437e9179
  • 23. OWASP FOUNDATION owasp.org Attacker Contract by Nikolai Mushegian Decompiled https://etherscan.io/address/0x4AfB544Eb87265cF7Fc8fdB843c81d34F7E2A369
  • 25. OWASP FOUNDATION owasp.org OWASP Smart Contract Top 10 (2023) • Reentrancy Attacks • Integer Overflow and Underflow • Timestamp Dependence • Access Control Vulnerabilities • Front-running Attacks • Denial of Service (DoS) Attacks • Logic Errors • Insecure Randomness • Gas Limit Vulnerabilities • Unchecked External Calls
  • 29. OWASP FOUNDATION owasp.org Integer Overflow and Underflow An integer overflow occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. https://cwe.mitre.org/data/definitions/190.html
  • 30. OWASP FOUNDATION owasp.org Increment uint8 (2^8-1) in Solidity 0+1=1 1+1=2 2+1=3 […] 253+1=254 254+1= 255 255 + 1 = 0
  • 32. OWASP FOUNDATION owasp.org OWASP Smart Contract Top 10 (2023) • Reentrancy Attacks • Integer Overflow and Underflow • Timestamp Dependence • Access Control Vulnerabilities • Front-running Attacks • Denial of Service (DoS) Attacks • Logic Errors • Insecure Randomness • Gas Limit Vulnerabilities • Unchecked External Calls
  • 33. OWASP FOUNDATION owasp.org Abritrage CTF Admin has gifted you 5e18 Btokens on your birthday. Using A,B,C,D,E token pairs on swap contracts, increase your BTokens. Interface to Uniswap v2 https://quillctf.super.site/challenges/quillctf-x-quickswap/arbitrage
  • 34. OWASP FOUNDATION owasp.org Vulnerability Description Arbitrage arises when price discrepancies exist across different markets, trading pairs or Liquidity Pools for the same asset. However, trading fees, gas fees, and slippage must be considered. To evaluate arbitrage opportunities it is possible to evaluate the indirect and circular trade “paths”, starting from B and ending with B when the exchange rate is calculated from the quantity of different tokens present in each pool. B -> A -> C -> B B -> A -> D -> B B -> A -> E -> B B -> C -> A -> B B -> C -> D -> B B -> C -> E -> B B -> D -> A -> B B -> D -> C -> B B -> D -> E -> B B -> E -> A -> B B -> E -> C -> B B -> E -> D -> B https://docs.uniswap.org/contracts/v2/concepts/core-concepts/pools
  • 36. Open: Everything at OWASP is radically transparent from our finances to our code. Innovative: We encourage and support innovation and experiments for solutions to software security challenges. Global: Anyone around the world is encouraged to participate in the OWASP community. Integrity: Our community is respectful, supportive, truthful, and vendor neutral OWASP FOUNDATION owasp.org • What are Smart Contracts? • What are the most common vulnerabilities? • Conclusions Agenda
  • 37. OWASP FOUNDATION owasp.org Conclusions Smart Contract security is a composite problem that can be derived from: • Programming issues (e.g., arithmetic vulnerabilities). • Features of the blockchain (e.g., access control, weak sources of randomness). • Feature of the Platform (e.g., reentrancy, time dependence, frontrunning). But the main point is to understand the Business Logic of the Smart Contract we’re auditing.
  • 39. OWASP FOUNDATION owasp.org Thank you to our sponsors