26 Апр, 2023

Unprotected Ether Withdrawal (SWC-105)


To mitigate this vulnerability, it is important to implement proper access controls in the smart contract. Access controls should be used to restrict which functions can be called and by whom. It is also important to avoid exposing initialization functions, and to make sure that constructor functions are properly named to prevent them from being callable after deployment.

In addition, it is important to perform thorough testing and auditing of the smart contract code to identify and address any potential vulnerabilities before deployment. It is also recommended to use standardized security tools and frameworks to ensure that the smart contract code is secure and reliable.


To mitigate the risk of unauthorized withdrawals, it is important to implement access controls that ensure withdrawals can only be triggered by authorized parties or according to the specifications of the smart contract system. This can be achieved by using techniques such as role-based access control, whitelisting, and multi-factor authentication.

It is also important to thoroughly test the access control mechanisms to ensure they work as intended and cannot be circumvented by attackers. Additionally, contracts should be audited by a reputable third-party security firm to identify and address any potential vulnerabilities before they can be exploited.

Finally, it is important to follow best practices for smart contract development and deployment, such as using the latest version of the Solidity compiler, avoiding deprecated features, and thoroughly testing contracts before deploying them to the live network.

Contract Samples

Code with a vulnerability

					pragma solidity ^0.4.21;
contract TokenSaleChallenge {
    mapping(address => uint256) public balanceOf;
    uint256 constant PRICE_PER_TOKEN = 1 ether;
    function TokenSaleChallenge(address _player) public payable {
        require(msg.value == 1 ether);
    function isComplete() public view returns (bool) {
        return address(this).balance < 1 ether;
    function buy(uint256 numTokens) public payable {
        require(msg.value == numTokens * PRICE_PER_TOKEN);
        balanceOf[msg.sender] += numTokens;
    function sell(uint256 numTokens) public {
        require(balanceOf[msg.sender] >= numTokens);
        balanceOf[msg.sender] -= numTokens;
        msg.sender.transfer(numTokens * PRICE_PER_TOKEN);


Tools for scaning SWC-105

1. MythX: MythX is a cloud-based security analysis platform that offers a range of vulnerability detection tools, including SWC-105, as well as other SWC vulnerabilities, in Solidity smart contracts.

2. Solhint: Solhint is a linter for Solidity that helps developers identify and fix common issues, including deprecated functions or features, in Solidity smart contracts.

3. Slither: Slither is a static analysis framework for Solidity that can identify a wide range of vulnerabilities, including deprecated functions or features, in smart contracts.

4. Securify: Securify is a security scanner for Ethereum smart contracts that can detect various vulnerabilities, including deprecated functions or features, through static analysis.

5. Oyente: Oyente is a security analyzer for Ethereum smart contracts that can detect deprecated functions or features, as well as other vulnerabilities, through static analysis.

Общее перечисление слабых мест (CWE)

CWE-284: Неправильный контроль доступа

Mitigation for SWC-105

1. Use safe math libraries: To avoid integer overflow and underflow vulnerabilities, developers should use safe math libraries that provide secure arithmetic operations.

2. Restrict user input: Developers can validate user input and enforce constraints to prevent users from providing large values that could lead to overflow and underflow.

3. Use smaller data types: By using smaller data types, developers can reduce the likelihood of overflow and underflow vulnerabilities.

4. Use require statements: Developers can use require statements to ensure that values passed into functions are within a certain range or meet specific criteria.

5. Avoid complex mathematical operations: Developers should avoid complex mathematical operations that are prone to overflow and underflow vulnerabilities.

6. Use tests and audits: Comprehensive testing and auditing can help identify vulnerabilities and ensure that code is secure.


SWC-105 highlights the vulnerability of the smart contract to an attack that is initiated through an unexpected function call. This can occur if the smart contract does not restrict access to sensitive functions and data to authorized parties. To avoid such vulnerabilities, developers must ensure that sensitive functions and data are only accessible to authorized parties. Developers should implement access control mechanisms, such as role-based access control or whitelisting, to restrict access to sensitive functions and data. Additionally, developers should be careful not to expose sensitive functions and data in their interfaces, and limit the exposure of the smart contract’s code to prevent attackers from discovering hidden vulnerabilities. Automated tools such as Mythril and Securify can be used to detect such vulnerabilities in smart contracts during the development phase, which can help in mitigating the risks associated with SWC-105.

Другие Услуги

Готовы к безопасности?

Связаться с нами