kth.sePublications
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf
Securing Smart Contracts Against Business Logic Flaws
KTH, School of Electrical Engineering and Computer Science (EECS), Computer Science, Theoretical Computer Science, TCS.ORCID iD: 0000-0002-0069-0588
2025 (English)Doctoral thesis, comprehensive summary (Other academic)
Sustainable development
SDG 9: Industry, innovation and infrastructure
Abstract [en]

Blockchain smart contracts empower decentralized applications (DApps) by enabling trustless, transparent, and immutable transactions. However, this immutability means that flaws in design or implementation lead to irreversible and costly security breaches. Therefore, rigorous verification and analysis of smart contracts before deployment is crucial. Furthermore, since not all vulnerabilities are detectable pre-deployment, monitoring after deployment is equally critical.

One particularly challenging yet understudied class of vulnerabilities in smart contracts is business logic flaws (BLFs), which occur when the implemented logic deviates subtly but critically from the intended behavior. BLFs are challenging to detect because they often require a deep understanding of the intended business rules rather than merely code-level analysis. This class of vulnerabilities has largely been overlooked in existing literature. This thesis introduces a comprehensive framework to address vulnerabilities across the entire DApp security lifecycle from specification and pre-deployment analysis to post-deployment monitoring with an emphasis on detecting, preventing, and mitigating BLFs.

At its core, our work formalizes high-level business logic of contracts using Dynamic Condition Response (DCR) graphs. We categorize design patterns into low-level platform/implementation specific and high-level business logic design patterns. We formalize the high-level patterns such as time-based constraints and action dependencies into precise graphical formal models. These models provide developers with a clear visual blueprint of intended contract workflows. Formalized contracts not only facilitate automated verification and analysis but also lay the groundwork for our "model to mitigate" approach. In this methodology, smart contract functions are mapped to DCR activities and its logic is modeled using DCR relations to expose design flaws by making implicit assumptions about the code explicit. 

Complementing our design-phase contributions, we propose an off-chain monitoring tool that observes on-chain transactions. By mapping each transaction against the DCR-specified logic, this tool detects deviations from intended behavior without instrumenting the deployed contract. Furthermore, our method effectively detects complex cross-chain attacks and violations of the specified behavior to secure the increasingly popular cross-chain DApps.

We address the lack of concrete exploit scenarios for business logic vulnerabilities using Large Language Models (LLMs) to inject realistic BLFs into contracts and synthesize corresponding exploits. Our approach uses DCR-based formal specifications as guidance, ensuring that synthesized vulnerabilities are both representative and realistic.

Recognizing the need for rigorous invariants to enforce security, we develop a semantic invariant differencing tool that given two smart contract require/assert statements it produces a verdict of which one is stronger. Our experiments prove its effectiveness in filtering out redundant or weak invariants to enhance the usefulness of dynamically mined invariants. In parallel, acknowledging the pivotal role of blockchain oracle security, we propose an oracle data lifecycle model spanning from the creation of data to its deprecation. We systematically identify vulnerabilities at each stage of this model and survey mitigation strategies.

Collectively, these contributions provide an end-to-end approach to smart contract security by bridging formal design and analysis, dynamic monitoring, and invariant refinement to build more resilient decentralized applications.

Abstract [sv]

Blockchainbaserade smarta kontrakt ger stöd för decentraliserade applikationer (DApps) genom att möjliggöra tillitslösa, transparenta och oföränderliga transaktioner. Emellertid innebär denna oföränderlighet att brister i design eller implementering leder till oåterkalleliga och kostsamma säkerhetsincidenter. Därför är rigorös verifiering och analys av smarta kontrakt innan driftsättning avgörande. Vidare kan inte alla sårbarheter upptäckas på förhand, varför övervakning efter driftsättning också är kritiskt. 

