Saturday, October 17, 2026
Science
No Result
View All Result
  • Login
  • HOME
  • SCIENCE NEWS
  • CONTACT US
  • HOME
  • SCIENCE NEWS
  • CONTACT US
No Result
View All Result
Scienmag
No Result
View All Result
Home Science News

Graph attention network learns to spot hidden gas waste in Ethereum smart contracts

October 17, 2026
in Science News
Blake Davidson
By Blake Davidson Scienmag Editorial Profile - Data Science
Reading Time: 6 mins read
0
Graph attention network learns to spot hidden gas waste in Ethereum smart contracts

Graph attention network learns to spot hidden gas waste in Ethereum smart contracts

65
SHARES
587
VIEWS
Share on FacebookShare on Twitter
ADVERTISEMENT

Every operation on the Ethereum blockchain carries a price. That price, measured in units of gas, is paid by users in cryptocurrency, and it scales with the computational complexity of the code being executed. Adding two numbers typically costs 3 gas units, while a simple transaction consumes 21,000. A function that charges a monthly service fee might burn 45,000 gas units; at a gas price of 80 gwei, that translates to 0.0036 ETH per call. For decentralized applications serving millions of users, these numbers compound into a formidable economic burden, and inefficiently written contracts can generate prohibitively high and volatile transaction fees that undermine the entire promise of blockchain technology.

Now a team of researchers in Morocco has introduced a deep learning framework that attacks this problem from a direction that traditional tools cannot reach. The framework, called GasGAT, was developed by Youssef Said and colleagues at the Laboratory of Information Processing, University Hassan II in Casablanca, together with a collaborator at the Hassania School of Public Works. Their work, published in Frontiers in Blockchain, models smart contracts not as lines of code to be scanned for known anti-patterns, but as semantic graphs in which functions, state variables, and control-flow constructs become nodes, and their interactions become edges. A Graph Attention Network, or GAT, then learns to navigate this graph and identify the structural causes of excessive gas consumption.

The innovation matters because existing gas optimization tools are largely confined to static heuristics and local pattern matching. Tools such as GasOptiScan and GasChecker excel at detecting pre-defined anti-patterns, like costly storage operations syntactically enclosed within loops. But they operate at a syntactic level and cannot easily model complex state dependencies or detect emergent inefficiencies that arise from the non-local interaction of multiple, seemingly optimized functions across a contract’s call graph. Machine learning approaches that treat contracts as flat feature vectors, such as opcode counts or function sizes, are similarly constrained by the expressiveness of manually chosen features. Neither family of methods can reason about long-range execution paths that span multiple functions.

GasGAT’s graph representation is designed precisely to expose these hidden dependencies. The researchers built a dedicated parser that transforms the Solidity Abstract Syntax Tree of each contract into a directed semantic graph. Nodes correspond to key semantic entities: public, internal, and private functions; control-flow constructs such as loops and conditionals; persistent state variables; and gas-intensive operations like the SSTORE instruction that writes to storage. Edges capture function call dependencies, control-flow relations, read and write accesses to state variables, and inter-procedural data and execution dependencies. Each node is described by a 16-dimensional feature vector encoding its type, function visibility, payable, view, and pure flags, normalized loop nesting depth, parameter count, source position, constructor status, and out-degree.

A concrete example illustrates why this representation is so powerful. Consider a batch-processing function that loops over an array of identifiers and calls an internal helper function, which in turn writes to a storage map. The expensive SSTORE operation is syntactically distant from the loop, buried inside the helper. The graph conversion creates a multi-hop path connecting the loop to the eventual storage write, and the attention mechanism can propagate along this entire execution chain. The model learns to attribute gas costs not to isolated syntax, but to the holistic interaction of iteration, calling context, and state mutation. Purely local, intra-procedural analyses would miss this pattern entirely, because no single function appears wasteful in isolation.

