Since you can reroll with a different fighterType than the NFT you own, you can reroll bypassing maxRerollsAllowed and reroll attributes based on a different fighterType
The reRoll function did not check that the supplied fighterType matched the NFT's actual type, so a user could pass a different type to bypass the per-type reroll limit and recalculate attributes using another type's generation and criteria.
klau5 Follow with McToady, vnavascues and 48 others
Originally disclosed on Code4rena
Submitted by klau5, also found by McToady, Tychai0s (1, 2), vnavascues, d3e4, shaka, alexxander, grearlake, AlexCzm, lanrebayode77, evmboi32, givn, juancito, VAD37, Varun_05, DanielArmstrong, linmiaomiao, 14si2o_Flint, Ryonen, n0kto, alexzoid, ktg, denzi_, Aymen0909, Davide, soliditywala, Aamir, sashik_eth, sl1, nuthan2x, 0xAsen, merlinboii, ke1caM, Draiakoo, petro_1912, MrPotatoMagic, PoeAudits, 0xCiphky, aslanbek, 0xvj, cats (1, 2), yotov721, btk, pynschon, solmaxis69, fnanni, 0xAlix2, 0xKowalski, blutorque, t0x1c, ubl4nk, BARW, radin100, Giorgio, zhaojohnson, 0xlemon, jesjupyter, SpicyMeatball, novamanbg, xchen1130, matejdb, haxatron, 0xAleko, Blank_Space, and Silvermist
Can reroll attributes based on a different fighterType, and can bypass maxRerollsAllowed.
Proof of Concept
maxRerollsAllowed can be set differently depending on the fighterType. Precisely, it increases as the generation of fighterType increases.
function incrementGeneration(uint8 fighterType) external returns (uint8) {
require(msg.sender == _ownerAddress);
@> generation[fighterType] += 1;
@> maxRerollsAllowed[fighterType] += 1;
return generation[fighterType];
}
The reRoll function does not verify if the fighterType given as a parameter is actually the fighterType of the given tokenId. Therefore, it can use either 0 or 1 regardless of the actual type of the NFT.
This allows bypassing maxRerollsAllowed for additional reRoll, and to call _createFighterBase and createPhysicalAttributes based on a different fighterType than the actual NFT’s fighterType, resulting in attributes calculated based on different criteria.
function reRoll(uint8 tokenId, uint8 fighterType) public {
require(msg.sender == ownerOf(tokenId));
@> require(numRerolls[tokenId] < maxRerollsAllowed[fighterType]);
require(_neuronInstance.balanceOf(msg.sender) >= rerollCost, "Not enough NRN for reroll");
_neuronInstance.approveSpender(msg.sender, rerollCost);
bool success = _neuronInstance.transferFrom(msg.sender, treasuryAddress, rerollCost);
if (success) {
numRerolls[tokenId] += 1;
uint256 dna = uint256(keccak256(abi.encode(msg.sender, tokenId, numRerolls[tokenId])));
@> (uint256 element, uint256 weight, uint256 newDna) = _createFighterBase(dna, fighterType);
fighters[tokenId].element = element;
fighters[tokenId].weight = weight;
fighters[tokenId].physicalAttributes = _aiArenaHelperInstance.createPhysicalAttributes(
newDna,
@> generation[fighterType],
fighters[tokenId].iconsType,
fighters[tokenId].dendroidBool
);
_tokenURIs[tokenId] = "";
}
}
PoC:
-
First, there is a bug that there is no way to set
numElements, so add a numElements setter to FighterFarm. This bug has been submitted as a separate report.function numElementsSetterForPoC(uint8 _generation, uint8 _newElementNum) public { require(msg.sender == _ownerAddress); require(_newElementNum > 0); numElements[_generation] = _newElementNum; } -
Add a test to the FighterFarm.t.sol file and run it. The generation of Dendroid has increased, and
maxRerollsAllowedhas increased. The user who owns the Champion NFT bypassedmaxRerollsAllowedby putting thefighterTypeof Dendroid as a parameter in thereRollfunction.function testPoCRerollBypassMaxRerollsAllowed() public { _mintFromMergingPool(_ownerAddress); // get 4k neuron from treasury _fundUserWith4kNeuronByTreasury(_ownerAddress); // after successfully minting a fighter, update the model if (_fighterFarmContract.ownerOf(0) == _ownerAddress) { uint8 maxRerolls = _fighterFarmContract.maxRerollsAllowed(0); uint8 exceededLimit = maxRerolls + 1; uint8 tokenId = 0; uint8 fighterType = 0; // The Dendroid's generation changed, and maxRerollsAllowed for Dendroid is increased uint8 fighterType_Dendroid = 1; _fighterFarmContract.incrementGeneration(fighterType_Dendroid); assertEq(_fighterFarmContract.maxRerollsAllowed(fighterType_Dendroid), maxRerolls + 1); assertEq(_fighterFarmContract.maxRerollsAllowed(fighterType), maxRerolls); // Champions maxRerollsAllowed is not changed _neuronContract.addSpender(address(_fighterFarmContract)); _fighterFarmContract.numElementsSetterForPoC(1, 3); // this is added function for poc for (uint8 i = 0; i < exceededLimit; i++) { if (i == (maxRerolls)) { // reRoll with different fighterType assertEq(_fighterFarmContract.numRerolls(tokenId), maxRerolls); _fighterFarmContract.reRoll(tokenId, fighterType_Dendroid); assertEq(_fighterFarmContract.numRerolls(tokenId), exceededLimit); } else { _fighterFarmContract.reRoll(tokenId, fighterType); } } } }
Recommended Mitigation Steps
Check fighterType at reRoll function.
function reRoll(uint8 tokenId, uint8 fighterType) public {
require(msg.sender == ownerOf(tokenId));
require(numRerolls[tokenId] < maxRerollsAllowed[fighterType]);
require(_neuronInstance.balanceOf(msg.sender) >= rerollCost, "Not enough NRN for reroll");
+ require((fighterType == 1 && fighters[tokenId].dendroidBool) || (fighterType == 0 && !fighters[tokenId].dendroidBool), "Wrong fighterType");
_neuronInstance.approveSpender(msg.sender, rerollCost);
bool success = _neuronInstance.transferFrom(msg.sender, treasuryAddress, rerollCost);
if (success) {
numRerolls[tokenId] += 1;
uint256 dna = uint256(keccak256(abi.encode(msg.sender, tokenId, numRerolls[tokenId])));
(uint256 element, uint256 weight, uint256 newDna) = _createFighterBase(dna, fighterType);
fighters[tokenId].element = element;
fighters[tokenId].weight = weight;
fighters[tokenId].physicalAttributes = _aiArenaHelperInstance.createPhysicalAttributes(
newDna,
generation[fighterType],
fighters[tokenId].iconsType,
fighters[tokenId].dendroidBool
);
_tokenURIs[tokenId] = "";
}
}
raymondfam (lookout) commented:
This report covers three consequences from the same root cause of fighter type validation: 1. more re-rolls, 2. rarer attribute switch, 3. generation attribute switch, with coded POC.
brandinho (AI Arena) confirmed
hickuphh3 (judge) increased severity to High and commented:
Note: issue 212’s fix is a little more elegant.
https://github.com/ArenaX-Labs/2024-02-ai-arena-mitigation/pull/17
Status: Mitigation confirmed. Full details in reports from niser93, d3e4, and fnanni.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The reRoll function used the caller-supplied fighterType for limit checks and attribute generation without verifying it matched the token's actual type.
Impact
A user could perform more rerolls than allowed and obtain attributes calculated under a different fighter type's generation and criteria.
What the attacker needed
Own a fighter NFT; enough NRN for reroll cost; another fighter type has a higher reroll limit
The fix
The reRoll function should require that the supplied fighterType matches the token's actual type, for example by checking the dendroid flag.
How it was found
- Increase the generation of the Dendroid fighter type so its maxRerollsAllowed rises.
- Mint a Champion NFT and fund the owner with enough NRN for rerolls.
- Reroll the Champion NFT using its own type until the Champion limit is reached.
- Reroll the same token again while passing the Dendroid type to exceed the Champion limit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Each fighter NFT has a type, and the game allows a limited number of rerolls for each type. The reroll function trusted the type supplied by the caller instead of checking it against the NFT, so a player could claim extra rerolls and get attributes rolled as if the NFT were a different type.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.