Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: medium
Invalid

The `Soulmate::readMessageInSharedSpace` function's weak randomness may enable malicious users to predict displayed messages from the Soulmate::niceWords array.

Description: Due to the weakness in randomness, malicious users may be able to predict the sequence or content of messages that will be displayed from the Soulmate::niceWords array.

function readMessageInSharedSpace() external view returns (string memory) {
return string.concat(sharedSpace[ownerToId[msg.sender]], ", ", niceWords[@> block.timestamp % niceWords.length]);
}

Impact: This vulnerability presents a considerable threat, allowing malicious users the potential to forecast the order of messages showcased from the Soulmate::niceWords array. As a result, the sanctity and privacy of the shared space, where sensitive messages is exchanged, stand at risk of compromise. This jeopardizes user privacy and trust, potentially leading to breaches of confidentiality.

Proof of Concept:

  1. A couple each mint a token with each other through the Soulmate::mintSoulToken function thus making them registered Soulmates with the Soulmate token.

  2. One of the soulmate partner writes to a corresponding soulmate partner via the Soulmate::writeMessageInSharedSpace function whereby the message is saved in the Soulmate::sharedSpace mapping.

  3. The malicious user discovers the randomness issue and exploits it by using a couple of fuzz runs to adjust the variable block.timeStamp and to call the Soulmate::readMessageInSharedSpace function in order to get some expected message.

  4. The malicious user retrieves and logs the expected message returned by the function, exploiting the vulnerability to access private messages between registered Soulmate token couples.

Proof Of Code

Place the following into the SoulmateTest.t.sol.

function testFuzz_maliciousUsercanReenterthefunctionmultipleTimestogetThepredictedMessageWanted(
uint256 numberOfTimesforLength
) public {
string[4] memory niceWords = ["sweetheart", "darling", "my dear", "honey"];
// Ensure numberOfTimesforLength is within the range of valid indices for niceWords
vm.assume(numberOfTimesforLength < niceWords.length);
vm.prank(soulmate1);
soulmateContract.mintSoulmateToken();
vm.prank(soulmate2);
soulmateContract.mintSoulmateToken();
vm.prank(soulmate2);
soulmateContract.writeMessageInSharedSpace("Buy some eggs");
vm.prank(maliciousUser);
vm.warp(numberOfTimesforLength);
string memory message = soulmateContract.readMessageInSharedSpace();
// Select a nice word from the array based on numberOfTimesforLength
string memory niceWord = niceWords[numberOfTimesforLength];
// Concatenate strings using abi.encodePacked
string memory expectedMessage = string(abi.encodePacked("Buy some eggs, ", niceWord));
assertEq(message, expectedMessage, "Message mismatch");
}

Recommended Mitigation: Use external sources of randomness via oracles like Chainlink VRF.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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