To train and evaluate the framework, the team retrieved source code for more than 100,000 unique verified smart contracts via the Etherscan API, filtering to retain contracts written in Solidity version 0.8.0 or later with at least 50 confirmed transactions. The final corpus comprised 40,000 contracts from the Ethereum mainnet, spanning decentralized finance protocols, NFT marketplaces, DAO governance contracts, and general-purpose utilities. Each contract was labeled using Slither static analysis to compute an aggregate inefficiency score based on the weighted presence of known gas-related anti-patterns. Contracts in the top quartile were labeled gas-inefficient, those in the bottom quartile gas-efficient, and the ambiguous middle 50 percent were deliberately excluded to establish a clear benchmark. A random subset of 500 contracts was independently reviewed by two smart contract security experts, yielding high inter-rater agreement with a Cohen’s Kappa of 0.89.

The GasGAT architecture consists of three stacked graph attention layers with an initial linear projection from 16-dimensional input features to a 128-dimensional hidden space. The first two layers use four attention heads with concatenation, while the final layer uses a single head. Residual connections and LayerNorm are applied after each layer, and the graph-level representation is obtained by concatenating global mean and max pooling over node embeddings, feeding a 256-dimensional vector to a three-layer MLP classifier. The model trains with the Adam optimizer, dropout of 0.3, and weighted cross-entropy loss to correct an 84-to-16 percent class imbalance. Remarkably, the entire framework contains only 94,530 trainable parameters and runs on a CPU with 16 GB of RAM, completing five-fold cross-validation in roughly three hours.

Under five-fold stratified cross-validation on 27,879 labeled graphs, GasGAT achieved a mean accuracy of 94.92 percent, with a standard deviation of 1.04 percent, and a macro F1-score of 88.69 percent, with a standard deviation of 2.70 percent. Precision stabilized at 96.94 percent, with a standard deviation of only 0.43 percent across all five folds, confirming the robustness of the classification capability. A McNemar statistical test yielded a statistic of 633.12 with p far below 0.05, confirming that the predictions are statistically significant and not attributable to chance. Training loss converged typically between epochs 5 and 20, with early stopping triggered before epoch 40 in all folds, indicating efficient optimization and strong generalization to unseen contracts.

The most striking result, however, concerns what happens when correlated node features are removed. The researchers rebuilt all graphs using a revised feature vector that completely eliminates two features directly tied to the labeling heuristics: a per-node gas weight estimate and membership in gas-intensive operations. When these features were removed, a graph convolutional network baseline dropped by 16.15 percentage points, from 99.05 to 82.90 percent F1, revealing that its near-perfect performance was primarily driven by memorizing the feature-label correlation. GraphSAGE and GIN dropped by 2.59 and 2.29 points respectively. GasGAT alone showed zero performance change, from 88.69 to 88.69 percent, providing direct empirical evidence that its attention mechanism learns genuine structural graph dependencies rather than exploiting label-feature correlations inherent in the heuristic labeling process.

The interpretability of the attention mechanism transforms predictive performance into actionable developer insights. In a real case study from the test set, a contract misclassified by an XGBoost baseline but correctly identified as gas-inefficient by GasGAT contained a public batch function that iterated over an array and invoked a registration function, which delegated state modification to an internal helper. Because the expensive SSTORE operation was not syntactically enclosed within the loop, no local static-analysis feature was activated. GasGAT assigned its highest attention weights to the edges forming the execution path between the loop and the deep state-modifying operation, with scores of 0.31, 0.47, and 0.52, and one edge carrying an attention score of 0.9965. A hub node exhibited seven outgoing edges with attention weights above 0.96, a pattern entirely absent from Slither’s detector catalogue. The highlighted attention path translates directly into refactoring guidance: developers can extract state-modifying logic to make gas costs visible at the call site, apply batch storage updates instead of repeated individual writes, or restructure the loop to minimize cross-function delegation.

