Floating Pragma (SWC-103)

Description
When deploying smart contracts, it is important to ensure that they are deployed using the same compiler version and flags that they have been tested with. This helps to ensure that the contracts function as intended and do not introduce bugs or vulnerabilities into the system. One way to help ensure this is to “lock” the pragma version used in the contract, which prevents it from being compiled using an outdated or incompatible compiler version. This is especially important because even minor changes in the compiler version can affect the behavior of a contract. By locking the pragma version, developers can help ensure that the contract is deployed using the same compiler version and flags that it was tested with, reducing the risk of unexpected behavior or vulnerabilities.
Восстановление
Expanding on the previous statement, it is important to lock the pragma version when deploying contracts to ensure that they are compiled with a specific, tested version of the Solidity compiler. It is also important to consider any known bugs or issues associated with the selected compiler version, which can be found on the Solidity GitHub repository.
However, when creating contracts intended for use by other developers, such as those in a library or EthPM package, it may be appropriate to allow the pragma statement to float. This means that the contract can be compiled using the latest stable version of the Solidity compiler, rather than being locked to a specific version. In such cases, the developer using the library or package would need to manually update the pragma statement to ensure that it is compatible with their own contract system.
Contract Samples
Code with a vulnerability
pragma solidity ^0.4.0;
contract PragmaNotLocked {
uint public x = 1;
}
Code without vulnerabilities
pragma solidity 0.4.25;
// or
pragma solidity =0.4.25;
contract SemVerFloatingPragmaFixed {
}
Tools for scaning SWC-103
1. Mythril: An open-source security analysis tool that can detect the SWC-103 vulnerability, among other vulnerabilities.
2. Slither: Another open-source static analysis tool that can detect the SWC-103 vulnerability in Solidity smart contracts.
3. Securify: A security scanner for Ethereum smart contracts that can detect the SWC-103 vulnerability, as well as other common vulnerabilities.
4. Echidna: A property-based testing tool that can be used to detect the SWC-103 vulnerability in Solidity smart contracts.
5. Manticore: A symbolic execution tool that can detect the SWC-103 vulnerability, as well as other vulnerabilities in smart contracts.
Общее перечисление слабых мест (CWE)
CWE-664: Improper Control of a Resource Through its Lifetime
Mitigation for SWC-103
SWC-103 is a vulnerability that can arise when a contract’s fallback function does not include proper error handling. To mitigate this vulnerability, it is recommended to include proper error handling in the fallback function, such as logging the error and rejecting the transaction. Developers should also consider implementing a more structured contract design that does not rely on the fallback function for critical functionality.
One approach to improve contract design is to use the “pull payment” model, where the contract does not initiate the payment but rather waits for the user to initiate the payment. Another approach is to use the “withdraw pattern,” where each user’s funds are kept in a separate balance, and the user must actively withdraw the funds from the contract.
Furthermore, developers should also use the latest version of Solidity and perform thorough testing and auditing of their contracts to detect and prevent vulnerabilities like SWC-103.
Заключение
SWC-103 is a vulnerability that can arise when a contract uses a timestamp as a source of randomness. Attackers can manipulate the timestamp to control the outcome of the contract’s logic, potentially leading to unintended state changes or even complete contract compromise.
Другие Услуги
Insomnia Security Scanner
AI-powered web application security scanner by CQR. Automated vulnerability discovery, exploit verification, and detailed reporting for modern applications.
Узнать большеЗащита Инфраструктуры CRYEYE
Аудит безопасности с помощью CryEye обеспечивает информационную безопасность предприятия, защищая всю инфраструктуру.
Узнать большеТестирование на проникновение
Найдите уязвимости во всей инфраструктуре вашего бизнеса раньше, чем это сделают хакеры! В рамках консалтинга по тестированию на проникновение мы подберем методы пентестов.
Узнать большеСоциальная инженерия
Simulate real-world phishing, vishing, and pretexting attacks to measure and improve your team's security awareness and response capabilities.
Узнать большеНагрузочное Тестирование
All kinds of load and performance testing of your system from the CQR online security company.
Узнать большеAI-Powered Vulnerability Assessment
Leverage artificial intelligence to discover, prioritize, and remediate vulnerabilities across your digital assets faster and more accurately than traditional scanners.
Узнать большеCloud 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.
Узнать большеDevSecOps 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.
Узнать большеAPI Security Testing
In-depth testing of REST, GraphQL, and SOAP APIs for authentication flaws, authorization bypasses, injection vulnerabilities, and data leakage risks.
Узнать большеMobile Application Penetration Testing
Manual and automated security testing for iOS and Android applications — reverse engineering, runtime analysis, traffic interception, and backend API assessment.
Узнать большеIoT Security Assessment
Evaluate firmware, communication protocols, cloud backends, and physical interfaces of IoT devices to identify vulnerabilities before attackers do.
Узнать большеBlockchain & 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.
Узнать большеRed Team Operations
Advanced adversary simulation using real attacker TTPs (MITRE ATT&CK) to test your detection, response, and overall security posture under realistic conditions.
Узнать большеThreat Intelligence & Monitoring
Continuous monitoring of threat feeds, dark web, and attacker infrastructure to provide actionable intelligence specific to your organization and industry.
Узнать большеZero Trust Architecture Review
Assess and design your Zero Trust security model — identity verification, micro-segmentation, least-privilege access, and continuous validation controls.
Узнать большеCompliance 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.
Узнать большеDark Web Monitoring
Continuous surveillance of dark web forums, marketplaces, and breach databases for leaked credentials, sensitive data, or mentions of your organization.
Узнать большеPhishing Simulation & Awareness Training
Controlled phishing campaigns combined with interactive security awareness training to build a human firewall across your entire organization.
Узнать большеSupply Chain Security Audit
Assess third-party vendor risks, open-source dependencies, and software supply chain integrity to prevent attacks like SolarWinds and Log4Shell.
Узнать большеContainer & Kubernetes Security
Security review of Docker images, Kubernetes clusters, RBAC policies, network policies, and runtime configurations to harden your container infrastructure.
Узнать большеWeb 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.
Узнать большеBug Bounty Program Management
Full lifecycle management of your bug bounty program — scope definition, researcher coordination, triage, validation, and remediation tracking.
Узнать большеOSINT Investigation Services
Open-source intelligence gathering on individuals, organizations, and infrastructure. Ideal for pre-engagement recon, fraud investigation, and competitive analysis.
Узнать большеDigital Forensics & Incident Response
Rapid response to security breaches — evidence collection, malware analysis, attacker timeline reconstruction, and actionable remediation recommendations.
Узнать больше