Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: medium
Invalid

assertvalidnonce will revert when difficulty is 10

Summary

https://github.com/Cyfrin/2024-10-swan-dria/blob/c8686b199daadcef3161980022e12b66a5304f8e/contracts/llm/LLMOracleCoordinator.sol#L313C4-L317C10

in the LLMOracleCoordinator.sol the assertvaidnonce function first creates a hash of the concatenated message (which includes the taskId, input, requester, sender, and nonce It converts the hashed message to a uint256 value and compares it to a threshold. The threshold is determined by the difficulty parameter.
If the hash value is greater than this threshold, it indicates that the nonce is invalid based on the difficulty requirement

Vulnerability Details

The threshold for valid hashes is calculated using a right bitwise shift based on the difficulty parameter:

threshold = type(uint256).max >> uint256(task.parameters.difficulty);

This operation effectively divides the maximum possible uint256 value by 2difficulty

For difficulty = 10, the threshold becomes approximately 2**246 meaning that only hashes lower than this value are considered valid.

The computed hash can exceed the threshold if it falls into the upper half of possible hash values. Given that the output of the Keccak-256 hash is uniformly distributed, it’s statistically likely that some hashes will be above
2**246

also setting difficulty is permissionless anyone an set the difficulty from 1 to 10

Impact

unecessary revert

Tools Used

Recommendations

remove the check

Updates

Lead Judging Commences

inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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