The researchers also conducted supplementary experiments on the full dataset, reintegrating the previously excluded middle 50 percent of contracts. In a three-class classification setting distinguishing gas-efficient, moderately optimized, and gas-inefficient contracts, GasGAT achieved 92 to 94 percent accuracy compared to 88 to 90 percent for a local baseline. In a regression formulation predicting a continuous inefficiency score, GasGAT reached an R-squared of 0.84 to 0.88 versus 0.72 to 0.78 for the baseline. A preliminary evaluation on 2,000 contracts written in Solidity versions 0.5 through 0.7, without retraining, exhibited stable qualitative behavior with limited performance degradation, suggesting that the learned representations capture higher-level execution structures rather than version-specific syntactic artifacts.

The authors are transparent about the limitations of their approach. The polarized dataset construction simplifies the classification task and may underrepresent moderately optimized contracts encountered in real-world development. The ground-truth labels are derived from static-analysis heuristic scores rather than large-scale dynamic execution profiling, because publicly available datasets validated through systematic runtime execution traces remain unavailable at the scale of 40,000 contracts. The dataset was restricted to Solidity 0.8.0 and later, so direct generalization to legacy contracts cannot be assumed without further validation. Training is computationally intensive due to graph attention operations, though inference requires only a single forward pass whose cost scales linearly with the number of nodes and edges, compatible with interactive developer assistance scenarios.

What distinguishes GasGAT from prior work is not marginal accuracy improvement but a paradigm shift from localized pattern matching to holistic structural analysis. To the best of the authors’ knowledge, it represents one of the first applications of graph attention networks specifically to the gas optimization problem, with an explicit focus on inter-procedural structural reasoning and developer-oriented interpretability. The framework identifies three categories of inter-procedural gas inefficiency that are fundamentally invisible to Slither’s detectors: delegation chains where expensive storage operations are triggered indirectly through multi-level call chains, hub functions that delegate execution to multiple state-modifying helpers through high-attention edges, and cross-function state accumulation where repeated mutations emerge only when considering the full inter-procedural execution path.

The implications extend beyond Ethereum. As blockchain applications proliferate across finance, supply chains, insurance, gaming, and e-voting systems, the economic viability of decentralized applications depends critically on controlling execution costs. GasGAT demonstrates that data-driven program analysis can complement manual rule engineering, offering a scalable alternative that learns structural abstractions not explicitly encoded in static analysis features. The attention mechanism functions not merely as a predictor but as a diagnostic tool, guiding developers toward concrete refactoring opportunities that enhance both performance and security. For future work, the team plans to extend the framework toward multi-class and regression-based formulations for finer-grained identification of gas anti-patterns, and to generalize it to legacy Solidity versions and other EVM-compatible blockchains, strengthening its applicability to real-world smart contract ecosystems.

Subject of Research: Computer Science

Article Title: GasGAT: a graph attention network framework for smart contract gas optimization

Article References: Said, Y., Khaddar, A. M., Hassine, L., Eddaoui, A., & Chafiq, T. (2026). GasGAT: a graph attention network framework for smart contract gas optimization. Frontiers in Blockchain, 9, Article 1838214. https://doi.org/10.3389/fbloc.2026.1838214

Image Credits: AI Generated

DOI: 10.3389/fbloc.2026.1838214

Keywords: Ethereum, smart contracts, gas optimization, graph attention network, machine learning, blockchain, interpretable AI, GasGAT, graph, attention, network, framework

Cite Scienmag News

Blake Davidson. (October 17, 2026). Graph attention network learns to spot hidden gas waste in Ethereum smart contracts. Scienmag. https://scienmag.com/graph-attention-network-learns-to-spot-hidden-gas-waste-in-ethereum-smart-contracts/

Blake Davidson. "Graph attention network learns to spot hidden gas waste in Ethereum smart contracts." Scienmag, 17 October 2026, https://scienmag.com/graph-attention-network-learns-to-spot-hidden-gas-waste-in-ethereum-smart-contracts/. Accessed 17 October 2026.

Blake Davidson. "Graph attention network learns to spot hidden gas waste in Ethereum smart contracts." Scienmag. October 17, 2026. https://scienmag.com/graph-attention-network-learns-to-spot-hidden-gas-waste-in-ethereum-smart-contracts/