En särskilt utmanande men tämligen outforskad klass av sårbarheter i smarta kontrakt är affärslogikbrister (BLF), som uppstår när den implementerade logiken avviker subtilt men kritiskt från det avsedda beteendet. BLF:er är svåra att upptäcka eftersom de ofta kräver en djup förståelse av de avsedda affärsreglerna snarare än enbart kodnivåanalys. Denna klass av sårbarheter har överlag förbisetts i befintlig litteratur. Den här avhandlingen introducerar ett omfattande ramverk för att hantera sårbarheter under hela säkerhetslivscykeln för DApps – från specifikation och analys före - till övervakning efter - driftsättning – med fokus på att upptäcka, förebygga och hindra BLF:er.

I grunden formaliserar vårt arbete affärslogik på hög nivå för kontrakt med hjälp av Dynamic Condition Response (DCR)-grafer. Vi kategoriserar designmönster som antingen lågnivå (plattforms- och implementeringsspecifika) eller högnivå (affärslogiska) designmönster. Vi formaliserar högnivåmönster, såsom tidsbaserade begränsningar och handlingsberoenden, med grafiska formella modeller. Dessa modeller ger utvecklare en tydlig visuell översikt över de avsedda kontraktsarbetsflödena.Formaliserade kontrakt underlättar inte bara automatiserad verifiering och analys utan lägger också grunden för vår "modellera för att hindra"-metod. I denna metod kopplas smarta kontraktsfunktioner till DCR-aktiviteter, och logiken modelleras med hjälp av DCR-relationer för att avslöja designfel genom att göra tidigare implicita antaganden om koden explicita. 

Som komplement till våra bidrag i designfasen föreslår vi ett off-chain-övervakningsverktyg som observerar on-chain-transaktioner. Genom att koppla varje transaktion mot den DCR-specificerade logiken upptäcker detta verktyg avvikelser från det avsedda beteendet utan att instrumentera det driftsatta kontraktet. Dessutom kan vår metod effektivt upptäcka komplexa cross-chain-attacker och överträdelser av specificerade beteenden, vilket bidrar till att öka säkerheten för de allt mer populära cross-chain DApps. Vi tar itu med bristen på konkreta exploateringsscenarier för BLF:er genom att använda stora språkmodeller (LLM) för att injicera realistiska BLF:er i kontrakt och syntetisera motsvarande exploateringar. Vårt angreppssätt använder DCR-baserade formella specifikationer som vägledning, vilket säkerställer att de syntetiserade sårbarheterna är både representativa och realistiska. 

Med insikten om behovet av rigorösa invarianter för att upprätthålla säkerhet utvecklar vi ett semantiskt verktyg för invariantdifferentiering som, givet två smarta kontraktsinvarianter, avgör vilken som är starkare. Våra experiment visar på verktygets effektivitet att filtrera bort redundanta eller svaga invarianter och därigenom ge mer användbara dynamiskt utvunna invarianter. Därutöver, beaktandes vikten av blockchain-orakelsäkerhet, föreslår vi en modell för datalivscykeln för orakel som löper från dataskapande till dess utfasning. Vi identifierar systematiskt sårbarheter i varje steg av denna modell och kartlägger hindrande strategier. 

Sammanfattningsvis erbjuder dessa bidrag ett helhetsangreppssätt för smart kontraktssäkerhet genom att koppla ihop formell design och analys, dynamisk övervakning samt förfining av invarianter – allt för att bygga mer motståndskraftiga decentraliserade applikationer.

Place, publisher, year, edition, pages
KTH Royal Institute of Technology, 2025. , p. 89
Series
TRITA-EECS-AVL ; 2025:56
Keywords [en]
Smart Contract, Vulnerability, Formal Specification, DCR Graphs, Business Logic Flaws
National Category
Computer Systems
Research subject
Computer Science
Identifiers
URN: urn:nbn:se:kth:diva-363085ISBN: 978-91-8106-288-5 (print)OAI: oai:DiVA.org:kth-363085DiVA, id: diva2:1956747
Public defence
2025-06-11, Kollegiesalen, Brinellvägen 6, 09:00 (English)
Opponent
Supervisors
Funder
Swedish Research Council
Note

QC 20250507

Available from: 2025-05-08 Created: 2025-05-07 Last updated: 2025-05-08Bibliographically approved
List of papers
1. Dynamic Vulnerability Detection on Smart Contracts Using Machine Learning
Open this publication in new window or tab >>Dynamic Vulnerability Detection on Smart Contracts Using Machine Learning
2021 (English)In: Proceedings Of Evaluation And Assessment In Software Engineering (EASE 2021), Association for Computing Machinery (ACM) , 2021, p. 305-312Conference paper, Published paper (Refereed)
Abstract [en]

In this work we propose Dynamit, a monitoring framework to detect reentrancy vulnerabilities in Ethereum smart contracts. The novelty of our framework is that it relies only on transaction metadata and balance data from the blockchain system; our approach requires no domain knowledge, code instrumentation, or special execution environment. Dynamit extracts features from transaction data and uses a machine learning model to classify transactions as benign or harmful. Therefore, not only can we find the contracts that are vulnerable to reentrancy attacks, but we also get an execution trace that reproduces the attack. Using a random forest classifier, our model achieved more than 90 percent accuracy on 105 transactions, showing the potential of our technique.

Place, publisher, year, edition, pages
Association for Computing Machinery (ACM), 2021
Keywords
Smart Contracts, Vulnerability Detection, Machine Learning for Dynamic Software Analysis, Ethereum, Blockchain
National Category
Computer Sciences Computer Systems
Identifiers
urn:nbn:se:kth:diva-308789 (URN)10.1145/3463274.3463348 (DOI)000744470000036 ()2-s2.0-85108912066 (Scopus ID)
Conference
Conference on Evaluation and Assessment in Software Engineering (EASE), JUN 21-24, 2021, Norwegian Univ Sci & Technol, ELECTR NETWORK
Note

Part of proceedings: ISBN 978-1-4503-9053-8

QC 20220214

Available from: 2022-02-14 Created: 2022-02-14 Last updated: 2025-05-07Bibliographically approved
2. Capturing Smart Contract Design with DCR Graphs
Open this publication in new window or tab >>Capturing Smart Contract Design with DCR Graphs
Show others...
2023 (English)In: Software Engineering and Formal Methods: 21st International Conference, SEFM 2023, Proceedings, Springer Science and Business Media Deutschland GmbH , 2023, p. 106-125Conference paper, Published paper (Refereed)
Abstract [en]

Smart contracts manage blockchain assets and embody business processes. However, mainstream smart contract programming languages such as Solidity lack explicit notions of roles, action dependencies, and time. Instead, these concepts are implemented in program code. This makes it very hard to design and analyze smart contracts. We argue that DCR graphs are a suitable formalization tool for smart contracts because they explicitly and visually capture the mentioned features. We utilize this expressiveness to show that many common high-level design patterns representing the underlying business processes in smart-contract applications can be naturally modeled this way. Applying these patterns shows that DCR graphs facilitate the development and analysis of correct and reliable smart contracts by providing a clear and easy-to-understand specification.

Place, publisher, year, edition, pages
Springer Science and Business Media Deutschland GmbH, 2023
Keywords
DCR Graphs, Design Patterns, Smart Contract Modelling
National Category
Computer Sciences
Identifiers
urn:nbn:se:kth:diva-340377 (URN)10.1007/978-3-031-47115-5_7 (DOI)001293530200007 ()2-s2.0-85177478118 (Scopus ID)
Conference
21st International Conference on Software Engineering and Formal Methods, SEFM 2023, Eindhoven, Netherlands, Kingdom of the, Nov 6 2023 - Nov 10 2023
Note

Part of ISBN 9783031471148

QC 20231204

Available from: 2023-12-04 Created: 2023-12-04 Last updated: 2025-05-07Bibliographically approved
3. From Creation to Exploitation: The Oracle Lifecycle
Open this publication in new window or tab >>From Creation to Exploitation: The Oracle Lifecycle
2024 (English)In: Proceedings - 2024 IEEE International Conference on Software Analysis, Evolution and Reengineering - Companion, SANER-C 2024, Institute of Electrical and Electronics Engineers (IEEE) , 2024, p. 23-34Conference paper, Published paper (Refereed)
Abstract [en]

Decentralized Finance (DeFi) systems leverage blockchain oracles to access off/on-chain data as a service. Therefore, maintaining the integrity of oracle data is essential. However, the integrity of these oracles data can be compromised through different attacks, and the effectiveness of these attacks varies depending on the specific stage of the oracle’s lifecycle. This work presents a comprehensive analysis of this lifecycle, identifying potential attack types and examining the efficacy of existing defense mechanisms. We propose a generalized model encompassing data creation, submission, consensus, election, and deprecation stages. We evaluate our model against seven recent high-profile DeFi exploits totaling $ 187 million. We have also studied bond systems as a preventive measure against at least a subset of oracle exploits. Our findings suggest that while bond systems increase the cost of attacks, thereby fortifying oracle data integrity against adversarial manipulations, they also require careful calibration to avoid hindering honest participation.

Place, publisher, year, edition, pages
Institute of Electrical and Electronics Engineers (IEEE), 2024
Keywords
Attack Mitigation, Blockchain Oracles, Bond Systems, Data Lifecycle, Decentralized Finance, Security
National Category
Software Engineering Computer Sciences
Identifiers
urn:nbn:se:kth:diva-353536 (URN)10.1109/SANER-C62648.2024.00009 (DOI)001298155000005 ()2-s2.0-85202600979 (Scopus ID)
Conference
2024 IEEE International Conference on Software Analysis, Evolution and Reengineering - Companion, SANER-C 2024, March 12-15, 2024, Rovaniemi, Finland
Note

Part of ISBN: 9798350351576

QC 20241008

Available from: 2024-09-19 Created: 2024-09-19 Last updated: 2025-05-07Bibliographically approved
4. HighGuard: Cross-Chain Business Logic Monitoring of Smart Contracts
Open this publication in new window or tab >>HighGuard: Cross-Chain Business Logic Monitoring of Smart Contracts
Show others...
2024 (English)In: PROCEEDINGS OF 2024 39TH ACM/IEEE INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING, ASE 2024, Association for Computing Machinery (ACM) , 2024, p. 2378-2381Conference paper, Published paper (Refereed)
Abstract [en]

Logical flaws in smart contracts are often exploited, leading to significant financial losses. Our tool, HighGuard, detects transactions that violate business logic specifications of smart contracts. HighGuard employs dynamic condition response (DCR) graph models as formal specifications to verify contract execution against these models. It is capable of operating in a cross-chain environment for detecting business logic flaws across different blockchain platforms. We demonstrate HighGuard's effectiveness in identifying deviations from specified behaviors in smart contracts without requiring code instrumentation or incurring additional gas costs. By using precise specifications in the monitor, HighGuard achieves detection without false positives. Our evaluation, involving 54 exploits, confirms HighGuard's effectiveness in detecting business logic vulnerabilities. Our open-source implementation of HighGuard and a screencast of its usage are available at: https://github.com/mojtaba-eshghie/HighGuard https://www.youtube.com/watch?v=sZYVV-slDaY

Place, publisher, year, edition, pages
Association for Computing Machinery (ACM), 2024
Series
IEEE ACM International Conference on Automated Software Engineering, ISSN 1527-1366
Keywords
Smart Contracts, DCR Graphs, Runtime Monitoring, Blockchain, Security
National Category
Computer Sciences
Identifiers
urn:nbn:se:kth:diva-361338 (URN)10.1145/3691620.3695356 (DOI)001353105400217 ()2-s2.0-85211650421 (Scopus ID)
Conference
39th ACM/IEEE International Conference on Automated Software Engineering (ASE), OCT 28-NOV 01, 2024, Sacramento, CA
Note

Part of ISBN 979-8-4007-1248-7

QC 20250317

Available from: 2025-03-17 Created: 2025-03-17 Last updated: 2025-05-07Bibliographically approved
5. Oracle-Guided Vulnerability Diversity and Exploit Synthesis of Smart Contracts Using LLMs
Open this publication in new window or tab >>Oracle-Guided Vulnerability Diversity and Exploit Synthesis of Smart Contracts Using LLMs
2024 (English)In: PROCEEDINGS OF 2024 39TH ACM/IEEE INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING, ASE 2024, Association for Computing Machinery (ACM) , 2024, p. 2240-2244Conference paper, Published paper (Refereed)
Abstract [en]

Many smart contracts are prone to exploits, which has given rise to analysis tools that try to detect and fix vulnerabilities. Such analysis tools are often trained and evaluated on limited data sets, which has the following drawbacks: 1. The ground truth is often based on the verdict of related tools rather than an actual verification result; 2. Data sets focus on low-level vulnerabilities like reentrancy and overflow; 3. Data sets lack concrete exploit examples. To address these shortconUngs, we introduce XruiGEN, which uses a model-based oracle specification of the business logic of the smart contracts to synthesize valid exploits using LLMs. Our experiments, involving 104 synthesized vulnerability-exploit pairs, demonstrated a 57% success rate in exploiting targeted aspects of the contract. They achieved exploit efficiency with an average of only 3.5 transactions per exploit, highlighting the effectiveness of our methodology.

Place, publisher, year, edition, pages
Association for Computing Machinery (ACM), 2024
Series
IEEE ACM International Conference on Automated Software Engineering, ISSN 1527-1366
Keywords
Exploit Synthesis, Smart Contract, Vulnerability, LLM, Large Language Models
National Category
Computer Sciences
Identifiers
urn:nbn:se:kth:diva-361330 (URN)10.1145/3691620.3695292 (DOI)001353105400188 ()2-s2.0-85211646919 (Scopus ID)
Conference
39th ACM/IEEE International Conference on Automated Software Engineering (ASE), OCT 28-NOV 01, 2024, Sacramento, CA
Note

Part of ISBN 979-8-4007-1248-7

QC 20250317

Available from: 2025-03-17 Created: 2025-03-17 Last updated: 2025-05-07Bibliographically approved
6. Formalizing Smart Contract Design Patterns with DCR Graphs
Open this publication in new window or tab >>Formalizing Smart Contract Design Patterns with DCR Graphs
Show others...
(English)Manuscript (preprint) (Other academic)
Abstract [en]

Smart contracts manage blockchain assets and embody business processes, yet mainstream languages lack explicit support for process concepts like roles, action dependencies, and time constraints leading to implementation complexity and analysis challenges. To address this, we utilize Dynamic Condition Response (DCR) graphs, a formal business process modeling language to formalize business logic semantics of smart contracts. Modeling smart contracts in DCR graphs involves translating its underlying behavioral logic—the "what" it does, not the "how" it is implemented in detail—into a declarative visual model using DCR's explicit constructs for events, roles, data, time, and inter-event relationships. Furthermore, we systematically model 15 common high-level smart contract design patterns, representing recurring solutions for business logic-level problems. These formalizations reduce ambiguity compared to informal descriptions, and serve as language-independent specifications. We demonstrate modeling process using three complete smart contract case studies, combining six design patterns. Our modeling methodology and formlizations enable future automated analysis and verification.

Keywords
Smart Contract Modeling, DCR Graphs, Design Patterns Formalization
National Category
Computer Systems
Research subject
Computer Science
Identifiers
urn:nbn:se:kth:diva-363065 (URN)
Funder
Swedish Research Council, 3407
Note

QC 20250505

Available from: 2025-05-05 Created: 2025-05-05 Last updated: 2025-05-07Bibliographically approved
7. Model to Mitigate: Using DCR Graphs to Prevent Vulnerabilities in Smart Contracts
Open this publication in new window or tab >>Model to Mitigate: Using DCR Graphs to Prevent Vulnerabilities in Smart Contracts
Show others...
(English)Manuscript (preprint) (Other academic)
Abstract [en]

