Source-linked AI summary
SmartMemory: Detecting On-chain-off-chain Communication Inconsistency for Smart Contract via Memory-based Agent
Zeqin Liao, Yuhong Nan, Henglong Liang, Zixu Gao, Lianyu Hu, Yuqiang Sun, Zhijie Zhong, Xiaoyu Ma, Zibin Zheng, Yang Liu
TL;DR
OFC vulnerabilities are often treated as separate categories, while OFC inconsistency identifies a shared break in value equivalence between on-chain and off-chain asset representations. SmartMemory maps varied business logic, reuses vulnerability knowledge through memory, and verifies candidates with taint analysis. It reports 80.68% precision and 87.65% recall on a labeled dataset, and 36 previously unseen OFCIs in a real-world audit, all acknowledged and patched.
Problem
OFCI detection must locate heterogeneous business logic and transfer vulnerability knowledge beyond finite patterns to identify unseen cases.
Source: §I · pp. 1–2, B. Challenges and Solutions · p. 4Method
SmartMemory maps varied OFC implementations to a canonical business-semantic representation, uses memory to derive reusable patterns and rules, and verifies candidates with taint analysis.
Source: §I · p. 2Results
80.68% precision and 87.65% recall were achieved on the manually labeled dataset, and 36 previously unseen OFCIs were found in 325 real-world applications.
Source: §I · p. 2, §VII · p. 10Takeaways & Limitations
All 36 previously unseen OFCIs found in the real-world audit were acknowledged and patched.
Source: §VII · p. 10Manual analysis during dataset collection and evaluation may involve subjective bias, mitigated through independent annotation, cross-validation, and referee adjudication.
Source: F. Threat to Validity · p. 10
Abstract
from arXiv · showhide
Smart contracts underpin decentralized finance, where growing demand for on-chain/off-chain communication(OFC) has driven diverse applications such as cross-chain bridges, real-world asset tokenization, and fiat-backed stablecoins. TheOFC-related security incidents in these applications are increasingly frequent, but prior studies address separate vulnerability categories within OFC applications rather than providing a unified view, causing vulnerabilities outside known patterns to be missed.In this paper, we identify OFC inconsistency (OFCI) as a root cause of OFC vulnerabilities, which arises from business-logic flaw and ultimately breaks the equivalence between the on-chain and off-chain asset representations to induce inconsistency.Automatically detecting OFCIs faces two challenges including (1)locating heterogeneous business logic, and (2) transferring existing vulnerability knowledge to identify unseen OFCI instances. To this end, we propose SmartMemory, the first framework to leverage a memory-based agent for OFCI detection. To address heterogeneity, SmartMemory maps diverse implementations ofOFC contracts into a canonical business-semantic representation to locate the business logic for OFCI inspection. For knowledge reuse, SmartMemory integrates a memory-based agent to distill vulnerability knowledge from features into patterns and detection rules, enabling knowledge transfer across cases to identify unseenOFCIs. Lastly, SmartMemory performs taint analysis to verify the reachability, type, and impact of each candidate OFCI. We construct the first real-world OFCI dataset comprising 48 DApps with 81 OFCIs for evaluation, on which SmartMemory achieves80.68% precision and 87.65% recall. In addition, through an analysis of 325 real-world OFC applications, SmartMemory detects 36 previously unknown OFCIs, all of which have been confirmed and fixed by corresponding parties.
I. INTRODUCTION
OFC vulnerabilities are fragmented across categories and tools, while SmartMemory frames them as breaks in on-chain/off-chain value equivalence. It maps heterogeneous business logic, reuses vulnerability knowledge across cases, and reports confirmed findings in a real-world audit.
I. INTRODUCTION
- Prior studies and tools split OFC incidents into separate vulnerability categories, and many tools consequently miss issues outside their patterns.The paper cites examples including access-control, accounting, event-forgery, interaction, signature-verification, reentrancy, and overflow focuses.Source: §I · p. 1
- OFCI is identified as a common underlying cause of OFC vulnerabilities: incomplete asset-exchange logic breaks the equivalence invariant between on-chain and off-chain representations.The paper focuses on where and how that invariant is structurally broken, rather than only on symptoms such as unauthorized state modification or accounting errors.Source: §I · p. 1
- Application-specific business semantics challenge generic analysis, while combinatorial growth in chains, assets, and implementations limits finite pattern sets and standalone LLM knowledge transfer.The authors motivate memory as a way to accumulate and reuse knowledge from detected cases to help identify unseen vulnerabilities.Source: §I · p. 2
- SmartMemory maps heterogeneous OFC implementations into a canonical business-semantic representation, uses memory to distill features into patterns and rules, then applies taint analysis to verify candidates.The analysis checks candidate reachability, type, and impact.Source: §I · p. 2
- 36 previously unseen OFCIs were found across 325 real-world applications, and all were confirmed and fixed.The paper also reports 80.68% precision and 87.65% recall on its manually labeled dataset of 48 applications with 81 OFCIs.Source: §I · p. 2
- The paper introduces a manually labeled OFC-vulnerability dataset and a large OFC-contract dataset for evaluating detection and real-world performance.The evaluation dataset covers 48 applications and 81 OFCIs; the larger dataset comprises 325 real-world applications.Source: §I · p. 2
II. BACKGROUND
OFC connects on-chain contracts with off-chain entities or settlements, enabling asset movement and exchange across those components. Its workflows must preserve value equivalence at the transitions between on-chain and off-chain representations.
A. On-chain and Off-chain Communication in DeFi
- OFC workflows include deposits, token burning and proof emission, off-chain verification, proof submission and asset registration, followed by valuation and minting.The architecture lets users deposit assets on one blockchain and redeem them off chain or on another blockchain, and vice versa.Source: A. On-chain and Off-chain… · p. 2
- The equivalence invariant requires an asset’s on-chain and off-chain representations to remain value-equivalent across relevant state transitions.The paper identifies three constrained transition seams: user transfer to on-chain proof (B1), emitted proof to off-chain parsed value (B2), and accepted off-chain proof to minted tokens (B3).Source: A. On-chain and Off-chain… · pp. 2–3
B. LLM Agent and Memory
OFC inconsistency is a business-logic flaw that breaks value equivalence between on-chain and off-chain asset representations. The section also frames memory as a mechanism for agents to accumulate and reuse knowledge.
B. LLM Agent and Memory
- Memory supports LLM agents through encoding, updating, and retrieving task-relevant knowledge, allowing experience-based insights to be reused across tasks.The passage describes memory as enabling agents to learn from experience and adapt to evolving task requirements.Source: B. LLM Agent and Memory · p. 3
A. Definition and Problem Statement
- An OFC inconsistency is a contract business-logic flaw that violates an equivalence invariant, making an asset’s on-chain value diverge from its off-chain counterpart.The paper classifies two structural types according to which invariant is violated and where the inconsistency appears.Source: A. Definition and Problem Statement · p. 3
- Asset-exchange inconsistency arises when contract logic computes an output-token quantity inconsistent with the corresponding input-side asset value.In the Pledge example, both minting paths use chainAmount, allowing minimal off-chain collateral to yield excessive tokens.Source: A. Definition and Problem Statement · p. 3
- Proof-semantic inconsistency occurs when an on-chain proof’s structure lets an off-chain verifier parse asset-flow meaning inconsistent with the intended semantics.A forged Transfer event can resemble a Deposit proof, potentially letting an attacker obtain a valid-looking proof without transferring assets.Source: A. Definition and Problem Statement · pp. 3–4
- The targeted inconsistencies are controllable-input violations of B1, B2, or B3 that induce on-chain/off-chain value inconsistency; non-contract causes are outside the static-analysis scope.The stated out-of-scope examples include runtime and off-chain infrastructure issues.Source: A. Definition and Problem Statement · p. 4
B. Challenges and Solutions
OFCI detection must handle heterogeneous business-logic implementations and reuse vulnerability knowledge across cases. SmartMemory responds with semantic mapping, layered memory, and a pipeline that identifies and verifies candidate inconsistencies.
B. Challenges and Solutions
- Heterogeneous OFC implementations make business logic difficult to locate, while evolving vulnerability patterns make manually defined patterns difficult to generalize.The challenge passage describes non-standard designs and combinatorial growth in chains, assets, implementations, and vulnerability patterns.Source: B. Challenges and Solutions · p. 4
- A domain-expert-derived conceptual model maps shared OFC semantics to primitive functions, intra-operations, and variables, enabling semantic annotation to locate logic for inspection.The model includes four key variables around equivalence breakpoints that capture OFC-specific asset-exchange semantics.Source: B. Challenges and Solutions · p. 4
- SmartMemory organizes vulnerability knowledge in feature, pattern, and rule graphs, progressively abstracting reusable knowledge and retrieving it with semantic and structural relevance.Update operators can merge redundant, remove outdated or falsified, and decompose overfitted knowledge.Source: B. Challenges and Solutions · p. 4
A. Overview
- The three-stage workflow locates OFC logic, identifies business-logic incompleteness, and uses cross-chain/off-chain taint analysis to verify reachability, inconsistency type, and impact.The agent retrieves relevant memory and combines it with annotated source code; taint analysis checks propagation to equivalence-invariant variables.Source: A. Overview · pp. 4–5
B. Contract Logical Semantic Extraction
SmartMemory uses a conceptual model to describe OFC contract logic at the levels of primitive functions, intra-operations, and operated variables. Semantic annotation maps varied implementations into this representation and supplies context for inspection.
B. Contract Logical Semantic Extraction
- The conceptual model organizes contracts into functions, intra-operations, and variables, with nine primitive functions and five classes of intra-operation.Experts review OFC contracts, categorize functions by workflow, abstract primitive intra-operations, and summarize key-variable semantics.Source: B. Contract Logical Semantic Extraction · p. 5
- Deposit, Burn, and Register model asset admission, outflow, and registration through checks, state updates, and emitted proofs or events.Deposit updates balances and supply and emits an inflow proof; Burn deducts balances, debt, and supply and emits an outflow proof; Register verifies collateral proof and emits a registration event.Source: B. Contract Logical Semantic Extraction · p. 5
- Mint, Price, Transfer, Yield, Govern, and Liquidate capture additional checks, state changes, and events involving assets, debt, balances, valuation, configuration, and supply.Govern updates risk parameters and configuration without a fixed order, while Liquidate checks debt and adjusts supply and debt.Source: B. Contract Logical Semantic Extraction · p. 5
- The model’s OFC specificity lies in key variables and equivalence breakpoints; semantic annotation labels statements with a primitive function, intra-operation, and operated variable.The conceptual model guides the LLM in identifying source-statement semantics; multiple labels on one statement are treated as a union.Source: B. Contract Logical Semantic Extraction · pp. 5–6
- Statement-semantic labels map different implementations of the same operation to a shared representation without replacing their original source code.Wormhole and Nomad differ in parameter names, counts, and mechanisms, yet can receive the same Register/Update/onchain-asset label.Source: B. Contract Logical Semantic Extraction · p. 6
- A call graph selects functions along the call chain, while matching triple labels delimit the context for the same business-logic operation.The selected functions are serialized into semantically annotated code context.Source: B. Contract Logical Semantic Extraction · p. 6
C. Agent-based Inconsistency Identification
SmartMemory uses a three-layer memory-based agent to retrieve and refine vulnerability knowledge for OFCI identification. The design organizes knowledge from case-specific features into patterns and rules, supporting transfer across detection cases.
C. Agent-based Inconsistency Identification
- SmartMemory organizes vulnerability knowledge into feature, pattern, and rule graphs, with cross-layer edges encoding abstraction and derivation relations.The memory design is inspired by auditors abstracting case-specific features into reusable patterns and rules.Source: C. Agent-based Inconsistency… · p. 6
- The feature layer records each vulnerability through business logic, vulnerability, PoC, patch, subcontract, and attack entities linked into a feature subgraph.Feature subgraphs are associated across vulnerabilities through shared business logic, reused subcontracts, or shared attack events.Source: C. Agent-based Inconsistency… · p. 6
- At each layer, similarity-based retrieval selects top-k nodes, then one-hop graph expansion adds their incoming and outgoing neighbors.The expansion is intended to capture both semantic and structural relevance.Source: C. Agent-based Inconsistency… · pp. 6–7
- The agent retrieves relevant knowledge top-down, using higher-layer results as seeds and accumulating them into queries for lower layers.It retrieves rules first, then patterns, then vulnerability features.Source: C. Agent-based Inconsistency… · p. 7
- Five memory-update operators abstract, merge, associate, remove, or decompose knowledge to refine and transfer OFCI knowledge.They support abstraction across associated entities, merging similar content, removing outdated knowledge, and decomposing overly case-specific patterns or rules.Source: C. Agent-based Inconsistency… · p. 7
D. Vulnerability Discovery via Taint Analysis
SmartMemory builds a cross-contract data-flow graph and uses taint analysis to verify whether candidate OFCI indicators are externally reachable and affect critical variables. The affected variables determine the OFCI type.
D. Vulnerability Discovery via Taint Analysis
- SmartMemory joins local data-flow graphs across proof production, off-chain confirmation, and proof submission to form a cross-contract data-flow graph.It abstracts the off-chain parsed asset value as a node and adds alignment edges across the data-flow break.Source: D. Vulnerability Discovery via Taint… · p. 8
- Taint analysis starts from externally controllable public-function inputs and checks candidate indicators and critical OFC variables as sinks.Forward propagation tests whether an external attacker can trigger an indicator and whether taint reaches variables involved in inconsistency checking.Source: D. Vulnerability Discovery via Taint… · p. 8
- Impact on variables 1 and 2, or 4 and 5, identifies Type-1 asset-exchange inconsistency; impact on variables 2 and 3 identifies Type-2 proof-semantic inconsistency.SmartMemory uses reachability and impact to verify indicators and determine their OFCI type.Source: D. Vulnerability Discovery via Taint… · p. 8
- In the mint example, both minting paths incorrectly reuse chainAmount, and taint analysis confirms effects on off-chain collateral proof and minted assets.The case is classified as asset-exchange inconsistency.Source: D. Vulnerability Discovery via Taint… · p. 8
- In the returnAssets example, structurally isomorphic emitted events prevent a relayer or witness from distinguishing forged from genuine proof.Taint analysis verifies external reachability and effects on the produced proof and parsed value, classifying the case as proof-semantic inconsistency.Source: D. Vulnerability Discovery via Taint… · p. 8
A. Implementation and Evaluation Setup
The evaluation examines detection effectiveness, component contributions, runtime and monetary costs, and zero-day discovery. It uses a manually labeled incident dataset and a larger real-world application set with measures to limit information leakage.
A. Implementation and Evaluation Setup
- The evaluation asks four questions about OFCI detection effectiveness, component contributions, runtime and monetary costs, and zero-day discovery.The evaluation uses GPT-5-mini and averages results over five runs.Source: A. Implementation and Evaluation Setup · p. 8
- The manually labeled dataset contains 81 OFCIs from 48 real-world OFC applications, annotated from public security reports and contract code.The dataset supplies ground truth for evaluation.Source: A. Implementation and Evaluation Setup · p. 8
- The large-scale dataset contains 325 applications and 5,158 code documents to assess performance on previously unseen OFCIs.The evaluation removes overlap with the labeled set and excludes target-application information from memory construction.Source: A. Implementation and Evaluation Setup · p. 8
B. RQ1: Overall Effectiveness
SmartMemory achieves 80.68% precision and 87.65% recall on the manually labeled dataset. Temporal-holdout results are comparable across pre- and post-cutoff cases, and the authors report that false positives and false negatives have identifiable context boundaries.
B. RQ1: Overall Effectiveness
- 80.68% precision and 87.65% recall: SmartMemory achieves these results on Dlabeled, with consistently strong performance on both subtypes.The evaluation compares detections with ground truth comprising 81 OFCIs in 48 applications.Source: B. RQ1: Overall Effectiveness · pp. 8–9, Table I · p. 9
- Most false positives stem from incomplete contract availability, while false negatives mainly depend on cryptographic libraries or real-time data sources such as oracles.The authors attribute the false positives to unresolved external calls and incomplete logic context during static analysis.Source: B. RQ1: Overall Effectiveness · p. 9
- With GPT-4o, post-cutoff cases yield 81.48% (22/27) precision and 88.00% (22/25) recall, compared with 80.00% (48/60) precision and 85.71% (48/56) recall for pre-cutoff cases.The authors say this suggests effectiveness is unlikely to be driven by pre-training leakage and report comparable performance under GPT-5-mini and GPT-4o.Source: B. RQ1: Overall Effectiveness · p. 9
C. RQ2: Ablation Study
The ablation study evaluates semantic extraction, memory designs, and taint-analysis-based discovery, while the overhead study measures runtime and token cost. SmartMemory improves recall over scope-matched tools and processes each DApp in about 205 seconds on average.
C. RQ2: Ablation Study
- 63.33% precision and 70.37% recall without semantic extraction show lower performance; the full method resolves 14 of 24 resulting false negatives.Semantic extraction distinguishes the two minting paths and their expected parameters, exposing their conflicting use of chainAmount.Source: Table II · p. 9, C. RQ2: Ablation Study · p. 9
- Adding memory content, retrieval, and update operators incrementally increases precision and recall monotonically, with each design contributing positively.The comparison begins with standalone LLM reasoning and adds memory components incrementally.Source: C. RQ2: Ablation Study · p. 9
- 87.80% recall versus SmartAxe’s 68.29% and 87.50% versus VCScope’s 43.75% show higher recall in both scope-matched comparisons.The method eliminates 8 of 13 false negatives from SmartAxe and 7 of 9 from VCScope.Source: C. RQ2: Ablation Study · pp. 9–10, Table III · p. 10
D. RQ3: Performance Overhead
- 204.84 seconds and 46,150 tokens per DApp are SmartMemory’s average total runtime and token use, at an estimated cost of $0.0213.The paper describes the runtime and cost as practical and notes that locally deployed open-source LLMs could further reduce monetary cost.Source: D. RQ3: Performance Overhead · p. 10, Table IV · p. 10
E. RQ4: Finding Zero-days in the Real World
In a study of 325 real-world OFC DApps, SmartMemory surfaced exploitable zero-day OFCIs that were acknowledged and fixed. The paper also reports limits from subjective manual analysis, situates its approach among prior work, and provides project materials through a repository.
E. RQ4: Finding Zero-days in the Real World
- 36 of 55 confirmed true positives were exploitable zero-day OFCIs across 325 DApps, and all 36 were acknowledged and fixed.The study reported 69 warnings, including 55 true positives and 14 false positives, and verified exploitability with proof-of-concept exploits.Source: E. RQ4: Finding Zero-days in the Real… · p. 10
F. Threat to Validity
- Subjective bias in manual collection and evaluation remains a threat, mitigated through independent expert annotation, cross-validation, and referee adjudication.The average Cohen’s Kappa across annotator pairs was 0.764, indicating substantial agreement.Source: F. Threat to Validity · p. 10
VI. RELATED WORK
- Prior smart-contract vulnerability methods rely on predefined patterns or lack continual learning, limiting adaptability to emerging OFC-specific variants.The related-work section also describes OFC tools focused on particular vulnerability types or adjacent problems.Source: §VI · p. 10
VII. CONCLUSION
- On 81 OFCIs from 48 DApps, SmartMemory achieved 80.68% precision and 87.65% recall.The conclusion also reports identifying 36 previously unseen zero-day OFCIs among 325 real-world DApps, all acknowledged and patched.Source: §VII · p. 10
VIII. DATA AVAILABILITY
- The repository provides artifacts, datasets, vulnerability statistics, prompts, parameter settings, embeddings, collection protocol, memory implementations, and disclosure materials.The repository is identified by DOI 10.5281/zenodo.21006162.Source: §VIII · p. 10