Platform: Code4rena
Start Date: 17/03/2023
Pot Size: $36,500 USDC
Total HM: 10
Participants: 98
Period: 3 days
Judge: leastwood
Total Solo HM: 5
Id: 223
League: ETH
Rank: 65/98
Findings: 1
Award: $22.77
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Sathish9098
Also found by: 0xAgro, 0xSmartContract, 0xdaydream, 0xnev, Awesome, Aymen0909, BRONZEDISC, Bauchibred, Deathstore, Diana, IceBear, Jerry0x, Kresh, Matin, Rolezn, Stryder, T1MOH, Udsen, adriro, alejandrocovrr, atharvasama, codeslide, cryptonue, descharre, igingu, jack, joestakey, libratus, lukris02, luxartvinsec, nadin, nasri136, reassor, scokaf, shark, slvDev, tnevler
22.7749 USDC - $22.77
The Tray.getTile()
function would always return 0 when _tileOffset>=7
but users might not know why
The Tray..getTile()
function provides information about one tile and it takes in two parameters uint256 _trayId
and uint8 _tileOffset)
, the function does include a check for when the _trayId
is non existent, L196 of Tray.sol:
if (!_exists(_trayId)) revert TrayNotMinted(_trayId);
But there are no checks to confirm that _tileOffset < 7
, and its explicitly stated that _tileOffset
needs to be between 0 .. TILES_PER_TRAY - 1
in the param natspec of _tileOffset
at L194:
/// @param _tileOffset Offset of the tile within the query, needs to be between 0 .. TILES_PER_TRAY - 1
meaning that when a user calls this function with an invalid tile offset they get a wrong return value and might not understand what the issue is.
Create an additional error case:
error InvalidTileOffset(uint8 _tileOffset)
Add a conditiion to Tray.getTile()
that _tileOffset
must be between 0 .. TILES_PER_TRAY - 1
function getTile(uint256 _trayId, uint8 _tileOffset) external view returns (TileData memory tileData) {
if (!_exists(_trayId)) revert TrayNotMinted(_trayId);
if(_tileOffset >= 7) revert InvalidTileOffset(uint8 _tileOffset)
tileData = tiles[_trayId][_tileOffset];
}
note
and/or revenue
addresses to the zero address should be avoided.If both or either of note
and revenue
addresses gets set to the zero address, any call to these contracts while being set to 0 is going to lead to unexpected behaviour such as contract reverts and force redeployments
There are no zero address checks in the functions Namepsace.changeNoteAddress()
and Namepsace.changeRevenueAddress()
function changeNoteAddress(address _newNoteAddress) external onlyOwner { address currentNoteAddress = address(note); note = ERC20(_newNoteAddress); emit NoteAddressUpdate(currentNoteAddress, _newNoteAddress); }
function changeRevenueAddress(address _newRevenueAddress) external onlyOwner { address currentRevenueAddress = revenueAddress; revenueAddress = _newRevenueAddress; emit RevenueAddressUpdated(currentRevenueAddress, _newRevenueAddress); }
Zero address checks should be added
Namespace.fuse()
functionUsers might not understand why their transaction is reverting
The revert error InvalidNumberOfCharacters()
is only used once in Namespace.sol at L112
if (numCharacters > 13 || numCharacters == 0) revert InvalidNumberOfCharacters(numCharacters);
As evident it's used to revert the case when the number of characters are more than 13, but the name of the error suggests otherwise and might lead users to not really understand why their transaction is reverting.
Change error name from InvalidNumberOfCharacters(uint256 numCharacters) to NumberOfCharactersTooLong(uint256 numCharacters)
Simplified code can help users/developers understand and use code easier.
Utils.sol L179-181 Includes script and also comments before these lines indicate that the 3 characters come from a different UTF-8 block, and therefore the values got hardcoded, but for all three cases the value returned are the same and as such all three conditions can be combined into one with the help of the OR operator.
Change the below:
if (_characterIndex == 4) return hex"F09D9192";
if (_characterIndex == 6) return hex"F09D9194";
if (_characterIndex == 14) return hex"F09D919C";
to:
if (_characterIndex == 4 || _characterIndex == 6 || _characterIndex == 14) ) return hex"F09D9192";
#0 - c4-judge
2023-04-11T16:20:03Z
0xleastwood marked the issue as grade-b