Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: low
Valid

`assertValidNonce` incorrectly validates the given nonce

Summary

The validation function LLMOracleCoordinator::assertValidNonce does not correctly follow the assertion mentioned in the code documentation which undeliberately allows a case where SHA3(taskId, input, requester, responder, nonce) == difficulty.

Vulnerability Details

The function LLMOracleCoordinator::assertValidNonce is used to validate the proof of work nonce.

function assertValidNonce(uint256 taskId, TaskRequest storage task, uint256 nonce) internal view {
bytes memory message = abi.encodePacked(taskId, task.input, task.requester, msg.sender, nonce);
if (uint256(keccak256(message)) > type(uint256).max >> uint256(task.parameters.difficulty)) { <@ // Reverts when SHA3(taskId, input, requester, responder, nonce) > difficulty
revert InvalidNonce(taskId, nonce);
}
}

This is incorrect because the documentation inside the LLMOracleTask contract states the following invariant in 2 different instances at L60 and L74 respectively:

/// @dev Proof-of-Work nonce for SHA3(taskId, input, requester, responder, nonce) < difficulty.
uint256 nonce;

Impact

This allows a nonce where SHA3(taskId, input, requester, responder, nonce) == difficulty which is unintended.

Tools Used

Manual Review

Recommendations

It is recommended to use >= instead in assertValidNonce:

function assertValidNonce(uint256 taskId, TaskRequest storage task, uint256 nonce) internal view {
bytes memory message = abi.encodePacked(taskId, task.input, task.requester, msg.sender, nonce);
if (uint256(keccak256(message)) >= type(uint256).max >> uint256(task.parameters.difficulty)) { <@ // Replaced ">" with ">="
revert InvalidNonce(taskId, nonce);
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Incorrect Proof-of-Work Difficulty Check in `assertValidNonce` Function

Support

FAQs

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