In the contract https://github.com/Cyfrin/2024-07-ark-project/apps/blockchain/ethereum/src/token/Deployer.sol
The functions deployERC721Bridgeable and deployERC1155Bridgeable in the Deployer library are publicly accessible. This means any address can call these functions to deploy new instances of ERC721 or ERC1155 contracts.
Impact:
Unauthorized users can deploy new contracts, leading to unexpected contract creations.
This can result in network congestion, unexpected gas costs, and potential misuse of resources.
Proof of Concept:
The following tests were executed to confirm the vulnerability:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test} from "forge-std/Test.sol";
import {Deployer} from "../src/token/Deployer.sol";
contract UnrestrictedAccessTest is Test {
address owner;
address nonOwner;
}
Results:
Ran 2 tests for test/Exploit.t.sol:UnrestrictedAccessTest
[PASS] testDeployERC1155BridgeableUnrestrictedAccess() (gas: 2170608)
[PASS] testDeployERC721BridgeableUnrestrictedAccess() (gas: 1936736)
Suite result: ok. 2 passed; 0 failed; 0 skipped; finished in 8.68ms (7.96ms CPU time)
Ran 1 test suite in 35.48ms (8.68ms CPU time): 2 tests passed, 0 failed, 0 skipped (2 total tests)
The tests passed, confirming that non-owner addresses could deploy new instances of ERC721 and ERC1155 contracts.
Mitigation:
To mitigate this vulnerability, add access control to the deployERC721Bridgeable and deployERC1155Bridgeable functions. Here is how you can do it using OpenZeppelin's Ownable contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "./ERC721Bridgeable.sol";
import "./ERC1155Bridgeable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/**
@title Collection contract deployer.
*/
contract Deployer is Ownable {
}
Explanation
Ownable Contract: The Deployer contract now inherits from OpenZeppelin's Ownable contract.
Access Control: The onlyOwner modifier is added to deployERC721Bridgeable and deployERC1155Bridgeable functions to restrict access to only the contract owner.
Conclusion
By adding access control, you ensure that only authorized users can deploy new instances of ERC721 and ERC1155 contracts, preventing unauthorized and potentially malicious deployments.
Tools used: Foundry
Please, do not suppose impacts, think about the real impact of the bug and check the CodeHawks documentation to confirm: https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity A PoC always helps to understand the real impact possible.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.