Skip to content

Instantly share code, notes, and snippets.

@RideSolo
Last active March 3, 2020 01:30
Show Gist options
  • Save RideSolo/f4f2c0ab25d22493b057046bad5d74e3 to your computer and use it in GitHub Desktop.
Save RideSolo/f4f2c0ab25d22493b057046bad5d74e3 to your computer and use it in GitHub Desktop.

WednesdayClub Audit Report.

1. Summary

This document is a security audit report performed by RideSolo, where WednesdayClub has been reviewed.

2. In scope

3. Findings

7 issues was reported:

  • 2 High severity issues.
  • 2 Low severity issues.
  • 2 Owner Privileges.
  • 1 note.

3.1. Block Gas Limit

Severity: High

Description

All the following functions have a high risk to throw for Out of Gas or Block Gas Limit since the post or comment Id to be deleted is saved inside an array and a loop is used to find it.

  • deleteUserPost
  • deleteIdFromPostIds
  • deletePost
  • deleteUserComment
  • deleteComment
  • deleteAllPosts

The more a user uses the Dapp to share post or comment the longer the array will get, meaning that for the long term no work arround can be done by the owner to avoid it.

Same issue is applicable for unfollow function where the array is a list of following or followers and unblockUser where the array is a list of blocked users.

Please note that once the id is found no break is used to exit the loop.

Following up with the same error:

  • nukeMe
  • nukePosts
  • nukeComments

Have the same issue where there might be not enough of gas to delete the whole list if it is long enough, also it might reach Block Gas Limit.

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L100

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L115

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L140

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L201

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L217

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L268

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L299

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L324

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L330

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L339

Recommendation

Mappings can be used to keep track of the array ellements id without looking through the whole array for the a specific post or comment to delete.

3.2. Misuse Of delete

Severity: High

Description

Developers should be aware that when delete is applied on an array id the value assigned to that id is reset to zero but the array length stays the same, meaning that the dev should implement a logic where the last element on the array will replace the deleted id and the array length should be decremented by one.

A function such deleteAllPosts is useless and does not meet the goal set by the dev (following the comments deleteAllPosts in groups i.e. delete 100, then 100 again, etc - for saving on gas and incase to many) since the first 100 deleted post will be just set to zero but the array lenght of postIds will stay the same. If the total number of posts is high enough the transaction can reach block gas limit.

Please note that delete is also used in other functions, and the delete logic should be updated to a better one.

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L130

3.3. Post & Comment Creation

Severity: low

Description

  • When creating a post using writePost the structure saved does not include _content and _media parameters (except the emitted event nothing can retrace the post to its included media or content), developers should always keep the link to the IPFS data inside the post structure and make it immutable.

  • Same issue is applicable for writeComment, nothing directly link the content and the media to the comment id (except the emmited event).

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L50#L67

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L150#L168

3.4. Post & Comment ID

Severity: note

Description

  • The inputted post id in writePost is not the same final id that is used to track the post itself.
  • The same note is applicable for writeComment.

This can lead users to confusion except if handled by the Dapp.

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L53

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L153

3.5. FallBack Function

Severity: low

Description

The fallback function is used to deposit ether to the contract, however it can be missused by users. Developers should create a dedicated function for deposit with a unique name.

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L44

3.6. Owner Privileges

severity: medium

Description

  • Pause/Unpause the posts, comments, likes and follow for users through whenNotPaused.
  • Delete posts and comments.

Code snippet

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L100

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L115

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L140

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L201

https://github.com/aelchim/WednesdayClub/blob/master/src/WednesdayClub.sol#L217

https://github.com/RideSolo/WednesdayClub/blob/master/src/WednesdayClub.sol#L268

Conclusion

The audit contracts are not safe for deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment