NFTBridge
60,000 USDC
View results
Submission Details
Severity: low
Invalid

Mapping State Management Issues in Messaging.sol

Summary

A security audit on the StarklaneMessaging contract revealed issues with the mapping state management that could lead to unintended or inconsistent states.

Vulnerability Details

The contract uses a mapping (_autoWithdrawn) to track the state of messages. This setup can inadvertently lead to unintended or inconsistent states if not managed properly.

Affected Code:

mapping(bytes32 => uint256) _autoWithdrawn;

POC (Proof of Concept)

Mappings in Solidity automatically return zero for any uninitialized key, which is implicitly treated as WITHDRAW_AUTO_NONE. Potential issues arise if proper state transitions are not enforced.

Scenario: Bob sends a message to Alice via the StarklaneMessaging contract. The state of the message must be tracked correctly to ensure it can only be consumed once.

  1. Initial State (WITHDRAW_AUTO_NONE):

    bytes32 msgHash = keccak256(abi.encodePacked("Message from Bob to Alice"));

    Kopier kode

    By default, _autoWithdrawn mapping for msgHash returns zero, interpreted as WITHDRAW_AUTO_NONE.

  2. Transition to Ready State (WITHDRAW_AUTO_READY):

    _autoWithdrawn[msgHash] = WITHDRAW_AUTO_READY;

    Kopier kode

    The msgHash state transitions from WITHDRAW_AUTO_NONE to WITHDRAW_AUTO_READY.

  3. Message Consumption:

    if (_autoWithdrawn[msgHash] != WITHDRAW_AUTO_READY) {
    revert WithdrawMethodError();
    }
    _autoWithdrawn[msgHash] = WITHDRAW_AUTO_CONSUMED;

    Kopier kode

    The state of msgHash becomes WITHDRAW_AUTO_CONSUMED.

Impact

  • Severity: Medium

  • Replay Attacks: Potential for the same message being consumed multiple times.

  • Incorrect State Consumption: Misinterpreted mapping states could cause improper management of message readiness and consumption.

Tools Used

  • Manual Code Review

Recommendations

  • Explicit Initialization: Ensure all mappings are explicitly initialized.

  • State Transition Checks: Implement explicit state transition checks.

  • Clear State Definitions: Utilize more granular state constants or enums.

Updates

Lead Judging Commences

n0kto Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational / Gas

Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!