DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Unused Like Struct in LikeRegistry contract

Unused Like Struct (Lack of Historical Like Data)

Description:

The contract defines a Like struct:

struct Like {
address liker;
address liked;
uint256 timestamp;
}

However, this struct is never actually used or stored in the contract. While the likeUser function records likes in the likes mapping, it does not save timestamps. This means:

  1. There is no way to track when a like occurred.

  2. Future features relying on historical data (e.g., "Who liked me in the past week?", "Anniversay of the first like") will not work.

  3. Potential auditing, analytics, or refund mechanisms become impossible.

Impact:

  • Loss of Time-Based Features:

    • Dating apps often use time-based algorithms (e.g., "Most liked users today").

    • Without timestamps, such features cannot be implemented.

  • Poor User Experience & Analytics:

    • Users cannot see a history of who liked them and when.

    • Admins cannot generate engagement reports.

  • Limits Future Expansions:

    • If the project later introduces like-based ranking (e.g., "Trending Profiles"), the missing timestamps will require a major contract upgrade.

Proof of Concept:

Consider the following scenario:

  1. Alice likes Bob.

  2. Bob wants to see who liked him in the past 24 hours, but there is no timestamp to filter recent likes.

  3. A feature like getRecentLikes(address user, uint256 timeframe) cannot be implemented.

Code Analysis:

The struct exists:

struct Like {
address liker;
address liked;
uint256 timestamp;
}

But likeUser does not store it anywhere:

likes[msg.sender][liked] = true;

This means only a boolean is stored, losing critical information.

Recommended Mitigation:

1. Store the Like Struct in a Mapping

Instead of just using a bool, modify likes to store a Like struct:

mapping(address => mapping(address => Like)) public likes;

Update likeUser to store the timestamp:

likes[msg.sender][liked] = Like({
liker: msg.sender,
liked: liked,
timestamp: block.timestamp
});

2. Add a Function to Retrieve Like History

Introduce a function to fetch like details:

function getLikeDetails(address liker, address liked) external view returns (uint256) {
return likes[liker][liked].timestamp;
}

3. Enable Time-Based Filtering for Future Features

Now, we can build functions like:

function getRecentLikes(address user, uint256 timeframe) external view returns (address[] memory) {
address[] memory recentLikers;
uint256 count = 0;
for (uint256 i = 0; i < matches[user].length; i++) {
address liker = matches[user][i];
if (likes[liker][user].timestamp >= block.timestamp - timeframe) {
recentLikers[count] = liker;
count++;
}
}
return recentLikers;
}
Updates

Appeal created

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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