Secure Smart Contract with Control Flow Integrity

Zhiyang Chen, Sidi Mohamed Beillahi, Pasha Barahimi, Cyrus Minwalla, Han Du, Andreas G. Veneris, Fan LongarXiv 2025 · DOI

Introduction

The decentralized finance (DeFi) ecosystem is built on the principle of composability, where modular smart contracts—often called "money legos"—interact to create complex financial instruments. While this modularity drives innovation, it also introduces significant security risks. Attackers frequently exploit inter-contract dependencies to execute "Frankenstein" transactions that bypass intended logic. Traditional security measures, such as static analysis and audits, often fail to account for the dynamic behaviors that emerge when unknown external contracts interact with a protocol.

To address these challenges, the CrossGuard framework introduces an on-chain defense mechanism that enforces Control Flow Integrity (CFI). By monitoring the "shape" of a transaction’s execution in real-time and comparing it against a whitelist of legitimate patterns, CrossGuard provides a robust shield against complex exploits like re-entrancy and oracle manipulation.

The CrossGuard Architecture

CrossGuard operates by tracking the sequence of function calls during a transaction. The system is built on three primary pillars:

  1. Instrumentation: Target smart contracts are modified to include "hooks." These hooks notify a central Guard Contract every time a protected function begins or ends.
  2. Dual-Variant Execution: To minimize gas overhead, CrossGuard implements two versions of every function. An _Untrusted version is used for external calls and triggers the guard mechanism, while a _Trusted version is reserved for internal protocol calls, bypassing the guard to save resources.
  3. The Guard Contract: This component acts as the system's brain, maintaining a whitelist of allowed control flow patterns represented as hashes of call sequences. If a transaction generates a pattern not found on the whitelist, the Guard Contract automatically reverts the transaction.
The CrossGuard architecture demonstrates how the Guard Contract records and validates control flow sequences across multiple contracts.

Simplification Heuristics

Raw call graphs are often too complex for efficient on-chain whitelisting. CrossGuard employs four key heuristics to simplify this data: pruning read-only calls (no SSTORE), standardizing common ERC20 operations, ignoring temporary storage writes (restore-on-exit), and focusing on "Read-After-Write" (RAW) dependencies where one call's logic depends on data modified by a previous call.

Evaluation and Datasets

The effectiveness of CrossGuard was evaluated using a comprehensive benchmark of 37 real-world DeFi exploits occurring between 2020 and 2024, including high-profile cases like bZx, CreamFi, and Beanstalk. To assess the risk of false positives, the authors analyzed 100,000 recent transactions from major protocols including AAVE, Lido, and Uniswap.

Key Results and Insights

The empirical study revealed that while benign transactions follow predictable, repetitive paths, attack transactions almost always introduce novel control flows. CrossGuard successfully identified and blocked 35 out of 37 (94.6%) analyzed hacks.

Benchmark results showing the detection performance of CrossGuard across various victim protocols and hack types.

Key performance metrics include:

  • Low False Positive Rate: The system maintained a tiny 0.26% false positive rate across the victim protocol datasets.
  • Efficiency: Optimized gas overhead averaged only 3.53%, outperforming existing industrial solutions.
  • Resilience: For 31 of the 35 blocked hacks, attackers could not bypass the defense by splitting their exploit into multiple transactions, as they typically relied on atomic operations like flash loans.

Limitations and Conclusion

Despite its high success rate, CrossGuard has limitations. It is currently unable to detect "trivial" single-call exploits, such as simple access control bugs or integer overflows, because these do not create a unique control flow signature. This accounted for the two missed hacks in the study (Bedrock_DeFi and Auctus). Additionally, protocol updates require administrators to manually update the whitelist of allowed flows.

In conclusion, CrossGuard demonstrates that enforcing Control Flow Integrity is a highly effective and efficient method for securing DeFi protocols against the inherent risks of composability. By focusing on the flow of execution rather than just the state, it provides a critical layer of defense that can protect contracts from day one.

Summary updated

BibTeX
@misc{chen2025secure,
  author = {Zhiyang Chen and Sidi Mohamed Beillahi and Pasha Barahimi and Cyrus Minwalla and Han Du and Andreas G. Veneris and Fan Long},
  title = {{Secure Smart Contract with Control Flow Integrity}},
  year = {2025},
  eprint = {2504.05509},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.05509},
}
Figure