CertiK reviewed TURNUP on 25 Jan 2024: 24 findings, 1 critical; 17 marked fixed, 2 acknowledged, 5 open.
Report hosted on skynet.certik.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 1 |
| High | 0 | 2 | 2 |
| Medium | 0 | 0 | 4 |
| Low | 5 | 0 | 10 |
The issue in the `sellShares()` function of the `TurnupSharesV4` contract is that it restricts the wisher from selling all their shares, including the first share, by the internal `_checkBalance()` function. ```solidity=400 function _checkBalance(address sharesSubject, uint256 balance, uint256 amount) internal view { if (balance < amount) revert InsufficientKeys(balance); if (sharesSubject == _msgSender() && balance == amount) revert CannotSellLastKey(); } ``` The `_checkBalance()` function is called to verify if the wisher has sufficient shares to sell and if they are attempting to sell their last share. If the wisher's balance is equal to the amount they want to sell, the function reverts with the error message `CannotSellLastKey()`. This check is intended for regular KEY subjects to prevent them from selling their only share, which was bought for free. However, for wishers, the situation is different. After creating a wish, there are reserved shares in the wish subject. The wisher should be able to purchase additional shares based on the non-zero supply. Even for the wisher themselves, they should pay for their first share. But the current implementation prevents the wisher from selling their first share, which is unfair. Likewise, if a wisher is associated with a subject, following this, if the subject purchases just one share of itself, it's not cost-free and cannot be sold.
In the execution of the `buyShares` and `sellShares` functions, a subject fee is applied when purchasing wishes, and if wishes expire without being linked to a share subject during the selling process, the subject fee is refunded to the wishes buyer. However, the subject fee amount is determined by the current total supply of wishes and the ongoing trading amount. Consequently, the subject fee incurred during the purchase of wishes may differ from the amount incurred during the sale of wishes. We would like to confirm with the team if this is aligned with the original design.
Based on the discussion regarding finding `TSV-18`, it was determined that the wisher address should be a pseudo address that cannot be used to purchase shares. However, there is currently no validation in the `newWishPass()` function to enforce this requirement. ```solidity=588 function newWishPass(address wisher, uint256 reservedQuantity) external virtual onlyOperator { if (sharesSupply[wisher] > 0) revert CannotMakeASubjectAWish(); if (reservedQuantity == 0 || reservedQuantity > 50) revert ReserveQuantityTooLarge(); if (wisher == address(0)) revert InvalidZeroAddress(); if (wishPasses[wisher].owner != address(0)) revert ExistingWish(wishPasses[wisher].owner); wishPasses[wisher].owner = wisher; wishPasses[wisher].reservedQuantity = reservedQuantity; wishPasses[wisher].totalSupply = reservedQuantity; wishPasses[wisher].createdAt = block.timestamp; emit WishCreated(wisher, reservedQuantity); } ```
The issue lies within the `TurnupSharesV4` contract where users are required to pay additional protocol fees and subject fees while purchasing or selling shares. The protocol fee is transferred to the `protocolFeeDestination` address, which can be altered by the contract owner. ```solidity (bool success2, ) = protocolFeeDestination.call{value: protocolFee}(""); ... if (!success1 || !success2) revert UnableToSendFunds(); ``` If the `protocolFeeDestination` is a malicious contract that either lacks a `receive()` or `fallback()` function, or explicitly rejects incoming native coins, this will lead to the entire transaction being reverted. This means that users will be unable to buy or sell shares - a situation known as a denial of service (DoS) attack. In essence, the problem is that the `TurnupSharesV4` contract does not handle potential failure when sending protocol fees to `protocolFeeDestination`. If the address set as `protocolFeeDestination` is a contract that cannot receive Ether, it will cause the `TurnupSharesV4` contract's buy and sell operations to fail. This vulnerability could be exploited maliciously to disrupt the contract's normal operation and cause a DoS issue.
The `newWishPass`, `bindWishPass`, and `claimReservedWishPass` functions, in combination with the `getPrice` function, create a scenario where the `sharesSubject` (the account bound to a wish pass) may have an unfair advantage over other users in the contract's share market. Let's analyze the `getPrice` first. ```solidity function getPrice(uint256 supply, uint256 amount) public pure virtual returns (uint256) { uint256 sum1 = supply == 0 ? 0 : ((supply - 1) * (supply) * (2 * (supply - 1) + 1)) / 6; uint256 sum2 = supply == 0 && amount == 1 ? 0 : ((supply + amount - 1) * (supply + amount) * (2 * (supply + amount - 1) + 1)) / 6; uint256 summation = sum2 - sum1; return (summation * 1 ether) / 2000; } ``` The function uses a quadratic summation formula to determine the price. This formula depends on the current supply and the amount of new shares being bought. The formula appears to be a variation of a sum of squares formula, which typically exhibits quadratic growth. The pricing formula exhibits quadratic growth relative to the supply of shares. This means that the price per share will increase as more shares are bought, and the rate of increase will itself increase as the supply grows. In such a pricing model, early buyers will purchase shares at a lower price compared to later buyers, as the price per share increases with each subsequent purchase. For early buyers to sell their shares at a profit, they would need to find buyers willing to purchase the shares at the higher current market price, which is determined by the increased supply. Then let's analyze the functions `newWishPass`, `bindWishPass`, and `claimReservedWishPass` in conjunction with the `getPrice` function to understand if the design potentially provides an unfair advantage to the `sharesSubject` (the account bound to a wish pass). - `newWishPass`: This function allows the operator to create a new wish pass with a specified `reservedQuantity` of shares for the wisher. The reserved quantity is initially set aside for the wisher for the initial supply. - `bindWishPass`: This function binds a `sharesSubject` to the created wish pass. This means the `sharesSubject` is now associated with the wish pass that has a set reserved quantity of shares. - `claimReservedWishPass`: This function allows the `sharesSubject` to buy the reserved quantity of shares. Importantly, the price for these shares is calculated using `getPrice(0, amount)`, which essentially means the price is computed as if there are no prior shares in supply (since supply is set to 0 in the calculation). After claiming the reserved shares, the `sharesSubject` can sell these shares. The selling price would be based on `getPrice(supply - reservedQuantity, amount)`, which considers the total supply minus the reserved quantity. The advantages of `sharesSubject` account: - **Lower Purchase Price for `sharesSubject`**: The `sharesSubject` can obtain the reserved quantity of shares at a significantly lower price (as if they were the first buyer), irrespective of the actual supply at the time of claiming. This is a substantial advantage. - **Profit Opportunity Without Initial Capital**: The `sharesSubject` can potentially sell these shares immediately at the current market price, which would likely be higher due to other shares in circulation. This means they can profit without having initially invested any capital. - **Flash Loans Opportunity**: The `sharesSubject` could leverage flash loans to claim and sell these reserved shares without any personal financial risk or upfront investment, potentially utilizing this mechanism for profit. Regular users have to buy shares at the current market price, which is influenced by the total supply of shares. They do not have the privilege of buying shares at a base price (as if they were the first buyers), unlike the `sharesSubject`.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (1)
1,045 projects reviewed · 1,376 reports · latest May 2025
See CertiK’s auditsSomething wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.
Tell us