Tags: AI-driven tools for smart contract auditingattentionblockchainBlockchain scalability and cost managementBlockchain transaction fee reduction techniquesDeep learning models for detecting gas wasteDeep learning-based gas cost analysisDetecting inefficient smart contract codeEthereumEthereum smart contract gas optimizationEthereum smart contract performance optimizationframeworkgas optimizationGasGATGasGAT framework for smart contract efficiencygraphgraph attention networkGraph attention networks for blockchain analysisinterpretable AIMachine learningmachine learning in blockchain securitynetworkSemantic graph modeling of smart contractssmart contracts
Share26Tweet16
Previous Post

Inside the Mosquito Salivary Gland: The Last Microbial Barrier Against Malaria

Next Post

Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia

Related Posts

Clouds, not evaporation, decide how land change shifts global climate
Earth Science

Clouds, not evaporation, decide how land change shifts global climate

October 17, 2026
Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia
Cancer

Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia

October 17, 2026
Inside the Mosquito Salivary Gland: The Last Microbial Barrier Against Malaria
Science News

Inside the Mosquito Salivary Gland: The Last Microbial Barrier Against Malaria

October 17, 2026
Nurses Face an Interruption Every Six Minutes While Giving Medication, Landmark Chinese Hospital Study Reveals
Medicine

Nurses Face an Interruption Every Six Minutes While Giving Medication, Landmark Chinese Hospital Study Reveals

October 17, 2026
Zebrafish Take Center Stage as Scientists Redefine the Future of Preclinical Research
Science News

Zebrafish Take Center Stage as Scientists Redefine the Future of Preclinical Research

October 17, 2026
DistilBERT Outperforms Perceiver in the Hunt for Fake Hotel Reviews
Science News

DistilBERT Outperforms Perceiver in the Hunt for Fake Hotel Reviews

October 17, 2026
Next Post
Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia

Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia

  • Mothers who receive childcare support from maternal grandparents show more optimized

    Mothers who receive childcare support from maternal grandparents show more parental warmth, finds NTU Singapore study

    27656 shares
    Share 11059 Tweet 6912
  • University of Seville Breaks 120-Year-Old Mystery, Revises a Key Einstein Concept

    1061 shares
    Share 424 Tweet 265
  • Bee body mass, pathogens and local climate influence heat tolerance

    682 shares
    Share 273 Tweet 171
  • Researchers record first-ever images and data of a shark experiencing a boat strike

    546 shares
    Share 218 Tweet 137
  • Groundbreaking Clinical Trial Reveals Lubiprostone Enhances Kidney Function

    531 shares
    Share 212 Tweet 133
Science

Embark on a thrilling journey of discovery with Scienmag.com—your ultimate source for cutting-edge breakthroughs. Immerse yourself in a world where curiosity knows no limits and tomorrow’s possibilities become today’s reality!

RECENT NEWS

  • Clouds, not evaporation, decide how land change shifts global climate
  • Hidden Cell Division Flaw Emerges as Driver of Aggressive Leukaemia
  • Graph attention network learns to spot hidden gas waste in Ethereum smart contracts
  • Inside the Mosquito Salivary Gland: The Last Microbial Barrier Against Malaria

Categories

  • Agriculture
  • Anthropology
  • Archaeology
  • Athmospheric
  • Biology
  • Biotechnology
  • Blog
  • Bussines
  • Cancer
  • Chemistry
  • Climate
  • Earth Science
  • Editorial Policy
  • Marine
  • Mathematics
  • Medicine
  • Pediatry
  • Policy
  • Psychology & Psychiatry
  • Science Education
  • Science News
  • Social Science
  • Space
  • Technology and Engineering

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 5,150 other subscribers

© 2025 Scienmag - Science Magazine

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • HOME
  • SCIENCE NEWS
  • CONTACT US

© 2025 Scienmag - Science Magazine

Discover more from Science

Subscribe now to keep reading and get access to the full archive.

Continue reading