The OneShot::getRapperStats function does not validate whether the tokenId provided as an input parameter corresponds to a minted token. The function uses rapperStats mapping to return the rapper stats for a given Id. In solidity if the rapperStats mapping is invoke with invalid token, the mapping will return the default values of each variable.
The OneShot::getRapperStats function does not validate whether the tokenId provided as an input parameter corresponds to a minted token. This could lead to the function returning a default RapperStats struct for non-existent token IDs.
The OneShot::getRapperStats is called in RapBattle::getRapperSkill function. The getRapperSkill function also doesn't validate the input parameter _tokenId. If the getRapperStats returns the default values for the _tokenId, the getRapperSkill will return 65 as a finalSkill.
The OneShot::getRapperStats is public and anyone can call it. If a user calls the function with the non-existing tokenId, the user will receive the default values for rapper stats. So the user will not understand that the tokenId is invalid. The following test shows the scenario when Bob calls the function with non-existing tokenId. You can add the test in the OneShot.t.test file and execute it with the Foundry command: forge test --match-test "testGetRapperStatsWithInvalidTokenId".
The test function testGetRapperSkillNonExistingTokenId demonstrates the sceanrio when the RapBattle::getRapperSkill is called with non-exisiting tokenId. The returned value for the skill will be 65 that is the BASE_SKILL. Execute the function with the Foundry command: forge test --match-test "testGetRapperSkillNonExistingTokenId" -vvvvv.
Manual Review, Foundry
Add a check in the OneShot::getRapperStats or/and in the RapBattle::getRapperSkill for existence of the tokenId.
In OneShot::getRapperStats:
In RapBattle::getRapperSkill:
If you change the RapBattle::getRapperSkill function, you also should add the following in IOneShot.sol file:
function getNextTokenId() external view returns (uint256);
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.