Skip to content

fix: logic bug in template contract MessageEmitter.sol#246

Merged
anirudhwarrier merged 1 commit intomainfrom
fix/MessageEmiiter-logic-bug
Feb 4, 2026
Merged

fix: logic bug in template contract MessageEmitter.sol#246
anirudhwarrier merged 1 commit intomainfrom
fix/MessageEmiiter-logic-bug

Conversation

@anirudhwarrier
Copy link
Collaborator

Identified in https://github.com/smartcontractkit/cre-workflows/pull/472#discussion_r2754016483

Logic Bug in getMessage

Location:

Solidity

function getMessage(address emitter, uint256 timestamp) public view returns (string memory) {
    bytes32 key = _hashKey(emitter, timestamp);
    require(bytes(s_messages[key]).length == 0, "Message does not exist for the given sender and timestamp");
    return s_messages[key];
}

Problem:

The require checks that the message length is zero (== 0), and reverts with "Message does not exist for the given sender and timestamp".
But a message does exist only if the length is greater than 0. This logic is inverted: it's allowing "empty" messages and reverting if present.

Fix:

The condition should be > 0, not == 0:

Solidity

require(bytes(s_messages[key]).length > 0, "Message does not exist for the given sender and timestamp");

@anirudhwarrier anirudhwarrier requested a review from czar0 February 4, 2026 09:57
@anirudhwarrier anirudhwarrier changed the title fix(template): logic bug in MessageEmitter.sol fix: logic bug in template contract MessageEmitter.sol Feb 4, 2026
@anirudhwarrier anirudhwarrier marked this pull request as ready for review February 4, 2026 10:00
@anirudhwarrier anirudhwarrier requested a review from a team as a code owner February 4, 2026 10:00
@anirudhwarrier anirudhwarrier added this pull request to the merge queue Feb 4, 2026
Merged via the queue into main with commit c30bdd8 Feb 4, 2026
21 checks passed
@anirudhwarrier anirudhwarrier deleted the fix/MessageEmiiter-logic-bug branch February 4, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants