Most of the FTC rewards can be taken by single entity
The FTCHook contract awards FTC tokens when a position is opened but does nothing when it is closed, so a trader can open and immediately close a position to earn the reward without holding it. An attacker could repeat this to capture most of the epoch's rewards, which are meant to be shared among genuine traders.
Malicious actor can collect the most reward which supposed to be share between genuine traders.
There is feature of flex protocol of Flex Trade Credit the user will earn FTC as they trade on the Flex Perpetual. As the position increases the token minted by FTCHook, it’s staked in the TLC Staking for that specific epoch under the user name which increased the position. For that staking, the reward will be issued to the trader in form of USDbC. Instead of opening the position for trading, the user opens the position just for the token and closes it instantly in the same block. As for increasing the position, he would be awarded by FTC but as he closed, instantly no effect on FTC. Because we are doing nothing while decreasing the position.
//FTCHook::onDecreasePosition
function onDecreasePosition(
address _primaryAccount,
uint256,
uint256,
uint256 _sizeDelta,
bytes32
) external onlyWhitelistedCaller {
// Do nothing
}
So what happen is, the reward supposed to be shared between all the Genuine traders. Some malicious actor can target it after checking the specific epoch which benefit him most and mint the stake reward as much as possible for small fees.
Practical example:
This is mere an example, trader can do this in small and big scale as well.
If it’s BTC or ETH market, weight 2.5, so user will receive 250,000 FTC for opening $100,000 position.
The total fee trader paid for this 250,000 FTC is $201; this way trader can earn the gurranteed profit in small fees. When the rewards came, this traders get the most reward of because of his big number of share. This reward is supposed to be share between all the traders who’s risking their collateral.
Proof of Concept
Most of the part of this test is taken by another tests. Current in the setUp weight is set to 1x instead of 2.5x. The tlc (FTC) is supposed to be 250,000.
We need to make the changes in the src/staking/FTCHook.
//FTCHook::onDecreasePosition
function onDecreasePosition(
address _primaryAccount,
uint256,
uint256,
uint256 _sizeDelta,
bytes32
) external onlyWhitelistedCaller {
// Do nothing
}
We need to set some timeFrame if user choose to close the position instantly or within that time frame. The TLC token should be taken back. Like we’re doing in TradingStakingHook::onDecreasePosition.
It’s not obvious from scoped files, but protocol has getStepMinProfitDuration configurations that set’s minimal duration of position depends on position size.
The submission describes that the position creation reward is immediately disbursed by the system and does not wait for any period of time, permitting a user to instantly capture rewards that exceed the system’s imposed fees.
The sponsor claims that the system prevents such scenarios by imposing a minimum step profit duration; however, as its name implies, this time-based restriction is solely imposed on profitable positions and is not activated for zero-profit positions (i.e. ones that are opened and closed immediately).
I believe that a severity of high is appropriate given that the system’s reward mechanism will effectively be compromised and can be compromised to an arbitrary degree via the use of flash-loans or similar mechanisms.
According to the audit rules and provided scope only changes made to the audited scope needs to be audited.
Previous audits: The results of the previous code audit can be found under ./audits. Only the changes made to the files within the defined scope need to be audited.
From the previous audits, both HMXV2 and publicly provided: See here or here. If we take a look at the audits, based on the dates and audit scope, we find out that this is the last audit. The audited commit hash is e7bdee69, while the fixes are conducted in this hash. If we compare the fix to the protocol’s own TLCHook.sol. The difference can be seen here. We’ll see that there are no differences, meaning the fixes have been incorporated into the protocol’s own imported code.
Now, if we compare the protocol’s TLCHook.sol with the inscope FTCHook.sol. The difference is here. As can be seen, there are no major differences beyond naming. As a result, based on the scoping rules, the issue should be out of scope as it’s doesn’t exist in the difference/changes made to the audited scope.
As per the audit scope, it is clearly given that /src/staking/FTCHook.sol is in SCOPE. And if it would not require to be audited then why they even bothered to add it in the scope files when there are so many other contracts is OUT of Scope.
Agreed that this should be OOS or QA. I personally was doing this audit keeping in mind that we have to take into account only differences. So if README states one thing but the issue is judged differently, it’s just unfair to other wardens
@ZanyBonzy, @Aamir, and @ABAIKUNANBAEV; thank you for your PJQA feedback!
I believe that you are misinterpreting what a delta audit is meant to accomplish. A delta audit does not infer that only the code changes are meant to be audited; a code change of function A will not only affect function A but also any other function that invokes it for which the actual code delta would be none.
Additionally, configurational changes are also meant to be evaluated between forks as they can lead to the invalidation of certain presumptions that the original code base made (i.e. configuration of tokens that do not have 18 decimals, etc.).
The original HMX code base issues an escrowed reward token that is native to the protocol as a reward based on trading activities. This directly results in a safeguard against manipulation as incentive rewards could be stifled after an exploitation event is detected, the rewards cannot be immediately captured, and the rewards are in the protocol’s own token. This would be classified as a known issue, and would be of minor-to-moderate severity depending on how one evaluates the issue.
The Flex Perpetual version outlines that the reward token might be an actively traded asset. I was able to find a direct mention of USDbC as the Warden outlines in their submission through Google’s cache, and the latest version of the Flex Perpetuals documentation (updated after the audit’s closure) continues to state that “other incentives” are also meant to be distributed alongside the platform’s vested token.
As we can observe, even if the code remained unchanged, the ramifications of the code’s behaviour have drastically changed. I believe that I have adequately elaborated on the submission’s major severity, and continue to consider it in-scope as the file is explicitly listed within the scope of the audit and the audit’s purpose is to evaluate all the ramifications of the Flex Perpetual team’s changes across the in-scope contracts regardless of whether those changes were direct line updates, configurational changes, or even compiler / EVM differences.
@fpcrypto-y, thanks for your feedback! I am not able to share screenshots here on C4 and the implication is a Google search result so I cannot share a URL. Typing “flex perpetuals USDbC” should demonstrate this as the second link, part of the https://docs.flex.trade/ documentation.
This section of your existing documentation outlines that other incentive rewards will be distributed alongside esFDX which would significantly undermine the security model of the system.
Regarding the protection measure, can you please clarify how it would work if the position did not capture any profit (i.e. remains the same or has lost minuscule funds)? If it does not apply, then the security measure is inexistent for this particular attack vector.
Finally, the code delta does not necessarily imply that code outside the delta is not expected to be audited. As an example, a project deploying to a zkEVM blockchain but using unsupported EVM instructions would be considered “out-of-scope” based on the code delta rationale which is invalid.
Please do let me know how the profit window security measure applies to unprofitable/net-zero trades. If it does, I am more than happy to downgrade this particular vulnerability to a minor issue.
About USDbC - I tried that google search and still couldn’t find where USDbC was distributing as rewards for FTC holders. We distribute USDC to stFDXLP, esFDX stakers, … but not for FTC holders. More details are here.
About the protection - a trader should wait at least 1 minute before closing the trade. That make more difficult to have many zero-profit trades. More details are here.
esFDX reward is not transferrable for users and is under our control. So we have situation that is under our control like you described about HMX:
This directly results in a safeguard against manipulation as incentive rewards could be stifled after an exploitation event is detected, the rewards cannot be immediately captured, and the rewards are in the protocol’s own token.
About adding “other incentives” to the platform - it depends on the amount that would be added. Only after we have info you can prove that a trader will have earnings from zero-net trades.
I think this submission is not a high risk problem.
@fpcrypto-y, once again thank you for your due diligence! I will focus on points 2, 3, and 4 as these are the most prevalent items in your response with regard to this exhibit’s validity.
This limitation applies to profitable trades. Net-zero trades as well as minuscule loss trades are not restricted by it. As such, the argument of the security measure is inapplicable and cannot be a factor in the exhibit’s validity.
The main focus of the report is not esFDX but rather other incentives that are meant to be distributed alongside it. The original documentation of the code did not list “other incentives” and this was included in the Flex Perpetuals iteration of the codebase, signifying that there is intent to add other assets beyond esFDX.
The same response as above applies.
Unless the minimum duration before a trade’s closure applies to unprofitable and net-zero trades alongside profitable trades, I cannot invalidate this exhibit.
I am more than happy to debate whether the submission is a medium-risk or high-risk issue due to the fact that we are making an assumption of what “other incentives” refers to and in most cases the amount that would be added should not be significantly high (i.e. the main incentive would always be esFDX), but I firmly believe it is valid and in-scope of the audit.
@0xsomeone - Thank you for clarifying your point. I agree that this issue is valid. However, I believe the submission’s severity should be adjusted to low-risk or medium-risk.
@fpcrypto-y - I believe that the assumptions that are needed for this submission to be considered valid indeed diminish the likelihood of the vulnerability occurring so a medium severity rating is more appropriate.
I initially thought that the USDbC asset was explicitly mentioned in the documentation, but the cached Google result is insufficient to determine whether it was mentioned in the context of incentives. As the “other incentives” statement has been confirmed to be present, a medium likelihood severity is more appropriate and the submission has been updated as such.
The original report as published on Code4rena, by farman1094. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
A malicious actor could capture most of the epoch's rewards, which are supposed to be shared among genuine traders, for a small fee.
What the attacker needed
Ability to open and close a position; pay small trading and execution fees
The fix
The FTCHook should reverse the FTC reward if a position is closed within a short time frame, similar to TradingStakingHook.
How it was found
Open a large position to earn FTC tokens.
Close the position immediately in the same block.
Withdraw the collateral and keep the FTC reward.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A trading platform gives reward tokens for opening a trade. The code that gives the reward does nothing when the trade is closed, so someone can open and close a trade straight away and keep the reward. They pay only small fees but get a large reward, taking most of the rewards meant for real traders.
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.