Research
LogicScan: An LLM-driven Framework for Detecting Business Logic Vulnerabilities in Smart Contracts
Business logic vulnerabilities are flaws in a protocol's design-level rules, such as a missing check on a user's debt health before their collateral is reduced, and they have caused the largest…

- arXiv
- 2602.03271
- Published
- 2026-02-03
- Authors
- Jiaqi Gao, Zijian Zhang, Yuqiang Sun, Ye Liu, Chengwei Liu, Han Liu, Yi Li, Yang Liu
AI summary
Overview
- Research area: Blockchain security, specifically automated detection of business logic vulnerabilities in Ethereum smart contracts using large language models (LLMs).
- Technical level: Advanced. The paper assumes familiarity with Solidity, smart contract invariants, static analysis tooling, and LLM prompting pipelines.
- Scope: The paper presents LogicScan, a two-stage framework (Logic Miner and Logic Checker) that mines business logic invariants from large volumes of deployed on-chain contracts and reuses them as reference constraints to audit target contracts for missing or weakly enforced checks.
What This Paper Is About
Business logic vulnerabilities are flaws in a protocol's design-level rules, such as a missing check on a user's debt health before their collateral is reduced, and they have caused the largest losses in DeFi. Existing static analysers look for fixed bug patterns, dynamic fuzzers rarely trigger these flaws, and earlier LLM-based tools tend to hallucinate or overfit to documented specifications. LogicScan's goal is to detect such flaws without hand-written rules, by treating the constraints that mature, widely used protocols already enforce as consensus "reference invariants" and flagging target contracts that omit them.
Key Contributions
- Contrastive auditing framework: An LLM-driven approach that induces business logic invariants from real-world on-chain projects and uses deviation from those consensus invariants as a signal for potential logic vulnerabilities, rather than relying on expert-written property specifications.
- Business Specification Language (BSL): A verifiable intermediate representation that normalizes diverse Solidity guard patterns (
assert,require, andif ... revert, with negative logic inverted into positive assertions) into a structuredcheckCondition* → call(LogicFunc)form, paired with a dual syntactic and semantic validation mechanism to curb hallucination. - Noise-aware logic aggregation: A voting scheme over retrieved template functions that canonicalizes synonymous invariant names via a domain knowledge dictionary and prunes invariants lacking majority support (frequency below ⌈k/2⌉), addressing template diversity and conflicting rules.
- Implementation and evaluation: LogicScan is evaluated on DeFiHacks, Web3Bugs, and a Top-200 market-cap contract set, reaching an F1 score of 85.2% and outperforming GPTScan, Slither, and ZepScope, plus a comparison against GPT-5.2 thinking.
Main Findings
- Headline detection performance: LogicScan achieves an F1 score of 85.2%, described as significantly outperforming state-of-the-art tools.
- Recall on real exploited contracts: It detects 94.3% of vulnerable cases from the DeFiHacks dataset.
- False positives on production code: It maintains a 7.1% false-positive rate on production-grade (Top-200) contracts.
- Scale of invariant mining: From 817,772 Ethereum contracts, filtering to the top 20% by both deployed time and transaction volume yielded 43,749 active contracts used as the invariant source corpus.
- Dictionary construction: Extracting all logical check conditions from the generated BSL corpus produced more than 62,000 distinct invariant conditions; the top 2,000 most frequent were selected as the basis for a manually curated synonym dictionary.
- Retrieval calibration: An empirical stability analysis found that correct self-retrieval occurs within the top five results in over 90% of cases, motivating a top-5 retrieval threshold, with candidate templates scoring below 80% similarity discarded.
- Cross-model stability: Additional experiments report consistent performance across different LLMs, indicating the approach is not tied to a single model, and that it is cost-effective; specific cost figures are not reported in the provided content.
- Ablation results: The paper states that its false-positive suppression mechanisms (multi-dimensional code extraction and noise-aware aggregation) substantially improve robustness, and that LogicScan behaves comparably or favourably on the RQ4 ablation, though the per-variant numbers are not included in the truncated content.
- Baseline comparisons: GPTScan was re-run with GPT-3.5-turbo and its original hyperparameters for fairness; PropertyGPT was not compared because it has no publicly available artifacts.
Methodology in Plain English
The approach rests on one observation, illustrated with the March 2023 Euler Finance incident (approximately $197 million lost), where a donateToReserves function burned a user's tokens without checking their Health Factor. A mature lending pool performing the equivalent collateral reduction (executeWithdraw) does enforce that check, so the missing check is a deviation from what the ecosystem already agrees on.
LogicScan turns this into a pipeline:
- Collect and filter contracts. Verified Ethereum contracts are stripped of inactive, proxy-only, interface, and library contracts, and only the most long-lived and heavily used ones are kept.
- Categorise by business role. Contract names are tokenized (e.g.
Token,Pool,Vault,Farm) to assign coarse business categories, since invariants only make sense within the same scenario. - Mine invariants. For each public function, the full internal call chain is expanded and a lightweight LLM writes a functional description, a logic summary, and a BSL specification. Only explicit checks in source code may be recorded — the model is forbidden from inferring implicit conditions.
- Validate and repair. A strict parser (e.g. ANTLR4-based) checks BSL syntax, and the count of
checkConditionentries is compared against the number of explicit guard statements in the AST. Errors are fed back to the model for up to four repair iterations; functions still failing are skipped. - Store. Functional descriptions are embedded into a vector database, other features go into a relational database, and the two are linked by function identifiers.
- Audit a target. For each target function, LogicScan retrieves the top-5 semantically similar templates restricted to the same Solidity major version and business category, then runs a three-phase LLM procedure: invariant induction across templates, consistency verification against the target, and deviation analysis to separate benign design differences from genuine omissions.
- Suppress false positives. Extra code context is gathered by finding every other function that writes to variables used in the call chain, and majority voting over templates removes implementation-specific quirks before the final judgement is issued.
The paper is explicit that a missing invariant is a review-worthy signal, not a definitive vulnerability verdict.
Why This Matters
- Research impact: It reframes logic vulnerability detection as invariant coverage analysis against implicitly agreed on-chain practice, sidestepping the need for expert-written specifications or documentation, which the paper identifies as the main generalisation bottleneck of prior LLM approaches such as GPTScan, PropertyGPT, and SmartInv.
- Real-world applications:
- Pre-deployment auditing of DeFi lending, vault, and staking protocols, where missing health-factor or accounting checks have proven catastrophic.
- Triage support for audit firms and bug-bounty platforms, prioritising functions whose invariants deviate from consensus implementations.
- Continuous monitoring of newly deployed forks and derivative protocols, which often inherit code but drop safeguards.
- Risk scoring for insurers, investors, or users assessing unfamiliar contracts before interacting with them.
- Industry relevance: The paper cites Chainalysis's 2025 Crypto Crime Security Report, which puts losses to crypto services at over $2.17 billion as of June 2025, exceeding the whole of 2024 and representing a 17% increase over the same period in 2022, with logic flaws rather than reentrancy or integer overflow driving the largest losses. A tool that scales invariant checking across a 43,749-contract corpus addresses a clear commercial gap.
Future Directions
- Broadening beyond Solidity version and category constraints: Retrieval is currently restricted to the same Solidity major version and a name-token–based business category; scaling to more languages and finer-grained categories is an open question.
- Improving the category heuristic: The authors concede categorisation is deliberately lightweight and misclassifications introduce noise, relying on frequency voting to absorb them; stronger classification could raise precision further.
- Expanding the invariant vocabulary: The synonym dictionary covers only the top 2,000 of more than 62,000 observed conditions, so coverage of rarer invariants is unexplored.
- Validation at scale: PropertyGPT could not be compared due to missing artifacts, and the truncated content does not report per-dataset precision and recall breakdowns or the concrete runtime and cost figures behind the efficiency claim, leaving room for fuller, reproducible benchmarking.
Target Audience
Smart contract security researchers and auditors, LLM-for-code researchers interested in hallucination control and retrieval-augmented reasoning, DeFi protocol engineering teams, and blockchain security tooling vendors. Readers should be comfortable with Solidity semantics and static analysis concepts; the paper is not aimed at general crypto users.
Authors’ abstract
Business logic vulnerabilities have become one of the most damaging yet least understood classes of smart contract vulnerabilities. Unlike traditional bugs such as reentrancy or arithmetic errors, these vulnerabilities arise from missing or incorrectly enforced business invariants and are tightly coupled with protocol semantics. Existing static analysis techniques struggle to capture such high-level logic, while recent large language model based approaches often suffer from…
The full abstract on arXiv