Submitted by avoloder, also found by _karanel, stanchev, Trident-Audits, 0xb0k0, Tamer, yaioxy, CyberscopeInterns, AuditGuy, 0xvd, n3smaro, AvantGard, Shahil_Hussain, and ZdravkoHr
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/EntityForging/EntityForging.sol#L102-L144
https://github.com/code-423n4/2024-07-traitforge/blob/279b2887e3d38bc219a05d332cbcb0655b2dc644/contracts/TraitForgeNft/TraitForgeNft.sol#L153-L179
It is possible to get the same NFT (same generation, same entropy) when the forging is done with the same parentId multiple times. Although the number of times this action will be feasible is limited with the forging potential of the token it can still occur at least once.
Scenario:
Add this test to the EntityForging.test.sol contract:
VS Code, Hardhat
You could use a mapping(bytes32 => bool) forgedPairs to store token ids that have been forged before. An additional function to generate the unique key for id pairs would be necessary, for example:
keccak256(abi.encodePacked(id1 < id2 ? id1 : id2, id1 < id2 ? id2 : id1));
This type of hashing would ensure that you treat two pairs in reverse order as the same, since (entropy1 + entropy2) / 2 is the same as (entropy2 + entropy1) / 2.
You could then add require statement to check if the pair has already been used before. Dont forget to add the pairs to the mapping after they have been forged.
Error
TForge1 (TraitForge) confirmed
dimulski (warden) commented:
samuraii77 (warden) commented:
Koolex (judge) commented:
dimulski (warden) commented:
Abdessamed (warden) commented:
Koolex (judge) commented:
