Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/3658644.3690293acmconferencesArticle/Chapter ViewAbstractPublication PagesccsConference Proceedingsconference-collections
research-article
Open access

FORAY: Towards Effective Attack Synthesis against Deep Logical Vulnerabilities in DeFi Protocols

Published: 09 December 2024 Publication History

Abstract

Blockchain adoption has surged with the rise of Decentralized Finance (DeFi) applications. However, the significant value of digital assets managed by DeFi protocols makes them prime targets for attacks. Current smart contract vulnerability detection tools struggle with DeFi protocols due to deep logical bugs arising from complex financial interactions between multiple smart contracts. These tools primarily analyze individual contracts and resort to brute-force methods for DeFi protocols crossing numerous smart contracts, leading to inefficiency.
We introduce FORAY, a highly effective attack synthesis framework against deep logical bugs in DeFi protocols. FORAY proposes a novel attack sketch generation and completion framework. Specifically, instead of treating DeFis as regular programs, we design a domain-specific language (DSL) to lift the low-level smart contracts into their high-level financial operations. Based on our DSL, we first compile a given DeFi protocol into a token flow graph, our graphical representation of DeFi protocols. Then, we design an efficient sketch generation method to synthesize attack sketches for a certain attack goal (e.g., price manipulation, arbitrage, etc.). This algorithm strategically identifies candidate sketches by finding reachable paths in Token Flow Graph (TFG), which is much more efficient than random enumeration. For each candidate sketch written in our DSL, FORAY designs a domain-specific symbolic compilation to compile it into SMT constraints. Our compilation simplifies the constraints by removing redundant smart contract semantics. It maintains the usability of symbolic compilation, yet scales to problems orders of magnitude larger. Finally, the candidates are completed via existing solvers and are transformed into concrete attacks via direct syntax transformation. Through extensive experiments on real-world security incidents, we demonstrate that FORAY significantly outperforms Halmos and ItyFuzz, the state-of-the-art (SOTA) tools for smart contract vulnerability detection, in both effectiveness and efficiency. Specifically, out of 34 benchmark DeFi logical bugs that happened in the last two years, FORAY synthesizes 27 attacks, whereas ItyFuzz and Halmos only synthesize 11 and 3, respectively. Furthermore, FORAY also finds ten zero-day vulnerabilities in the BNB chain. Finally, we demonstrate the effectiveness of our key components and FORAY's capability of avoiding false positives.

References

