Uninitialized Storage Pointer (SWC-109)

Description
In Solidity, local variables that are declared with a storage location and not initialized, are assigned an unpredictable storage slot by the compiler. This can lead to unexpected behavior of the contract, especially if the uninitialized variable is later assigned a value or used in a contract function.
If an uninitialized local variable points to an existing storage slot, it can overwrite the existing data, leading to unintended results. For example, if an uninitialized variable is used to store user balances, and the slot that it points to already contains data for another purpose, the user balances could be overwritten with unintended data. This could lead to funds being lost or transferred to unintended addresses.
Similarly, if an uninitialized variable points to an unused or unallocated storage slot, an attacker could exploit this vulnerability to write arbitrary data to that storage slot, potentially enabling them to gain control over the contract or steal funds.
To mitigate this vulnerability, all local storage variables should be explicitly initialized with a value before they are used or assigned to a storage slot. It is also good practice to avoid reusing storage slots for multiple purposes, as this can increase the risk of unintended overwriting of data. Additionally, developers should perform thorough testing and auditing of their smart contracts to identify any instances of uninitialized storage variables and address them before deployment.
Remediation
Solidity programming language allows developers to define variables in the contract which can be stored in the memory or storage of the contract. However, uninitialized local storage variables can be a source of vulnerabilities in the contract. This is because they can unintentionally or intentionally point to an unexpected storage location in the contract.
For instance, if a storage pointer is uninitialized in the contract, then an attacker could exploit it to gain control over the storage area in the contract that was unintentionally pointed to by the uninitialized storage pointer. This can lead to vulnerabilities such as reading or modifying data that was not intended to be read or modified.
To mitigate this vulnerability, it is important to check if the contract requires a storage object. If it is not necessary to use a storage object, a local variable with the memory attribute can be used instead. This ensures that the variable is explicitly marked as a memory object and is not inadvertently pointing to a storage location.
In cases where a storage object is required, it is essential to initialize it upon declaration, and specify the storage location with the keyword storage. Initializing storage variables upon declaration ensures that they are initialized to a known value and the location they point to is explicitly defined.
It is worth noting that starting from compiler version 0.5.0, uninitialized storage pointers no longer compile, thereby resolving the issue systematically. However, it is still essential to follow the best practices to avoid any potential vulnerabilities.
Contract Samples
Code with a vulnerability
pragma solidity ^0.4.19;
contract CryptoRoulette {
uint256 private secretNumber;
uint256 public lastPlayed;
uint256 public betPrice = 0.1 ether;
address public ownerAddr;
struct Game {
address player;
uint256 number;
}
Game[] public gamesPlayed;
function CryptoRoulette() public {
ownerAddr = msg.sender;
shuffle();
}
function shuffle() internal {
// randomly set secretNumber with a value between 1 and 20
secretNumber = uint8(sha3(now, block.blockhash(block.number-1))) % 20 + 1;
}
function play(uint256 number) payable public {
require(msg.value >= betPrice && number <= 10);
Game memory game;
game.player = msg.sender;
game.number = number;
gamesPlayed.push(game);
if (number == secretNumber) {
// win!
msg.sender.transfer(this.balance);
}
shuffle();
lastPlayed = now;
}
function kill() public {
if (msg.sender == ownerAddr && now > lastPlayed + 1 days) {
suicide(msg.sender);
}
}
function() public payable { }
}
Code without a vulnerability
pragma solidity ^0.4.19;
contract CryptoRoulette {
uint256 private secretNumber;
uint256 public lastPlayed;
uint256 public betPrice = 0.1 ether;
address public ownerAddr;
struct Game {
address player;
uint256 number;
}
Game[] public gamesPlayed;
function CryptoRoulette() public {
ownerAddr = msg.sender;
shuffle();
}
function shuffle() internal {
// randomly set secretNumber with a value between 1 and 20
secretNumber = uint8(sha3(now, block.blockhash(block.number-1))) % 20 + 1;
}
function play(uint256 number) payable public {
require(msg.value >= betPrice && number <= 10);
Game game;
game.player = msg.sender;
game.number = number;
gamesPlayed.push(game);
if (number == secretNumber) {
// win!
msg.sender.transfer(this.balance);
}
shuffle();
lastPlayed = now;
}
function kill() public {
if (msg.sender == ownerAddr && now > lastPlayed + 1 days) {
suicide(msg.sender);
}
}
function() public payable { }
}
Tools for scaning SWC-109
1. Mythril – an open-source EVM bytecode analyzer that can detect a wide range of vulnerabilities, including uninitialized storage variables.
2. Securify – an automated security scanner that can analyze Solidity code and detect a variety of vulnerabilities, including uninitialized storage pointers.
3. SmartCheck – a smart contract security analyzer that can detect uninitialized storage variables and other common vulnerabilities.
4. Slither – a static analysis framework that can detect uninitialized storage variables and other potential vulnerabilities in Solidity code.
5. Oyente – a security analysis tool that can detect uninitialized storage variables and other potential issues in Ethereum smart contracts.
The Common Weakness Enumeration (CWE)
CWE-824: Access of Uninitialized Pointer
Mitigation for SWC-109
1. Always initialize storage variables: It is important to ensure that all storage variables are initialized before usage. This can be achieved by assigning default values during the declaration of the variable.
2. Use the memory keyword for local variables: If a local variable is sufficient for a particular use case, it is advisable to use the memory keyword instead of storage to ensure that the variable is not mistakenly assigned to storage.
3. Use updated compiler versions: As mentioned earlier, compiler versions 0.5.0 and higher systematically resolve this issue by preventing contracts with uninitialized storage pointers from compiling. It is therefore recommended to use updated compiler versions to avoid this vulnerability.
4. Perform manual code review: Manual code review can help to identify instances of uninitialized storage variables that may have been missed during testing or by automated tools.
5. Use automated security analysis tools: Tools such as Mythril, Securify, and Oyente can help to detect instances of uninitialized storage variables in smart contracts.
Conclusion
SWC-109 highlights the importance of initializing all storage variables to prevent them from pointing to unexpected storage locations. This can be achieved by explicitly marking the storage location of the variable with the memory attribute if a local variable is sufficient, or by initializing the storage variable upon declaration and specifying the storage location. It is important to always check whether a contract requires a storage object, as in many situations a local variable may be sufficient. Finally, it is worth noting that this issue has been systematically resolved as of compiler version 0.5.0 and higher, as contracts with uninitialized storage pointers no longer compile.
Other Services
Insomnia Security Scanner
AI-powered web application security scanner by CQR. Automated vulnerability discovery, exploit verification, and detailed reporting for modern applications.
Learn moreInfrastructure Protection by CRYEYE
Security audits via CryEye provide enterprise information security, protecting the entire infrastructure.
Learn morePenetration Testing
Find vulnerabilities across your entire business infrastructure before hackers do! At penetration testing consulting, we will select pentest methods and other custom cybersecurity recommendations for your business.
Learn moreSocial Engineering
Simulate real-world phishing, vishing, and pretexting attacks to measure and improve your team's security awareness and response capabilities.
Learn morePerformance Testing
All kinds of load and performance testing of your system from the CQR online security company.
Learn moreAI-Powered Vulnerability Assessment
Leverage artificial intelligence to discover, prioritize, and remediate vulnerabilities across your digital assets faster and more accurately than traditional scanners.
Learn moreCloud Security Audit (AWS / GCP / Azure)
Comprehensive security review of your cloud environments — IAM policies, network controls, data exposure, and misconfigurations across all major cloud platforms.
Learn moreDevSecOps Integration
Embed security into every stage of your CI/CD pipeline. Automated SAST, DAST, SCA, and secret scanning so vulnerabilities are caught before they reach production.
Learn moreAPI Security Testing
In-depth testing of REST, GraphQL, and SOAP APIs for authentication flaws, authorization bypasses, injection vulnerabilities, and data leakage risks.
Learn moreMobile Application Penetration Testing
Manual and automated security testing for iOS and Android applications — reverse engineering, runtime analysis, traffic interception, and backend API assessment.
Learn moreIoT Security Assessment
Evaluate firmware, communication protocols, cloud backends, and physical interfaces of IoT devices to identify vulnerabilities before attackers do.
Learn moreBlockchain & Smart Contract Audit
Formal verification and manual code review of smart contracts on Ethereum, Solana, and other chains. Detect reentrancy, overflow, and logic flaws before deployment.
Learn moreRed Team Operations
Advanced adversary simulation using real attacker TTPs (MITRE ATT&CK) to test your detection, response, and overall security posture under realistic conditions.
Learn moreThreat Intelligence & Monitoring
Continuous monitoring of threat feeds, dark web, and attacker infrastructure to provide actionable intelligence specific to your organization and industry.
Learn moreZero Trust Architecture Review
Assess and design your Zero Trust security model — identity verification, micro-segmentation, least-privilege access, and continuous validation controls.
Learn moreCompliance Consulting (PCI DSS / SOC 2 / GDPR)
Expert guidance to achieve and maintain compliance with major security frameworks. Gap analysis, remediation roadmaps, and audit-readiness support.
Learn moreDark Web Monitoring
Continuous surveillance of dark web forums, marketplaces, and breach databases for leaked credentials, sensitive data, or mentions of your organization.
Learn morePhishing Simulation & Awareness Training
Controlled phishing campaigns combined with interactive security awareness training to build a human firewall across your entire organization.
Learn moreSupply Chain Security Audit
Assess third-party vendor risks, open-source dependencies, and software supply chain integrity to prevent attacks like SolarWinds and Log4Shell.
Learn moreContainer & Kubernetes Security
Security review of Docker images, Kubernetes clusters, RBAC policies, network policies, and runtime configurations to harden your container infrastructure.
Learn moreWeb Application Firewall (WAF) Deployment
Professional WAF setup, rule tuning, and ongoing management to block SQL injection, XSS, CSRF, and other OWASP Top 10 threats in real time.
Learn moreBug Bounty Program Management
Full lifecycle management of your bug bounty program — scope definition, researcher coordination, triage, validation, and remediation tracking.
Learn moreOSINT Investigation Services
Open-source intelligence gathering on individuals, organizations, and infrastructure. Ideal for pre-engagement recon, fraud investigation, and competitive analysis.
Learn moreDigital Forensics & Incident Response
Rapid response to security breaches — evidence collection, malware analysis, attacker timeline reconstruction, and actionable remediation recommendations.
Learn more