code-423n4 / 2023-09-maia-findings

24 stars 17 forks source link

The absence of an event or notification mechanism in case of an attempt to add an already existing bridge agent is an error in the contract's behavior. #151

Open c4-submissions opened 1 year ago

c4-submissions commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-09-maia/blob/c0dc3550e0754571b82d7bfd8f0282ac8fa5e42f/src/BranchPort.sol#L319-L324

Vulnerability details

Impact

Lack of observability and potential confusion regarding the status of a bridge agent. Specifically:

Lack of Observability:

Potential Misunderstanding:

Proof of Concept

Function Signature and Modifier:

    function addBridgeAgent(address _bridgeAgent) external override requiresBridgeAgentFactory {

Check if Bridge Agent Already Exists:

    if (isBridgeAgent[_bridgeAgent]) revert AlreadyAddedBridgeAgent();

Marking Bridge Agent as Active:

    isBridgeAgent[_bridgeAgent] = true;

Adding Bridge Agent to List:

    bridgeAgents.push(_bridgeAgent);

You can see this function attempts to add a bridge agent. Before doing so, it checks if the provided bridge agent address is already registered. If it is, the function reverts. Otherwise, it marks the bridge agent as active and adds it to the list of registered bridge agents.

The fact that there's no mechanism to emit an event or notify external systems when an attempt is made to add an already existing bridge agent. This could lead to confusion or miscommunication about the status of the bridge agent.

addBridgeAgent

function addBridgeAgent(address _bridgeAgent) external override requiresBridgeAgentFactory {
    if (isBridgeAgent[_bridgeAgent]) revert AlreadyAddedBridgeAgent();

    isBridgeAgent[_bridgeAgent] = true;
    bridgeAgents.push(_bridgeAgent);
}

If a bridge agent is added more than once. The code currently checks if _bridgeAgent is already an existing bridge agent (isBridgeAgent[_bridgeAgent]). If it is, the function reverts with an error message AlreadyAddedBridgeAgent(), which implies that the bridge agent is already added.

However, there's no event or mechanism in place to emit a notification or record that an attempt was made to add an existing bridge agent. This means that external observers or systems interacting with the contract won't have a way of knowing if such an attempt was made.

Tools Used

Manual Review

Recommended Mitigation Steps

Consider adding an event as I previously suggested:

event BridgeAgentAdded(address indexed bridgeAgent);

function addBridgeAgent(address _bridgeAgent) external override requiresBridgeAgentFactory {
    if (isBridgeAgent[_bridgeAgent]) revert AlreadyAddedBridgeAgent();

    isBridgeAgent[_bridgeAgent] = true;
    bridgeAgents.push(_bridgeAgent);

    emit BridgeAgentAdded(_bridgeAgent); // Add this line to emit the event
}

Now this event will notify external observers whenever a bridge agent is added, providing a clear record of such events.

Assessed type

Access Control

c4-pre-sort commented 11 months ago

0xA5DF marked the issue as low quality report

0xA5DF commented 11 months ago

Emitting events is QA

c4-judge commented 11 months ago

alcueca changed the severity to QA (Quality Assurance)

c4-judge commented 11 months ago

alcueca marked the issue as grade-a