• LISA
    LISA
    • Public Scans
    • My Scans
    1. Scan
    2. ...
    2025-07-02 06:36:51
    Public
    Full Disclosure

    OWASP SC04-06 Contracts Audit

    high6
    Created By:
    Credit Usage:

    Unrestricted balance modification allows any user to arbitrarily set their balance

    HIGH

    Description

    The setBalance function is publicly accessible without any access control checks. This allows any user to modify their balance (or any other user's balance if they pass a different address) to any arbitrary value. In financial contracts, this could lead to direct loss of funds (e.g., users setting their balance to an inflated value and withdrawing unauthorized amounts if paired with a withdrawal function).

    Recommendation

    Add access control restrictions to the setBalance function (e.g., using OpenZeppelin's Ownable pattern or role-based access control). Alternatively, if user-controlled balance updates are required, implement proper validation logic to ensure balances can only be modified through legitimate operations.

    Affected Lines

    Line 7 – 9

    Arbitrary delegatecall allows privilege escalation and state manipulation

    HIGH

    Description

    The forward function allows any user to perform a delegatecall to an arbitrary address with arbitrary data. Since delegatecall executes the target contract's code in the context of the current contract, an attacker can craft a malicious contract that modifies critical state variables (e.g., changing the owner). This enables full control over the contract by unauthorized parties.

    Recommendation

    Restrict the forward function with an onlyOwner modifier to ensure only the owner can invoke it. Additionally, carefully review the necessity of allowing arbitrary delegatecalls, as they introduce significant security risks.

    Affected Lines

    Line 11 – 13

    Reentrancy vulnerability in withdraw function allows attackers to drain funds

    HIGH

    Description

    The withdraw function performs an external call to send ETH before updating the user's balance. This allows a malicious contract to re-enter the withdraw function repeatedly before the balance is reset, draining the contract's funds. The impact is loss of all ETH in the contract due to reentrancy attacks.

    Recommendation

    Apply the checks-effects-interactions pattern by updating the balance to zero before making the external call. Change the code order to set balances[msg.sender] = 0; prior to the ETH transfer.

    Affected Lines

    Line 15 – 18

    Arbitrary balance modification due to missing access control

    HIGH

    Description

    The setBalance function allows any caller to modify the balance of any address arbitrarily. This lack of access control enables malicious users to set incorrect balances for themselves or others, leading to potential theft, unfair advantages, or broken accounting logic in dependent systems. For example, an attacker could inflate their own balance to withdraw undeserved funds or manipulate another user's balance to disrupt the system.

    Recommendation

    Implement access control to restrict who can modify balances. If users should only update their own balance, add require(msg.sender == user, "Unauthorized");. If balance modification should be restricted to privileged accounts, use an onlyOwner modifier or similar access control pattern.

    Affected Lines

    Line 7 – 9

    Arbitrary delegatecall allows any user to escalate privileges and modify contract state

    HIGH

    Description

    The forward function is publicly accessible without any access control, allowing any user to perform a delegatecall to an arbitrary contract address. Delegatecall executes the target contract's code in the context of the caller's storage, enabling malicious actors to modify critical state variables (e.g., change the owner). This can lead to full contract compromise, including fund theft or logic manipulation.

    Recommendation

    Add an access control modifier (e.g., onlyOwner) to the forward function to restrict its usage to the contract owner. Additionally, carefully validate the callee address and consider whitelisting allowed contracts if possible.

    Affected Lines

    Line 11 – 13

    Reentrancy vulnerability allowing attackers to drain contract funds

    HIGH

    Description

    The contract updates the user's balance after making an external call during withdrawal. This allows a malicious actor to recursively call the withdraw function before their balance is reset, enabling them to drain the contract's entire balance. The impact is loss of all funds in the contract through reentrancy attacks.

    Recommendation

    Follow the Checks-Effects-Interactions pattern by updating the user's balance to 0 before making the external call. Change the function to set balances[msg.sender] = 0; prior to the msg.sender.call operation.

    Affected Lines

    Line 11 – 19