It shouldn’t be possible to create a vault with Cally’ own token
The Cally contract allowed creating a vault with itself as the token, so the vault's ownership was immediately transferred to the contract. This made the vault unusable and locked any ETH deposited by users who bought or exercised options.
Submitted by p4st13r4, also found by GimelSec, TrungOre, and VAD37
https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L193
https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L199
Impact
Affected code:
- https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L193
- https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L199
Currently it’s possible to create an ERC-721 vault using Cally’ own address as token, and using the freshly minted vault id as tokenIdOrAmount. This results in a new vault whose ownership is passed to Cally contract immediately upon creation.
The vault allows users to perform buyOption and increase the ETH balance of the Cally contract itself, which is still the vault beneficiary. As soon as an user calls exercise, she will receive the vault.tokenIdOrAmount in exchange, which in this case coincides with the vault nft. However this is of no good because the final user may just initiate a withdrawal, which will:
- always fail because the vault id is burned (https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L335) and then transferred back to the user (https://github.com/code-423n4/2022-05-cally/blob/main/contracts/src/Cally.sol#L344)
- leave all the ETH unredemable in Cally contract
So the vault will be unusable and the ETH deposited by users to buy/exercise options will remain locked in Cally contract
Proof of Concept
- Current vault id is, let’s say, 11
- User deploys a vault with Cally’ address as
tokenand13astokenIdOrAmount - Since
createVault()mints the vault token to the user, and then transfers the underlying address from the user, an user is able to create a vault with something she doesn’t own at the moment of thecreateVault()function call, because it’s created while the function runs - The vault
13is pretty limited in functionality, because Cally’ smart contract is the owner - However, users can still buy options: so Alice and Bob deposit their premiums
- Whoever
exercisethe active option, becomes the vault owner now; this is of no good because no one can actually callwithdraw()as it will always revert, and no one can recover the ETH deposited by Alice and Bob as they are locked forever
Recommended Mitigation Steps
Add the following check at the start of createVault():
require(token != address(this), "Cant use Cally as token");
outdoteth (Cally) confirmed, disagreed with severity and commented:
This is an exploit that requires users to actively make a very precise and niche mistake. should be medium severity in our opinion.
fix for this issue is here: https://github.com/outdoteth/cally/pull/10
HardlyDifficult (judge) decreased severity to Medium and commented:
Copying in the POC from GimelSec in #244 because it’s an interesting attack to consider for this issue as well.
Alice (Attacker) pack 2 transactions into same block:
first transaction: calls
createVaultto vault a NFT which worth 100 ETH, with parameters:
dutchAuctionStartingStrikeIndexis set to 0 (whichstrikeOptionsis 1 ETH)- a long
durationDays, e.g.255daysthen Alice will get a
vaultId 1token, and Alice do another transaction: callbuyOption(1)to get aoptionId 2tokenAlice re-vault the
vaultId 1token with strike 89 ETH, and get avaultId 3tokenBob see that the auction of
vaultId 3token is 89 ETH, but thevaultId 3token can get the NFT which worth 100 ETH, so Bob pays 89 ETH, callsbuyOption(3), andexercise(4)to get thevaultId 1token. Then, Bob callsinitiateWithdraw(1)and waits for theoptionId 2token to expire (whichdurationDaysis set to255days in step 1).Alice monitors that someone bought the
vaultId 1token, then Alice quickly callsexercise(2). Finally, Alice just pays Bob 1 ETH, and gets the NFT back. Alice also gets 89 ETH which is paid by Bob from thevaultId 3token.I agree with (2) Medium for this issue. It can be abused, but the impacted parties can clearly see this is an attempt to subvert the system in some way (a vault of a vault with an NFT, instead of a single value with an NFT as expected). That should be a red flag for Bob in the example above.
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
The createVault function did not check that the token address was not the Cally contract itself, allowing a vault to be created with the contract as the underlying token.
Impact
The vault becomes unusable and any ETH deposited by users to buy or exercise options remains locked in the Cally contract.
What the attacker needed
Attacker can call createVault; victim buys option on the vault
The fix
The fix was to add a check at the start of createVault that the token address is not the Cally contract.
How it was found
- Deploy a vault with Cally's address as the token and a future vault id as the tokenIdOrAmount.
- The vault is created and its ownership is passed to the Cally contract.
- Users can still buy options and deposit ETH into this vault.
- If a user exercises the option, they become the vault owner but cannot withdraw because the vault id is burned.
- The ETH deposited remains locked in the Cally contract.
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 vault is a smart contract that holds an NFT and lets others buy options on it. The bug let someone create a vault where the token was the Cally contract itself, so the vault became owned by the contract and could never be withdrawn, trapping any money paid in.
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.