sherlock-audit / 2024-10-ethos-network-judging

0 stars 0 forks source link

Jovial Tan Donkey - Wrong storage of Reply in EthosDiscussion.sol #333

Closed sherlock-admin2 closed 3 weeks ago

sherlock-admin2 commented 3 weeks ago

Jovial Tan Donkey

Low/Info

Wrong storage of Reply in EthosDiscussion.sol

Summary

In EthosDiscussion.sol when creating a reply via addReply(), the reply is stored incorrectly.

Root Cause

The booleanbool isTargetThisContract is from Line 115. Where the function isAddressThisContract() returns true if 'targetContract' is EthosDiscussion.

  bool isTargetThisContract = _isAddressThisContract(targetContract);

  function _isAddressThisContract(address targetContract) private view returns (bool) {
    return targetContract == address(this);
  }

However, the boolean is stored in reverse.

function addReply(
    address targetContract,
    uint256 targetId,
    string memory content,
    string memory metadata
  )   
 replies[_replyCount] = Reply(
@>  !isTargetThisContract,
      targetContract,
      authorID,
      _replyCount,
      targetId,
      block.timestamp,
      0,
      content,
      metadata
    );

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

No response

PoC

No response

Mitigation

Fix the typo

    replies[_replyCount] = Reply(
-     !isTargetThisContract,
+     isTargetThisContract, 
     targetContract,
      authorID,
      _replyCount,
      targetId,
      block.timestamp,
      0,
      content,
      metadata
    );