Vulnerability Details
In 'FjordAuctionFactory', the owner can create an auction (FjordAuction) calling 'FjordAuctionFactory::createAuction'.
The problem is that a certain auction with the same values can be created.
Impact
If this happens the transaction will fail because there can't be two contracts with the same address.
POC
function test_vulnerability_cantCreateAContractWithAnAddressAlreadyExistent() public {
bytes32 salt = bytes32(keccak256(abi.encode("Pepe to the moon")));
address auctionToken = 0x6982508145454Ce325dDbE47a25d4ec3d2311933;
uint256 biddingTime = 7 days;
uint256 totalTokens = 1_000_000;
vm.startPrank(owner);
deal(auctionToken, owner, 2_000_000);
ERC20(auctionToken).approve(address(auctionFactory), 2_000_000);
auctionFactory.createAuction(auctionToken, biddingTime, totalTokens, salt);
vm.expectRevert();
auctionFactory.createAuction(auctionToken, biddingTime, totalTokens, salt);
vm.stopPrank();
}
Tools Used
Manual review, Foundry
Recommendations
Consider using create instead of using create2 to create auctions.
Consider changing the logic of 'FjordAuctionFactory::createAuction' in this:
function createAuction(
address auctionToken,
uint256 biddingTime,
uint256 totalTokens
) external onlyOwner {
address auctionAddress = address(
new FjordAuction(fjordPoints, auctionToken, biddingTime, totalTokens)
);
IERC20(auctionToken).transferFrom(msg.sender, auctionAddress, totalTokens);
emit AuctionCreated(auctionAddress);
}