[1]
1inch. 2023. One-stop access to decentralized finance. https://1inch.io/.
[2]
a16z. 2023. Halmos: A symbolic testing tool for EVM smart contracts. https://github.com/a16z/halmos.
[3]
AAVE. 2023. Aave: Open Source Liquidity Protocol. https://aave.com/.
[4]
Elvira Albert, Shelly Grossman, Noam Rinetzky, Clara Rodríguez-Nú nez, Albert Rubio, and Mooly Sagiv. 2020. Taming Callbacks for Smart Contract Modularity. Proc. ACM Program. Lang., Vol. 4, OOPSLA, Article 209 (nov 2020), 30 pages. https://doi.org/10.1145/3428277
[5]
Glenn Ammons, Rastislav Bodík, and James R Larus. 2002. Mining specifications. In Proceedings of the 29th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (Portland, Oregon) (POPL '02). Association for Computing Machinery, New York, NY, USA, 4--16.
[6]
Thanassis Avgerinos, Sang Kil Cha, Alexandre Rebert, Edward J Schwartz, Maverick Woo, and David Brumley. 2014. Automatic exploit generation. Commun. ACM, Vol. 57, 2 (2014), 74--84.
[7]
Binance Smart Chain Developers. 2017. Binance Smart Chain Whitepaper. https://github.com/bnb-chain/whitepaper/blob/master/WHITEPAPER.md.
[8]
Sam Blackshear, Evan Cheng, David L Dill, Victor Gao, Ben Maurer, Todd Nowacki, Alistair Pott, Shaz Qadeer, Dario Russi Rain, Stephane Sezer, et al. 2019. Move: A language with programmable resources. Libra Assoc (2019), 1.
[9]
blockworks. 2023. Mango Markets Mangled by Oracle Manipulation for 112M. https://blockworks.co/news/mango-markets-mangled-by-oracle-manipulation-for-112m/.
[10]
Priyanka Bose, Dipanjan Das, Yanju Chen, Yu Feng, and Christopher Kruegel. 2022. SAILFISH: Vetting Smart Contract State-Inconsistency Bugs in Seconds. In 2022 IEEE Symposium on Security and Privacy (SP).
[11]
CertiK. 2023. Hack3d: The Web3 Security Report 2023. https://www.certik.com/resources/blog/7BokMhPUgffqEvyvXgHNaq-hack3d-the-web3-security-report-2023. Accessed: 2024-07--24.
[12]
Sang Kil Cha, Thanassis Avgerinos, Alexandre Rebert, and David Brumley. 2012. Unleashing mayhem on binary code. In 2012 IEEE Symposium on Security and Privacy. IEEE, 380--394.
[13]
Jiaqi Chen, Yibo Wang, Yuxuan Zhou, Wanning Ding, Yuzhe Tang, XiaoFeng Wang, and Kai Li. 2023. Understanding the Security Risks of Decentralized Exchanges by Uncovering Unfair Trades in the Wild. In 2023 IEEE 8th European Symposium on Security and Privacy (EuroS&P). 332--351. https://doi.org/10.1109/EuroSP57164.2023.00028
[14]
Ting Chen, Yufei Zhang, Zihao Li, Xiapu Luo, Ting Wang, Rong Cao, Xiuzhuo Xiao, and Xiaosong Zhang. 2019. TokenScope: Automatically Detecting Inconsistent Behaviors of Cryptocurrency Tokens in Ethereum. In Proceedings of the 2019 ACM SIGSAC Conference on Computer and Communications Security (London, United Kingdom) (CCS '19). Association for Computing Machinery, New York, NY, USA, 1503--1520. https://doi.org/10.1145/3319535.3345664
[15]
Yanju Chen, Junrui Liu, Yu Feng, and Rastislav Bodik. 2022. Tree Traversal Synthesis Using Domain-Specific Symbolic Compilation. In Proceedings of the 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems (Lausanne, Switzerland) (ASPLOS '22). Association for Computing Machinery, New York, NY, USA, 1030--1042.
[16]
Yanju Chen, Chenglong Wang, Osbert Bastani, Isil Dillig, and Yu Feng. 2020. Program Synthesis Using Deduction-Guided Reinforcement Learning. In Computer Aided Verification, Shuvendu K Lahiri and Chao Wang (Eds.). Springer International Publishing, Cham, 587--610.
[17]
Zhiyang Chen, Sidi Mohamed Beillahi, and Fan Long. 2022. FlashSyn: Flash Loan Attack Synthesis via Counter Example Driven Approximation. arxiv: 2206.10708 [cs.PL]
[18]
Jaeseung Choi, Doyeon Kim, Soomin Kim, Gustavo Grieco, Alex Groce, and Sang Kil Cha. 2021. SMARTIAN: Enhancing Smart Contract Fuzzing with Static and Dynamic Data-Flow Analyses. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE). 227--239. https://doi.org/10.1109/ASE51524.2021.9678888
[19]
ConsenSys. 2020. Mythril: Security Analysis Tool for Ethereum Smart Contracts. https://github.com/ConsenSys/mythril.
[20]
Leonardo de Moura and Nikolaj Bjørner. 2008. Z3: An Efficient SMT Solver. In Tools and Algorithms for the Construction and Analysis of Systems. Springer Berlin Heidelberg, 337--340.
[21]
decrypt. 2023. Zunami Protocol Loses Over 2.1 Million in Price Manipulation Hack. https://decrypt.co/152366/zunami-protocol-curve-finance-hack/.
[22]
DeFi Prime. 2023. Ethereum DeFi Ecosystem. https://defiprime.com/ethereum
[23]
DeFiHackLabs. 2023. DeFi Hacks Reproduce - Foundry. https://github.com/SunWeb3Sec/DeFiHackLabs.
[24]
defillama. 2023. DefiLlama - DeFi Dashboard. https://defillama.com/.
[25]
DYDX. 2023. dYdX: Trade Perpetuals on the most powerful trading platform. https://dydx.exchange/.
[26]
Moritz Eckert, Antonio Bianchi, Ruoyu Wang, Yan Shoshitaishvili, Christopher Kruegel, and Giovanni Vigna. 2018. HeapHopper: Bringing bounded model checking to heap implementation security. In 27th USENIX Security Symposium (USENIX Security 18). 99--116.
[27]
William Entriken, Dieter Shirley, Jacob Evans, and Nastassia Sachs. 2018. ERC-721: Non-Fungible Token Standard. Ethereum Improvement Proposals. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-721.
[28]
Josselin Feist, Gustavo Grieco, and Alex Groce. 2019. Slither: A Static Analysis Framework for Smart Contracts. In 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB). IEEE. https://doi.org/10.1109/wetseb.2019.00008
[29]
Yu Feng, Ruben Martins, Osbert Bastani, and Isil Dillig. 2018. Program Synthesis Using Conflict-Driven Learning. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (Philadelphia, PA, USA) (PLDI 2018). Association for Computing Machinery, New York, NY, USA, 420--435.
[30]
Yu Feng, Ruben Martins, Jacob Van Geffen, Isil Dillig, and Swarat Chaudhuri. 2017. Component-Based Synthesis of Table Consolidation and Transformation Tasks from Examples. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (Barcelona, Spain) (PLDI 2017). Association for Computing Machinery, New York, NY, USA, 422--436.
[31]
Yu Feng, Emina Torlak, and Rastislav Bodik. 2021. Summary-Based Symbolic Evaluation for Smart Contracts. In Proceedings of the 35th IEEE/ACM International Conference on Automated Software Engineering (Virtual Event, Australia) (ASE '20). Association for Computing Machinery, New York, NY, USA, 1141--1152. https://doi.org/10.1145/3324884.3416646
[32]
foundry team. 2021. Foundry: A Blazing Fast, Portable and Modular Toolkit for Ethereum Application Development. https://github.com/foundry-rs/foundry.
[33]
Neville Grech, Michael Kong, Anton Jurisevic, Lexi Brent, Bernhard Scholz, and Yannis Smaragdakis. 2018. MadMax: Surviving out-of-Gas Conditions in Ethereum Smart Contracts. Proc. ACM Program. Lang., Vol. 2, OOPSLA, Article 116 (oct 2018), 27 pages. https://doi.org/10.1145/3276486
[34]
Shelly Grossman, Ittai Abraham, Guy Golan-Gueta, Yan Michalevsky, Noam Rinetzky, Mooly Sagiv, and Yoni Zohar. 2017. Online Detection of Effectively Callback Free Objects with Applications to Smart Contracts. Proc. ACM Program. Lang., Vol. 2, POPL, Article 48 (dec 2017), 28 pages. https://doi.org/10.1145/3158136
[35]
Lewis Gudgeon, Daniel Perez, Dominik Harz, Benjamin Livshits, and Arthur Gervais. 2020. The Decentralized Financial Crisis. arxiv: 2002.08099 [cs.CR]
[36]
Zheng Guo, Michael James, David Justo, Jiaxiao Zhou, Ziteng Wang, Ranjit Jhala, and Nadia Polikarpova. 2019. Program synthesis by type-guided abstraction refinement. Proc. ACM Program. Lang., Vol. 4, POPL (Dec. 2019), 1--28.
[37]
Bo Jiang, Ye Liu, and W. K. Chan. 2018. ContractFuzzer: Fuzzing Smart Contracts for Vulnerability Detection. In Proceedings of the 33rd ACM/IEEE International Conference on Automated Software Engineering (Montpellier, France) (ASE '18). Association for Computing Machinery, New York, NY, USA, 259--269. https://doi.org/10.1145/3238147.3238177
[38]
Queping Kong, Jiachi Chen, Yanlin Wang, Zigui Jiang, and Zibin Zheng. 2023. DeFiTainter: Detecting Price Manipulation Vulnerabilities in DeFi Protocols. In Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis (Seattle, WA, USA) (ISSTA 2023). Association for Computing Machinery, New York, NY, USA, 1144--1156. https://doi.org/10.1145/3597926.3598124
[39]
Tien-Duy B Le and David Lo. 2018. Deep specification mining. In Proceedings of the 27th ACM SIGSOFT International Symposium on Software Testing and Analysis (Amsterdam, Netherlands) (ISSTA 2018). Association for Computing Machinery, New York, NY, USA, 106--117.
[40]
Lido. 2023. Lido - Liquid Staking for Digital Tokens. https://lido.fi/.
[41]
Junrui Liu, Yanju Chen, Eric Atkinson, Yu Feng, and Rastislav Bodik. 2023. Conflict-Driven Synthesis for Layout Engines. Proc. ACM Program. Lang., Vol. 7, PLDI (June 2023).
[42]
Loi Luu, Duc-Hiep Chu, Hrishi Olickel, Prateek Saxena, and Aquinas Hobor. 2016. Making Smart Contracts Smarter. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security (Vienna, Austria) (CCS '16). Association for Computing Machinery, New York, NY, USA, 254--269. https://doi.org/10.1145/2976749.2978309
[43]
MakerDAO. 2023. MakerDAO: An Unbiased Global Financial System. https://makerdao.com/.
[44]
David Mandelin, Lin Xu, Rastislav Bodík, and Doug Kimelman. 2005. Jungloid Mining: Helping to Navigate the API Jungle. In Proceedings of the 2005 ACM SIGPLAN Conference on Programming Language Design and Implementation (Chicago, IL, USA) (PLDI '05). Association for Computing Machinery, New York, NY, USA, 48--61. https://doi.org/10.1145/1065010.1065018
[45]
Merkle Science. 2022. Hack Track: Analysis of the BNB Smart Chain Exploit. https://blog.merklescience.com/general/hack-track-analysis-of-the-bnb-smart-chain-exploit. Accessed: 2024-07--24.
[46]
Mark Mossberg, Felipe Manzano, Eric Hennenfent, Alex Groce, Gustavo Grieco, Josselin Feist, Trent Brunson, and Artem Dinaburg. 2019. Manticore: A User-Friendly Symbolic Execution Framework for Binaries and Smart Contracts. In 2019 34th IEEE/ACM International Conference on Automated Software Engineering (ASE). 1186--1189. https://doi.org/10.1109/ASE.2019.00133
[47]
Tai D. Nguyen, Long H. Pham, Jun Sun, Yun Lin, and Quang Tran Minh. 2020. SFuzz: An Efficient Adaptive Fuzzer for Solidity Smart Contracts. In Proceedings of the ACM/IEEE 42nd International Conference on Software Engineering (Seoul, South Korea) (ICSE '20). Association for Computing Machinery, New York, NY, USA, 778--788. https://doi.org/10.1145/3377811.3380334
[48]
Maria Leonor Pacheco, Max von Hippel, Ben Weintraub, Dan Goldwasser, and Cristina Nita-Rotaru. 2022. Automated Attack Synthesis by Extracting Finite State Machines from Protocol Specification Documents. arxiv: 2202.09470 [cs.CR]
[49]
PancakeSwap. 2023. Everyone's Favorite DEX. https://pancakeswap.finance/.
[50]
Phitchaya Mangpo Phothilimthana, Michael Schuldt, and Rastislav Bodik. 2016. Compiling a Gesture Recognition Application for a Low-Power Spatial Architecture. SIGPLAN Not., Vol. 51, 5 (jun 2016), 102--112. https://doi.org/10.1145/2980930.2907962
[51]
Witek Radomski, Andrew Cooke, Philippe Castonguay, James Therien, Eric Binet, and Ronan Sandford. 2018. ERC-1155: Multi Token Standard. Ethereum Improvement Proposals. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-1155.
[52]
Chaofan Shou, Shangyin Tan, and Koushik Sen. 2023. ItyFuzz: Snapshot-Based Fuzzer for Smart Contract. In Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis (Seattle, WA, USA) (ISSTA 2023). Association for Computing Machinery, New York, NY, USA, 322--333. https://doi.org/10.1145/3597926.3598059
[53]
Armando Solar-Lezama, Liviu Tancau, Rastislav Bodik, Sanjit Seshia, and Vijay Saraswat. 2006. Combinatorial sketching for finite programs. In Proceedings of the 12th international conference on Architectural support for programming languages and operating systems (San Jose, California, USA) (ASPLOS XII). Association for Computing Machinery, New York, NY, USA, 404--415.
[54]
solidityscan. 2023. ROE Finance hack Analysis ' Price Manipulation. https://blog.solidityscan.com/roe-finance-hack-analysis-price-manipulation-6993fbea0d7c/.
[55]
Tether Developers. 2014. Tether: Fiat currencies on the Bitcoin blockchain. https://tether.to/en/.
[56]
Emina Torlak and Rastislav Bodik. 2014. A Lightweight Symbolic Virtual Machine for Solver-Aided Host Languages. In Proceedings of the 35th ACM SIGPLAN Conference on Programming Language Design and Implementation (Edinburgh, United Kingdom) (PLDI '14). Association for Computing Machinery, New York, NY, USA, 530--541.
[57]
Petar Tsankov, Andrei Dan, Dana Drachsler-Cohen, Arthur Gervais, Florian Bünzli, and Martin Vechev. 2018. Securify: Practical Security Analysis of Smart Contracts. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security (Toronto, Canada) (CCS '18). Association for Computing Machinery, New York, NY, USA, 67--82. https://doi.org/10.1145/3243734.3243780
[58]
Uniswap. 2023. The Uniswap Protocol. https://uniswap.org/.
[59]
Fabian Vogelsteller and Vitalik Buterin. 2015. ERC-20: Token Standard. Ethereum Improvement Proposals 20 (Nov 2015). [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-20.
[60]
Michelle Y Wong and David Lie. 2016. Intellidroid: a targeted input generator for the dynamic analysis of android malware. In NDSS, Vol. 16. 21--24.
[61]
Gavin Wood et al. 2014. Ethereum: A secure decentralised generalised transaction ledger. Ethereum project yellow paper, Vol. 151, 2014 (2014), 1--32.
[62]
Siwei Wu, Dabao Wang, Jianting He, Yajin Zhou, Lei Wu, Xingliang Yuan, Qinming He, and Kui Ren. 2021. DeFiRanger: Detecting Price Manipulation Attacks on DeFi Applications. arxiv: 2104.15068 [cs.CR]
[63]
Valentin Wüstholz and Maria Christakis. 2020. Harvey: A Greybox Fuzzer for Smart Contracts. In Proceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (Virtual Event, USA) (ESEC/FSE 2020). Association for Computing Machinery, New York, NY, USA, 1398--1409. https://doi.org/10.1145/3368089.3417064
[64]
Anatoly Yakovenko. 2018. Solana: A new architecture for a high performance blockchain. Whitepaper (2018).
[65]
Zhuo Zhang, Brian Zhang, Wen Xu, and Zhiqiang Lin. 2023. Demystifying exploitable bugs in smart contracts. In 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE). IEEE, 615--627.
[66]
L Zhou, K Qin, A Cully, B Livshits, and A Gervais. 2021. On the just-in-time discovery of profit-generating transactions in DeFi Protocols. 919--936. https://doi.org/10.1109/SP40001.2021.00113
[67]
Liyi Zhou, Xihan Xiong, Jens Ernstberger, Stefanos Chaliasos, Zhipeng Wang, Ye Wang, Kaihua Qin, Roger Wattenhofer, Dawn Song, and Arthur Gervais. 2023. Sok: Decentralized finance (defi) attacks. In 2023 IEEE Symposium on Security and Privacy (SP). IEEE, 2444--2461.

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
CCS '24: Proceedings of the 2024 on ACM SIGSAC Conference on Computer and Communications Security
December 2024
5188 pages
ISBN:9798400706363
DOI:10.1145/3658644
This work is licensed under a Creative Commons Attribution International 4.0 License.

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 09 December 2024

Check for updates

Author Tags

  1. attack synthesis
  2. blockchain
  3. defi
  4. smart contract

Qualifiers

  • Research-article

Funding Sources

Conference

CCS '24
Sponsor:

Acceptance Rates

Overall Acceptance Rate 1,261 of 6,999 submissions, 18%

Upcoming Conference

CCS '25

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 297
    Total Downloads
  • Downloads (Last 12 months)297
  • Downloads (Last 6 weeks)142
Reflects downloads up to 18 Feb 2025

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media