Software engineering researchers have unveiled an adaptive deep learning framework capable of hunting security vulnerabilities across complex, decentralized blockchain applications. In a study published in Automated Software Engineering, investigators Na Wang, Kun Zhang, Moroti Sonde, and Victor S. Sheng introduced the Dual-Stream Multi-Instance and Granularity Fusion Network, designated as DMG. Designed to operate across multiple program representations including source code, compiled bytecode, and operational code sequences, the framework formulates vulnerability identification as a weakly supervised multiple instance learning problem. By evaluating disassembled Ethereum bytecode simultaneously at the fine-grained level of basic straight-line execution blocks and the coarse-grained level of dispatch-organized functions, DMG bridges a critical historical divide in automated software auditing. It eliminates the need for manual, instruction-level vulnerability labeling by learning robust vulnerability indicators strictly from contract-level binary flags, thereby offering a practical and scalable solution for auditing deployed smart contracts without requiring access to proprietary source code.
Smart contracts represent self-executing programs deployed directly on decentralized blockchain networks to execute transactions and automate business logic without intermediaries. Their adoption has grown rapidly across diverse ecosystems, including decentralized finance, the Internet of Things, healthcare data management, and critical infrastructure systems. However, the fundamental operational characteristics of blockchain networks create severe security stakes for deployed code. Unlike traditional software systems that receive ongoing hotfixes and security patches, smart contracts become completely immutable once compiled and committed to the distributed ledger. Because these autonomous programs frequently custody, trade, and transfer high-value digital assets, subtle programming flaws can trigger irreversible and catastrophic financial exploits. Empirical records document that malicious actors launched thirty-four flash loan attacks in 2023 that drained approximately 225 million dollars in digital assets, alongside fourteen price manipulation exploits that inflicted an additional 140 million dollars in damages. These modern incidents mirror historic attacks such as the 2016 DAO breach, where an exploited reentrancy defect resulted in the theft of over 3.6 million Ether, representing roughly 60 million dollars in losses at the time.
Existing automated vulnerability detection methodologies generally fall into two broad computational paradigms, yet both struggle when transferred to complex, modern deployment environments. Classical software testing systems rely on static analysis, dynamic fuzzing, and formal symbolic execution tools, such as Slither, Mythril, Securify, Sailfish, and Echidna. While these tools leverage rigorous mathematical proofs and explicit rule sets, they depend heavily on handcrafted detection heuristics and predefined execution patterns, causing them to miss novel exploit variants and exhibit high false alarm rates. Conversely, data-driven machine learning models seek to learn statistical vulnerability patterns automatically from labeled code corpora. Unfortunately, the vast majority of existing learning-based detectors have been trained on synthetic or toy contract datasets that feature artificially simplified semantic structures and isolated failure patterns. Real-world smart contracts collected from active blockchain networks are typically five to ten times larger than toy benchmarks in terms of total function count and code complexity, exhibiting intricate cross-function call graphs, nested inheritance, and distributed state dependencies that completely break oversimplified classifiers.
A further engineering barrier stems from program visibility and representation granularity across the Ethereum virtual machine ecosystem. Fully supervised neural networks that require localized, fine-grained annotations identifying exact lines or instructions responsible for vulnerabilities cannot scale effectively, especially given that only approximately one percent of deployed smart contracts have publicly verifiable source code available. To overcome this limitation, DMG constructs its analytical representations directly from low-level operational code sequences derived from compiled bytecode. The framework processes available source files through the standard Solidity compiler and utilizes the Mythril disassembler to extract operational opcode streams. Crucially, the system architecture explicitly strips away raw operands such as concrete execution addresses, threshold values, and compiler configuration constants. Retaining raw operands would introduce massive noise and representation heterogeneity, making it difficult for neural networks to discover generalizable security patterns. Instead, DMG focuses strictly on stable opcode ordering, control-flow boundaries, and the structural relationships connecting localized basic blocks with dispatchable function units.
To formalize this multi-tiered structural perspective, DMG leverages the mathematical framework of multiple instance learning, treating each individual smart contract as an unannotated bag composed of two distinct instance sequences. The fine-grained sequence consists of straight-line basic blocks delineated by terminal halting and branching instructions, such as return, stop, and jump commands. The coarse-grained sequence consists of higher-level program functions identified through the contract runtime function selector table, which routes execution using entry point relative addresses. To accommodate sequence modeling requirements while preserving natural execution positions, contracts are padded or truncated to fixed thresholds of 512 basic blocks and 512 function slots, tracking valid positions through binary masking vectors. By pairing basic blocks with their corresponding parent functions through a structural tagging mechanism, DMG establishes an explicit hierarchical correspondence between local execution instructions and global functional logic, enabling the network to learn rich vulnerability representations using only a single binary label indicating whether the entire contract is secure or compromised.
The dual-stream neural architecture processes these two instance spaces through specialized, path-appropriate neural encoders designed to respect their intrinsic computational properties. For the fine-grained branch, basic blocks are first mapped into continuous 768-dimensional embedding vectors and processed via layer normalization. Because block execution follows rigid chronological control pathways, the system routes block embeddings through a single-layer bidirectional long short-term memory network featuring a hidden state size of 128 units in each direction. Concatenating both directions yields a 256-dimensional contextual representation, which is passed through dropout regularization, two linear transformations, and a Gaussian Error Linear Unit activation function to compute block-level attention scores. In contrast, inter-functional interactions within smart contracts are rarely strictly sequential, instead depending on asynchronous call invocations and shared state variables. Consequently, the coarse-grained branch processes the sequence of function embeddings through a multi-head self-attention mechanism utilizing four parallel attention heads, enabling the model to capture wide structural dependencies across distributed functional modules.
To synthesize these independent analytical pathways into a unified contract-level assessment, DMG introduces a lightweight, granularity-aware feature fusion mechanism. The system leverages the structural tagging function to sum all normalized block-level attention weights belonging to each respective function, generating a scalar importance score that quantifies the accumulated fine-grained risk concentrated within that functional unit. This derived scalar modulates the contextualized function representation produced by the multi-head attention branch, adaptively scaling the function vector according to its constituent block-level evidence without distorting its underlying vector space. The modulated function representations are subsequently averaged across all function positions to construct a single 768-dimensional contract vector. Finally, this global embedding enters a semantic enhancement classifier composed of a two-layer multi-layer perceptron with a hidden dimension of 256, layer normalization, and an explicit residual skip connection that preserves foundational semantic features before final projection into binary softmax classification probabilities.
The research team evaluated DMG through extensive experimental benchmarking on a dedicated computing workstation running Ubuntu 22.04 LTS, CUDA 12.0, PyTorch 2.0.1, and an Nvidia RTX A4000 graphics processing unit. The evaluation examined two public datasets: a synthetic toy benchmark comprising 72,026 Ethereum contracts and a real-world benchmark containing 5,000 contracts collected from active deployments. The real-world corpus underwent decentralized application decomposition, structural deduplication, and systematic filtering to eliminate benign coding style warnings and compiler hints, yielding 125 confirmed vulnerable contracts alongside 4,875 benign samples. Both collections were partitioned into eighty percent training pools and twenty percent held-out test sets using stratified sampling to preserve native label distributions. For the balanced synthetic dataset, models were trained for 50 epochs using the Adam optimizer with a learning rate of 0.0001, batch sizes of 32, and standard decision thresholds of 0.5. For the imbalanced real-world corpus, training extended to 70 epochs with batch sizes of 16, utilizing inverse class-frequency weighting and an optimized decision threshold of 0.39 calibrated on validation data.
Empirical results confirmed that DMG consistently outperformed both traditional software testing tools and competitive deep learning models across comprehensive evaluation metrics. On the synthetic toy benchmark, DMG attained 93.60 percent accuracy, 94.36 percent precision, 93.28 percent recall, and an F1-score of 93.79 percent, whereas conventional testing engines such as Slither, Mythril, Securify, and Sailfish failed to exceed 52 percent accuracy or 47 percent F1-scores. On the challenging, highly skewed real-world dataset, DMG maintained superior discriminative stability, achieving 98.16 percent accuracy, 60.78 percent precision, 74.40 percent recall, and a 68.88 percent F1-score. Furthermore, DMG secured an area under the precision-recall curve of 59.16 percent, substantially surpassing dedicated machine learning baselines such as ContractWard at 31.74 percent and SCSGuard at 43.25 percent. Systematic ablation experiments demonstrated the vital contribution of each architectural component: removing the fine-grained block stream caused precision on real contracts to fall to 34.84 percent, while removing the coarse-grained function stream collapsed model recall to 47.20 percent and reduced the precision-recall area to 19.85 percent.
Beyond predictive performance, computational complexity analysis and profiling confirmed that DMG delivers exceptional runtime efficiency, achieving an average inference latency of less than one millisecond per contract on both experimental benchmarks. The fine-grained bidirectional long short-term memory branch exhibits linear computational complexity relative to basic block counts, while the coarse-grained multi-head attention encoder scales quadratically with function positions, maintaining modest computational footprints. The authors documented key operational boundaries, noting that function selector heuristics covered 99.96 percent of toy samples and 94.68 percent of real-world samples, experiencing degraded grouping on proxy-heavy and assembly-intensive contracts. Additionally, stripping raw operands preserves universal structural logic but limits the model’s ability to assess vulnerabilities that hinge on concrete constants or state variable thresholds, such as transaction order dependence. By uniting hierarchical multiple instance learning with adaptive dual-stream fusion, DMG establishes an effective, low-latency foundation for safeguarding decentralized software ecosystems.
Subject of Research: Weakly supervised vulnerability detection in Ethereum smart contracts using multi-granularity neural networks
Article Title: DMG: Dual-Stream multiple instance learning network for hunting vulnerable smart contracts via adaptive granularity fusion
Article References: Wang, N., Zhang, K., Sonde, M., & Sheng, V. S. (2026). DMG: Dual-Stream multiple instance learning network for hunting vulnerable smart contracts via adaptive granularity fusion. Automated Software Engineering, 33(4), Article 147. https://doi.org/10.1007/s10515-026-00687-w
Image Credits: AI Generated
DOI: 10.1007/s10515-026-00687-w
Keywords: smart contracts, vulnerability detection, multiple instance learning, Ethereum, bytecode analysis, opcode modeling, bidirectional LSTM, multi-head attention, granularity fusion, software security, reentrancy, weakly supervised learning, blockchain security, deep learning, static analysis, precision recall curve, computational complexity
News Source: Blake Davidson. (November 23, 2026). Dual-Stream Neural Network Accurately Detects Vulnerabilities in Real-World Smart Contracts. Scienmag.



