A security audit on the StarklaneMessaging contract revealed issues with the mapping state management that could lead to unintended or inconsistent states.
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:
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.
Initial State (WITHDRAW_AUTO_NONE):
Kopier kode
By default, _autoWithdrawn mapping for msgHash returns zero, interpreted as WITHDRAW_AUTO_NONE.
Transition to Ready State (WITHDRAW_AUTO_READY):
Kopier kode
The msgHash state transitions from WITHDRAW_AUTO_NONE to WITHDRAW_AUTO_READY.
Message Consumption:
Kopier kode
The state of msgHash becomes WITHDRAW_AUTO_CONSUMED.
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.
Manual Code Review
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.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.