ProfilePicture subprotocol is immutably linked by subprotocolName to the CID protocol
The ProfilePicture contract fixes its subprotocol name at construction time, so it must be registered in the SubprotocolRegistry under exactly that name to work. If someone else registers that name first, the contract cannot simply be re-registered under a different name and would have to be redeployed.
Submitted by d3e4
https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-pfp-protocol/src/ProfilePicture.sol#L59 https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-pfp-protocol/src/ProfilePicture.sol#L99
Besides having to re-register the protocol, it will also have to be redeployed.
Proof of Concept
A protocol is registered by name in the SubprotocolRegistry. Quoting the Canto Identity Protocol contest details:
“In theory, someone can front-run a call to SubprotocolRegistry.register with the same name, causing the original call to fail. There is a registration fee (
100 $NOTE) and the damage is very limited (original registration call fails, user can just re-register under a different name), so this attack is not deemed feasible.”
However, the ProfilePicture subprotocol suffers from the additional issue of also having to be redeployed, making this exploit more severe.
In ProfilePicture, subprotocolName is set on construction.
constructor(address _cidNFT, string memory _subprotocolName) ERC721("Profile Picture", "PFP") {
cidNFT = ICidNFT(_cidNFT);
subprotocolName = _subprotocolName;
subprotocolName is used to retrieve the cidNFTID to which the subprotocols NFT is added.
uint256 cidNFTID = cidNFT.getPrimaryCIDNFT(subprotocolName, _pfpID);
IAddressRegistry addressRegistry = cidNFT.addressRegistry();
if (cidNFTID == 0 || addressRegistry.getAddress(cidNFTID) != ERC721(nftContract).ownerOf(nftID)) {
nftContract = address(0);
nftID = 0; // Strictly not needed because nftContract has to be always checked, but reset nevertheless to 0
}
This means that this subprotocol must be registered under this name, or it will not work. So if ProfilePicture is deployed but someone else manages to register it in the SubprotocolRegistry before the owner (recipient of fees) of ProfilePicture (by frontrunning or otherwise), it cannot simply be re-registered under a different name, but would have to be redeployed with a new name under which it then can be registered.
Recommended Mitigation Steps
Since the subprotocol is meant to be registered with the CID protocol, its deployment and registration should be atomic. Or the name can be initialized after deployment and registration, and set by a (temporary) owner to the name it then has been registered with.
OpenCoreCH (Canto Identity) acknowledged and commented:
We will do deployment and registration in one transaction, but the issue is generally true.
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
Likely the subprotocol name is set immutably in the constructor rather than being assignable after deployment and registration.
Impact
An attacker could front-run the registration to take the name, forcing the owner to redeploy the ProfilePicture contract and re-register under a different name.
What the attacker needed
Attacker registers the name first; registration fee of 100 $NOTE
The fix
Deployment and registration should be atomic, or the name should be set by a temporary owner after registration.
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.
A smart contract here is set up with a fixed name that it later uses to look up data in another contract. If another person grabs that name first in the registry, the original contract can never find its data, and because the name is baked in at creation, the only remedy is to deploy a fresh contract with a new name.
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.