Enhancing Ethereum Smart Contract Security
Enhancing Ethereum Smart Contract Security
(A). BACKGROUND
Blockchain technology has revolutionized digital transactions, and Ethereum is now the most
popular platform for developing and executing smart contracts. In particular, Decentralised
Finance (DeFi) and Non-Fungible Tokens (NFTs) rely on smart contracts, which are self-
contained programs written in languages like Solidity and compiled into low-level Ethereum
Virtual Machine (EVM) bytecode. While the immutability of smart contracts guarantees that
their behavior can’t be changed after deployment, it also means that any hidden bug or
security oversight becomes a permanent part of the code. Once such an issue slips through, it
can quickly turn into heavy financial losses, something the DeFi space has seen more than
once in its major breach history. The 2016 DAO breach—where attackers siphoned off more
than 3.6 million ETH—stands as one of the clearest examples of why stronger security
measures are urgently needed.
When faced with the increasing complexity and rapid evolution of smart contracts and the
EVM environment, traditional security auditing techniques usually fail. As a result, more
advanced techniques are needed to identify minor but harmful vulnerabilities that
conventional tools might miss. Even in cases where the source code is absent or has been
modified due to compiler optimisations, reverse engineering offers an efficient way for
analysts to dissect produced EVM bytecode, rebuild the underlying logic, and identify
vulnerabilities. Additionally, by analysing opcode-level data from smart contract bytecode,
machine learning techniques—such as Random Forest algorithms—have demonstrated
success in identifying patterns associated with fraudulent or insecure activity in DeFi
protocols.
The majority of static analysis tools currently in use work relatively well on straightforward
problems, but they often become confused by context-specific flaws, Resulting in either a
large number of false alarms or, worse, a complete lack of detection of sophisticated attack
patterns that exploit minor logical faults. Many categories of critical weaknesses remain
poorly understood and frequently evade detection by existing techniques. The DAO issue is a
classic illustration of how inadequate sharing of lessons learned from previous exploits has
frequently resulted in significant losses throughout history.
An automated, quick, and highly accurate method that can consistently identify these elusive
flaws in compiled EVM bytecode is therefore desperately needed by the ecosystem. By
addressing risks prior to contracts becoming live, such a system would enable developers and
auditors to lower the likelihood of expensive exploits drastically.
(C). RESEARCH OBJECTIVES
This study seeks to tackle the highlighted challenges through the following goals:
1. To create a structured and repeatable process for reverse engineering Ethereum EVM
bytecode, enabling the extraction of key structural and behavioural patterns that reveal
potential vulnerabilities—even in cases where the source code is unavailable or has been
heavily altered by compiler optimisations.
2. To explore and implement machine learning methods, with the Random Forest model, to
automatically recognise hidden patterns and indicators of complex security weaknesses
directly within compiled EVM bytecode.
3. To test and measure the performance of the proposed approach in identifying both known
and previously unseen vulnerabilities in real-world Ethereum smart contracts, especially
those used in DeFi and NFT platforms, while overcoming the shortcomings of current
detection tools.
4. To strengthen the overall security of the Ethereum ecosystem by delivering a fast, scalable,
and practical framework that supports early and proactive discovery of risks in smart
contracts before they are deployed.
Using advanced methods like Ghidra, the Ethereum EVM bytecode is reverse-engineered to
start the process. In this step, the compiled code is broken down into a readable format, and
key components, such as opcode sequences, control flow graphs—which are especially
challenging to accurately reconstruct due to the stack-based architecture of the EVM—data
dependencies, and general structural properties, are extracted. Following their extraction,
these components are arranged into a structured dataset that may be used for machine
learning analysis.
The last step involves training a Random Forest classifier on this dataset using labelled
samples that provide a clear distinction between secure bytecode patterns and those that are
vulnerable. In related tasks, such as opcode-based analysis for detecting fraudulent behaviour
in DeFi protocols, Random Forest has demonstrated impressive performance in the past. The
trained model gains the ability to identify complex and challenging indicators of security
flaws that are frequently missed by manual assessments or traditional static analysis methods.
Lastly, a wide range of real-world smart contracts is utilised to assess the system's
effectiveness thoroughly. To find out the accuracy of the approach in identifying various
types of vulnerabilities commonly found in DeFi and NFT projects, key metrics, including
precision, recall, and F1-score, are calculated. This method guarantees that the approach is
dependable and feasible for actual implementation.
(E). SCOPE
This research focuses exclusively on Ethereum smart contracts which operate using the
Ethereum Virtual Machine (EVM).The subtle and often missed patterns that reveal
significant vulnerabilities in DeFi protocols and NFT initiatives will be the focus of the
vulnerability identification efforts. Reentrancy attacks, integer overflow and underflow
errors, ineffective access control systems, and other logic-related flaws are examples of these.
The Random Forest technique for machine learning-driven pattern detection and Ghidra for
reverse engineering generated bytecode will be the main tools utilised during the project. The
Ethereum network and its own EVM bytecode format will be the only ones used for actual
implementation, testing, and analyzation even if some of the fundamental ideas may apply to
other blockchain platforms.
(F). LIMITATIONS
This study acknowledges some potential limitations that could impact the whole model.
The performance of a machine-learning model depends heavily on the quality of its training data—
its size, diversity, and accuracy all play a major role. When the dataset contains gaps, built-in biases,
or too few examples of rare vulnerability types, the model’s reliability can drop noticeably . Random
Forest can occasionally behave like a "black box," making it difficult to pinpoint the precise
reason why particular bytecode portions are flagged as dangerous, despite its overall strength
and stability.
Because smart contract attacks are constantly changing, new exploit strategies are frequently
developed. To be successful against new threats, the model may therefore require regular
updates and retraining.
The method may struggle to identify runtime-dependent errors or vulnerabilities that are only
visible during specific transaction sequences, as it is primarily static and only operates on
compiled bytecode. For instance, it is particularly challenging to pinpoint problems related to
gas usage in the absence of real execution traces.
Lastly, only EVM bytecode patterns are included in the study. This approach may not be able
to discover defects that start in high-level languages like Solidity but disappear or become
unrecognisable after compilation.
Chapter 2: Related Work This chapter examines previous studies on smart contract
vulnerabilities, traditional static and dynamic analysis methods, and the growing use of
machine learning in blockchain and cybersecurity domains, with a focus on existing
vulnerability detection approaches.
Chapter 3: Background on Ethereum and Smart Contracts This chapter covers essential
concepts, including the Ethereum blockchain, the Ethereum Virtual Machine (EVM)
architecture, the Solidity programming language, and widely known attack patterns targeting
smart contracts.
Chapter 5: Experimental Results and Analysis. This chapter presents the evaluation
outcomes, including performance metrics, comparisons with current detection tools, and real-
world case studies that highlight vulnerabilities identified by the system.
Chapter 6: Discussion This chapter interprets the results, explores their broader impact,
revisits the study's limitations, and suggests promising directions for future work.
Chapter 7: Conclusion This final chapter recaps the entire research, highlights the key
contributions, and provides closing remarks.
2. LITERATURE REVIEW
Smart contract security has garnered considerable research interest, mainly due to the significant
financial losses incurred by attacks on decentralised applications. This chapter reviews previous
research on the types of vulnerabilities affecting smart contracts, current detection technologies,
and the utilization of sophisticated methods, such as reverse engineering and machine learning, to
improve identification and prevention.
Symbolic execution is another sophisticated method that treats inputs as symbolic variables rather
than fixed values in order to investigate all potential execution paths. This method was used by early
programs like Oyente and DefectChecker to systematically find vulnerabilities in Ethereum contracts.
Analysing Ethereum Virtual Machine (EVM) bytecode is essential for securing smart
contracts, especially when the original source code is missing or when compiler optimisations
create discrepancies that only appear at the low-level bytecode stage.
Reverse engineering (RE) enables experts to break down and interpret this compiled code-the
only version permanently stored on the blockchain-to recover the contract's underlying logic
and execution flow.
Tools such as Ghidra play a central role by offering powerful disassembly, decompilation,
and control-flow graph (CFG) generation capabilities. These features allow analysts to
reconstruct program behavior even without access to the high-level source.
However, building an accurate and complete CFG from EVM bytecode remains technically
difficult. The stack-based execution model and dynamic jump targets (computed at runtime)
make traditional control-flow reconstruction unreliable and incomplete in many cases.
Despite these obstacles, reverse engineering delivers critical structural insights and feature
sets-like opcode patterns and data flows-that serve as the foundation for advanced automated
analysis, including machine learning-based vulnerability detection.
Despite tremendous advances in the security of smart contracts, this study tries to address some
major gaps:
Detecting Subtle EVM-Level Flaws Current ML approaches show potential, but they often miss low-
signal, high-impact vulnerabilities that evade rule-based detectors-especially in DeFi and NFT
contracts. The fast-evolving attack landscape demands detection systems that adapt quickly to new
exploit patterns as they emerge on the blockchain.
Robust Feature Extraction from Bytecode. Constructing accurate control-flow graphs (CFGs) from
stack-based EVM bytecode continues to be a major bottleneck. A more systematic and
comprehensive feature extraction pipeline is needed to capture fine-grained behavioural traits
suitable for training reliable ML models.
Model Interpretability for Developer Trust. Even effective models like Random Forest can appear
opaque. Developers need clear explanations-not just predictions-of why a specific bytecode segment
is flagged, enabling faster debugging and confident remediation.
Scalability against Emerging Threats. With smart contract logic growing in complexity and new
vulnerability classes appearing regularly, detection frameworks must operate efficiently at scale and
deliver low-latency risk alerts to prevent exploitation in production environments.
This study fills in these gaps by offering an integrated system that tightly couples advanced reverse
engineering (using tools like Ghidra) with targeted machine learning (Random Forest) to perform
high-precision, explainable, and adaptable vulnerability identification directly on EVM bytecode.
It is anticipated that the suggested approach, which highlights the uses of DeFi and NFTs, would
significantly improve detection accuracy as well as the delivery of useful insights. This would lessen
the attack surface inside the Ethereum ecosystem by allowing developers to protect decentralized
apps before they are deployed.
1
3. METHODOLOGY
This chapter presents the research methodology in a structured yet practical way,
showing how each step contributes to the overall aims of the study. The approach is
bytecode. Doing so transforms dense low-level instructions into features the model
can actually interpret, which is essential for identifying the kinds of nuanced
The next sections go into further detail about each step to ensure that the suggested
3.1 INTRODUCTION
systems.
designed explicitly for DeFi and NFT smart contracts, achieved by skillfully
Its key component is a Random Forest model that is trained on a carefully selected
dataset, which includes EVM bytecode samples classified as either susceptible or non-
3. Feature Engineering
real-world settings.
learning model. To provide a solid training foundation for the Random Forest
classifier, this section outlines the entire process of data collection, vulnerability
The dataset is built from authentic, on-chain Ethereum smart contract bytecode to
ensure maximum realism and relevance. Multiple trusted sources are combined to
create a balanced, diverse, and well-labelled collection of both vulnerable and secure
contracts.
Ethereum Mainnet (via Etherscan API) Direct extraction of live deployed bytecode
vulnerable contracts across multiple vulnerability classes, ideal for training and
testing.
contracts from public projects, along with CTF challenges (e.g., Ethernaut, Damn
scenarios.
5
vulnerable or safe. Security holes in the gathered bytecode samples are methodically
Reentrancy
Integer overflow/underflow
Unhandled exceptions
For contracts with pre-existing audit reports or benchmark labels, these annotations
This methodical, multi-phase labelling workflow minimises noise, assures high label
accuracy, and prioritises EVM-specific fault patterns that resist compilation and
increase in efficiency.
3.3.3 Labeling
those labels are off, the model’s understanding starts to drift. In this section, I describe
a three-level labeling process built to stay accurate at scale while also reducing the
8
independent experts.
Bias Control: Annotators are rotated across batches and blinded to prior labels to
classifier training dataset while lowering noise and ensuring high-fidelity ground
truth.
Since raw EVM bytecode isn’t something a machine-learning model can make sense
of on its own, the data has to go through a bit of reshaping first. In practice, this
means cleaning it up, pulling out the pieces that actually matter, and turning
everything into a format the model can reason about without getting lost in low-level
noise. In this section, I walk through the preparation pipeline step by step-what tools
were used, why those choices made sense at the time, and the kind of output each
stage produces once the bytecode has been processed enough to be useful.
Output Formats
Sequence-based:
Because of its multi-modal preprocessing, the Random Forest model and its future
modifications may learn from both sequential patterns and structural correlations seen
in EVM bytecode.
12
real-world settings.
Feature Categories
13
Our layered feature design lets the model pick up on both small-scale execution
cues and the broader structure of the program, making it better suited to identify
3.5 MODELS
Random Forest is the major classification technique used in this work to discover
EVM bytecode vulnerabilities, and it also provides features for comparing with other
models.
14
A Random Forest combines a large number of decision trees, each built from different
sampled data and feature subsets. During prediction, it checks the outputs of all trees
Selected Value /
Parameter Justification
Range
n_estimators 500–1000 Helps steady the model and reduce variance.
Lets the forest capture deeper, more subtle
max_depth None (or ~30)
patterns.
min_samples_split 2 A simple setting that keeps overfitting in check.
Cuts down tree similarity and improves
max_features 'sqrt' or 'log2'
diversity.
class_weight 'balanced' Useful when vulnerable samples are fewer.
A random forest works a bit like a crowd of decision-makers rather than one overly
them, each trained on a shuffled slice of the data and a different mix of features. This
randomness introduces a kind of healthy disagreement among the trees, which oddly
enough makes the final result more reliable. Once all the trees have made their
guesses, the forest settles on whatever answer most of them agree on-a majority vote
that tends to smooth out the mistakes any single tree might make.
Core Mechanism
A Random Forest works by building a large collection of decision trees, each trained
on its own randomly sampled slice of the data and feature set. This randomness
introduces just enough variety among the trees to keep the model from locking onto
noise. When it’s time to make a prediction, the forest simply looks at what the
majority of its trees decide and takes that as the final answer.
Random Forest is the best option for automatic, scalable, and easily accessible