Research
Ethereum NFT Smart Contracts: Knowledge-Guided Vulnerability Detection with LLM and Code Slicing
Static analyzers can screen NFT contracts quickly with rules, but they struggle with application-specific logic because matching a transfer, arithmetic operator, or timestamp reference does not prove…

- arXiv
- 2607.21983
- Published
- 2026-07-24
- Authors
- Deyu Yang, Rundong Wei, Xiaoqi Li
AI summary
Overview
Research area: Blockchain security — automated vulnerability detection in Ethereum non-fungible token (NFT) smart contracts, combining static pattern matching, code slicing, and large language model (LLM) reasoning.
Technical level: Intermediate. Readers benefit from familiarity with Ethereum accounts, the ERC-721 standard, and basic LLM prompting concepts, but the paper's pipeline is described in accessible engineering terms.
Scope (one sentence): The paper evaluates a pipeline that uses regular-expression screening plus a structure-aware context window to extract line-numbered ERC-721 code slices, then constrains DeepSeek with an ERC-721-oriented knowledge base and a fixed output schema to label three vulnerability classes — reentrancy, integer overflow or underflow, and timestamp dependence — across 450 NFT contract samples.
What This Paper Is About
Static analyzers can screen NFT contracts quickly with rules, but they struggle with application-specific logic because matching a transfer, arithmetic operator, or timestamp reference does not prove exploitability. Conversely, handing an entire contract to an LLM introduces irrelevant context and produces inconsistent, hard-to-parse answers. The authors' goal is to narrow what the model sees — through vulnerability-focused code slices — and constrain how it answers — through domain knowledge, explicit decision rules, and a fixed output schema — so detection results are consistent enough for automated batch processing.
Key Contributions
- A focused detection workflow for three representative vulnerability classes in Ethereum NFT smart contracts: reentrancy, integer overflow or underflow, and timestamp dependence.
- A slicing procedure that converts complete contracts into line-numbered, vulnerability-focused code slices, using class-specific regular expressions as a high-recall filter followed by a structure-aware context window that expands toward function boundaries.
- A constrained DeepSeek analysis stage that supplies an ERC-721-oriented knowledge base, a closed label set, explicit rejection rules (for example, return
Nonewhen evidence is insufficient), and a fixed response schema with vulnerability type, suspicious line range, and rationale. - Batch results, runtime measurements, vulnerability distributions, and two ablations isolating the effects of the external knowledge base and of code slicing on reported outputs.
Main Findings
- Full configuration results: On 450 NFT contract samples, the full pipeline produced 437 positive labels and 13
Nonelabels, a reported positive-label rate of 97.1% (437/450 = 97.11%). - Class distribution: 155 reentrancy labels, 141 integer overflow or underflow labels, 141 timestamp-dependence labels, and 13
Nonelabels. - Ablation — removing the knowledge base: Analyzing the same code slices without the external knowledge base yielded 392 positive labels and 58
Nonelabels, or 87.11%. - Ablation — removing slicing as well: Analyzing complete contracts without the knowledge base yielded 332 positive labels and 118
Nonelabels, or 73.78%. - Measured deltas: Adding external knowledge to sliced inputs raised the reported rate by 10.00 percentage points (87.11% to 97.11%); under the no-knowledge condition, replacing complete contracts with code slices raised it by 13.33 percentage points (73.78% to 87.11%).
- Runtime: Slice extraction took 13.74s in total, about 0.03s per contract. An average detection request took about 3.8s, while the complete batch took 34min, or 4.53s per sample end to end. The complete-contract ablation run took 37min, or 4.93s per contract.
- Selected-sample demonstrations: Three illustrative samples reported reentrancy (external transfer before the expected state update without an effective lock), potential unchecked integer arithmetic (custom arithmetic tied to a Solidity version earlier than 0.8.0), and timestamp-dependent control logic (fundraising checks relying on
nowor equivalent conditions across multiple functions). - Metric caveat: Because the evaluation used no independently adjudicated ground truth, the authors explicitly describe the primary metric as a positive-label rate, not classification accuracy, and state that precision and recall cannot be established.
Methodology in Plain English
The pipeline has three stages. First, contracts and their vulnerability-category labels are loaded from a CSV file, and class-specific regular expressions locate candidate statements — for example, transfer( and withdrawToAddress for reentrancy, compound assignments such as += and -= or exponentiation for arithmetic issues, and block.timestamp, block.number, and now for timestamp dependence. Second, for each match the system builds an initial window of five lines on each side, then searches backward for a likely function start and forward while balancing braces (scanning up to fifty lines) to find the end of the function, producing a line-numbered code slice. Third, each slice is sent to the official DeepSeek API with a prompt containing the ERC-721 knowledge base, the line-numbered slice, a closed label set of the three classes plus None, and rules instructing the model to analyze only the supplied slice, avoid assuming unshown behavior, return None when evidence is insufficient, and report locations as Lines X-Y. Responses are parsed into three fields (type, location, cause) and aggregated for statistics. The point of the design is division of labor: the regex filter keeps recall high while the LLM judges whether surrounding logic actually satisfies the vulnerability definition — for instance, a transfer that updates state first, arithmetic checked by the language or a library, or timestamps used only for noncritical logging.
Why This Matters
The paper's distinctive angle is treating the LLM's input and output as engineering constraints rather than as a general-purpose oracle: slicing controls what the model sees, and a knowledge base plus fixed schema controls how it answers. This yields a reproducible-shaped batch pipeline without training or fine-tuning a model.
Impact on research: The ablation design gives a controlled comparison of two levers — focused context and domain knowledge — and quantifies each, which is a useful methodological template for LLM-based auditing studies. The authors are also candid that a positive-label rate is not accuracy, setting a clear bar for what follow-up evaluations must report.
Real-world applications:
- Pre-audit triage for NFT marketplaces and minting platforms, flagging candidate contracts before human review.
- Continuous monitoring of deployed ERC-721 collections, where transfer, approval, and metadata logic govern unique assets.
- Developer-facing review tooling that surfaces a specific suspicious line range and rationale alongside each flag.
- Screening in due-diligence workflows for identity, ownership, exchange, and application-specific NFT use cases.
Industry relevance: The pipeline uses off-the-shelf components — regexes, a hosted LLM API, and a fixed schema — so it fits existing audit and CI-style tooling more readily than a custom-trained model would. The runtime figures (about 0.03s per contract for slicing, 4.53s per sample end to end for the full batch) are the kind of numbers practitioners need when deciding whether such a check can run at portfolio scale.
Future Directions
- Establish adjudicated ground truth. The authors call for expert-reviewed labels, a confusion matrix, per-class precision, recall, F1 score, confidence intervals, and inter-annotator agreement, none of which the current evaluation includes.
- Freeze and publish the configuration. The exact DeepSeek model identifier, decoding temperature, token limit, API version, retry policy, and full knowledge-base text were not recorded; publishing the dataset and scripts would address reproducibility and allow analysis of output stability.
- Compare against baselines. Benchmarking the approach against static analyzers and other LLM-based detectors would situate the reported rates relative to existing tools.
- Broaden and deepen the analysis. Extending beyond the three classes (access-control failures, unchecked calls, denial of service, oracle manipulation, and upgradeability risks are currently out of scope) and addressing slice blind spots — inherited modifiers, storage invariants, cross-function calls, cross-contract behavior, and false positives from legitimate timestamp use — are natural next steps.
Target Audience
Smart-contract security researchers and auditors; blockchain engineers building NFT or ERC-721 systems; and applied LLM researchers interested in how code slicing, retrieval-style domain knowledge, and constrained output schemas change model behavior on code-analysis tasks. It is also relevant to reviewers and practitioners who need a clear example of how to report LLM-based detection results honestly, including the explicit distinction between a positive-label rate and accuracy.
Authors’ abstract
Ethereum non-fungible tokens (NFTs) implement ownership, transfer, authorization, and metadata operations through smart contracts, making contract vulnerabilities a direct risk to digital assets. Existing static analyzers provide efficient rule-based screening but can struggle with application-specific logic, whereas unconstrained large language model analysis may be distracted by irrelevant code or produce inconsistent outputs. We present a vulnerability-detection method…
The full abstract on arXiv