Platform: Code4rena
Start Date: 20/09/2022
Pot Size: $100,000 USDC
Total HM: 4
Participants: 109
Period: 7 days
Judge: GalloDaSballo
Id: 163
League: ETH
Rank: 81/109
Findings: 1
Award: $55.20
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x4non, 0x52, 0x5rings, 0xNazgul, 0xRobocop, 0xSmartContract, 0xdeadbeef, 0xsanson, 8olidity, Amithuddar, Aymen0909, B2, B353N, CertoraInc, Ch_301, Chom, CodingNameKiki, Deivitto, ElKu, Funen, JC, JohnnyTime, Kresh, Lambda, Noah3o6, RaymondFam, ReyAdmirado, RockingMiles, Rolezn, Sm4rty, SuldaanBeegsi, Tadashi, TomJ, Tomio, V_B, Waze, __141345__, a12jmx, ak1, arcoun, asutorufos, aviggiano, berndartmueller, bharg4v, bin2chen, brgltd, bulej93, c3phas, catchup, cccz, ch0bu, cryptonue, cryptphi, csanuragjain, delfin454000, devtooligan, djxploit, durianSausage, eighty, erictee, exd0tpy, fatherOfBlocks, giovannidisiena, hansfriese, ignacio, joestakey, ladboy233, lukris02, m9800, malinariy, martin, minhtrng, obront, oyc_109, pedr02b2, pedroais, pfapostol, philogy, prasantgupta52, rbserver, ronnyx2017, rotcivegaf, rvierdiiev, sach1r0, shung, simon135, throttle, tnevler, tonisives, wagmi, yixxas, zkhorse, zzykxx, zzzitron
55.1985 USDC - $55.20
function gobble( uint256 gobblerId, address nft, uint256 id, bool isERC1155 ) external { // Get the owner of the gobbler to feed. address owner = getGobblerData[gobblerId].owner; // The caller must own the gobbler they're feeding. if (owner != msg.sender) revert OwnerMismatch(owner); // Gobblers have taken a vow not to eat other gobblers. if (nft == address(this)) revert Cannibalism(); unchecked { // Increment the # of copies gobbled by the gobbler. Unchecked is // safe, as an NFT can't have more than type(uint256).max copies. ++getCopiesOfArtGobbledByGobbler[gobblerId][nft][id]; } emit ArtGobbled(msg.sender, gobblerId, nft, id); isERC1155 ? ERC1155(nft).safeTransferFrom(msg.sender, address(this), id, 1, "") : ERC721(nft).transferFrom(msg.sender, address(this), id); }
When feeding gobblers, only checks on address owner and msg.sender are made, when in reality line79 GoblersERC1155B, line 102 GoblersERC721 both use "setApprovalForAll" and "Approve" which can be used as a check to ensure that a work around for using an NFT your not approved to use cannot be found. in the test file "pages" is used to see if you own the nft but this check does not appear to be in the function either
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/test/ArtGobblers.t.sol#L963 https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L723
There does not seem to be any tracking as to what NFTs have been fed to gobblers, I see that there is a mapping to increment the # in this mapping of gobbler id to nft contracts fed and that it maps the gobbler id to nft contract Ids, and increments but does not track NFT address as well as Id.
addresses /// @notice Maps gobbler ids to NFT contracts and their ids to the # of those NFT ids gobbled by the gobbler. mapping(uint256 => mapping(address => mapping(uint256 => uint256))) public getCopiesOfArtGobbledByGobbler;
But it does not appear to be used, I would assume it would maybe used to make sure the same Ids are not used or similar but that does not seem to be a concerne either (at least it appears not to check if the same id have been used before) this would be good to use as a check to make sure the same Ids of nfts are not being used to feed the gobbler, or use this in a public veiwable function that ties address(this) too ids of copiesOfArtGobbledByGobbler, so that a user can see what Ids etc have been used on thier gobbler.
No check on what NFT you can feed the gobbler, this could leave this function open to an inexperienced user feeding a gobbler an NFT of high value accidentely, unless this is how the dev intended this function to work(that any NFT can be used) as atm user can simply add "Address, Id" of any nft user owns, Instigate a check here to see what exaclty the NFT is for example "Pages" as i see this used in the TEST file it would be a good use case here to ensure the right NFT is being used.
Best practice here would be to add checks for the following as well as does user own the gobbler, is user msg.sender, does user own the NFT they want to feed the gobbler and or is user approved to use said NFT, has it been used before (ID reuse) is it ERC1155, ERC721, is it the correct NFT (not one user owns thats worth £2k)
#0 - GalloDaSballo
2022-10-06T20:28:18Z
NC
NC
Disputed / bulked with the above
2NC
#1 - GalloDaSballo
2022-10-06T20:28:38Z
I think the manual report is a good start, but the report missed tons of other aspects of the code