We propose a "Model to Mitigate" methodology: designing a platform-agnostic model of smart contract business logic and analyzing it before implementation. Using Dynamic Condition Response (DCR) graphs—originally for modeling business processes—we formally specify smart contracts. Our method captures high-level properties like event ordering, role-based access control, and time constraints to prevent design-rooted vulnerabilities. While we verify our approach on existing smart contracts (i.e., post-implementation scenarios), the proposed methodology is applicable during design time (pre-development). Our method applied on real-world exploited and audited smart contracts yields six key insights to enhance smart contract security and efficiency.  

Keywords
Smart Contract Security, DCR Graphs, Vulnerability Prevention, Blockchain, Declarative Business Logic Modeling, Decentralized Applications (dApps)
National Category
Computer Systems
Research subject
Computer Science
Identifiers
urn:nbn:se:kth:diva-363067 (URN)
Funder
Swedish Research Council, 3407
Note

QC 20250505

Available from: 2025-05-05 Created: 2025-05-05 Last updated: 2025-05-07Bibliographically approved
8. SInDi: Semantic Invariant Differencing For Solidity Smart Contracts
Open this publication in new window or tab >>SInDi: Semantic Invariant Differencing For Solidity Smart Contracts
(English)Manuscript (preprint) (Other academic)
Abstract [en]

Advancements in invariants-based smart contract analysis and verification call for tools that reliably and efficiently check semantic difference between invariants.These invariants, logical expressions that should hold in blockchain transactions are enforced through require/assert statements in Solidity smart contracts.  We present SInDi, a semantic invariant differencing tool for Solidity contracts that symbolically checks the differences of any two given invariants and quickly generates a verdict. Our evaluation on real-world smart contracts demonstrates SInDi's accuracy of 100% and efficiency of 0.09 seconds on average per verdict compared to human verdicts. Furthermore, we develop an invariant denoising pipeline based on SInDi that effectively removes up to 41.8% of weak dynamically-mined invariants to facilitate further analysis and verification tasks based on these auto-generated invariants.

Keywords
Invariants, Symbolic Analysis, Semantic Equivalence, Smart Contracts, Pre-/Post-Conditions
National Category
Computer Systems
Research subject
Computer Science
Identifiers
urn:nbn:se:kth:diva-363066 (URN)
Funder
Swedish Research Council, 3407
Note

QC 20250505

Available from: 2025-05-05 Created: 2025-05-05 Last updated: 2025-05-07Bibliographically approved

Open Access in DiVA

Securing Smart Contracts Against Business Logic Flaws(2705 kB)65 downloads
File information
File name FULLTEXT01.pdfFile size 2705 kBChecksum SHA-512
ad0d8299fd43bc899f76c3be206905a102bdfbe65d6431e87b143577fbe7c41e48cdf1fac7832e0547fa28ea34d39b617bef760025863a48d83775b9ef56cc3b
Type fulltextMimetype application/pdf

Authority records

Eshghie, Mojtaba

Search in DiVA

By author/editor
Eshghie, Mojtaba
By organisation
Theoretical Computer Science, TCS
Computer Systems

Search outside of DiVA

GoogleGoogle Scholar
Total: 65 downloads
The number of downloads is the sum of all downloads of full texts. It may include eg previous versions that are now no longer available

isbn
urn-nbn

Altmetric score

isbn
urn-nbn
Total: 1938 hits
CiteExportLink to record
Permanent link

Direct link
Cite
Citation style
  • apa
  • ieee
  • modern-language-association-8th-edition
  • vancouver
  • Other style
More styles
Language
  • de-DE
  • en-GB
  • en-US
  • fi-FI
  • nn-NO
  • nn-NB
  • sv-SE
  • Other locale
More languages
Output format
  • html
  • text
  • asciidoc
  • rtf