Depositing to another receiver othan than `msg.sender` will lead to stuck funds by increasing `avgStart` without claiming
The staking contract's update function claims rewards for the caller (msg.sender) but when a deposit is made to a different address, the receiver's average start time is increased without first claiming their pending rewards. This can delay or reduce the receiver's rewards, and if they withdraw soon after, they may lose accrued rewards.
StakedEXA::_update() is called when minting and if the time staked is smaller than the reference time, it calls _claim(reward), which claims the rewards for the msg.sender. However, the mint may be to someone else other than msg.sender, so avgStart[to]` will increase without first claiming, which will lead to loss of rewards for the receiver of the new deposit.
Root Cause
In StakedEXA.sol::146 on claim(reward), it claims to the msg.sender, but the deposit is done to the to address, which may be different.
Internal pre-conditions
Anyone must do a deposit to a different address.
External pre-conditions
None.
Attack Path
User has some StakedEXA from previous deposits.
Another user deposits/mints to user 1, which increases avgStart[user1], but does not claim first for user1, making the funds stuck.
Impact
The funds are stuck for much longer than they are supposed to. The duration is 24 weeks in the tests, so users can have to wait up to 24 weeks more if they do a really big deposit while having fully claimable rewards. Additionally, in case they decide to withdraw after depositing, before the rewards vest again, they will lose these funds to savings.
PoC
Paste the following test in StakedEXA.t.sol to confirm that address(this) deposits more without claiming.
Claiming should be made to the receiver of the funds, to. The _claim() function should be adapted to receiver an account argument.
Discussion
santiellena
Escalate.
This issue should be Low/Informational.
In order to "exploit" this vulnerability, the attacker has to donate a sufficient amount to the victim to move the avgStart parameter enough. The inability of the victim to withdraw will be temporal and not permanent because as time passes, the penalty decreases, so the issue is incorrect when states that will lead to stuck funds.
Additionally, as this issue is about causing temporal unavailability of part of the funds of a user, the DoS rules might apply.
MARKDOWN
i. The issue causes locking of funds for users for more than a week.
ii. The issue impacts the availability of time-sensitive functions (cutoff functions are not considered time-sensitive). If at least one of these are describing the case, the issue can be a Medium. If both apply, the issue can be considered of High severity. Additional constraints related to the issue may decrease its severity accordingly.
Griefing for gas (frontrunning a transaction to fail, even if can be done perpetually) is considered a DoS of a single block, hence only if the function is clearly time-sensitive, it can be a Medium severity issue.
Point 1) For this to cause unavailability of part of the funds due to temporal penalties for more than a week, big donations must be made which makes the attack unfeasible.
Point 2) Claiming rewards is not time sensitive.
For all of the above, I believe that this issue doesn't warrant medium severity.
sherlock-admin3
Escalate.
This issue should be Low/Informational.
In order to "exploit" this vulnerability, the attacker has to donate a sufficient amount to the victim to move the avgStart parameter enough. The inability of the victim to withdraw will be temporal and not permanent because as time passes, the penalty decreases, so the issue is incorrect when states that will lead to stuck funds.
Additionally, as this issue is about causing temporal unavailability of part of the funds of a user, the DoS rules might apply.
MARKDOWN
i. The issue causes locking of funds for users for more than a week.
ii. The issue impacts the availability of time-sensitive functions (cutoff functions are not considered time-sensitive). If at least one of these are describing the case, the issue can be a Medium. If both apply, the issue can be considered of High severity. Additional constraints related to the issue may decrease its severity accordingly.
Griefing for gas (frontrunning a transaction to fail, even if can be done perpetually) is considered a DoS of a single block, hence only if the function is clearly time-sensitive, it can be a Medium severity issue.
Point 1) For this to cause unavailability of part of the funds due to temporal penalties for more than a week, big donations must be made which makes the attack unfeasible.
Point 2) Claiming rewards is not time sensitive.
For all of the above, I believe that this issue doesn't warrant medium severity.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
0xsimao
The issue is valid because:
It doesn't need to be an attacker, the same user can use one wallet to deposit into another, triggering this bug
It always leads to stuck funds for longer and directly to loss of funds in some cases
Additionally, in case they decide to withdraw after depositing, before the rewards vest again, they will lose these funds to savings.
Due to 1. Making the funds stuck for a lot of time is possible and has no significant requirements (up to 24 weeks as stated in the issue)
santiellena
Agree. However, I still consider it borderline Medium/Low
Temporary unavailability is not loss of funds. In which cases loss of funds occurs?
As stated in the issue, there actually are significant requirements. The user has to duplicate its staking position in that deposit from other wallet.
I will keep the Escalation so the HoJ reviews it. I think both are fair points.
0xsimao
Loss of funds occurs when the user withdraws after depositing. Instead of claiming the rewards on the deposit, avgStart would increase without claiming. Then, when withdrawing, here, on claimWithdraw(), it transfers these rewards to savings, when they should have gone to the user. So the rewards would be lost for the user on unstake. It's not like he can unstake and claim the rewards later, a part of them or all would be lost.
santiellena
You are right @0xsimao, in case of staking and then unstaking that will lead to loss of accrued rewards. Unluckily, I didn't have time to check your point before to delete the escalation.
WangSecurity
I agree with @0xsimao arguments and believe medium severity is appropriate here. If you need a deeper analysis from my side, let me know, but I don't see a point in repeating the same points. Planning to reject the escalation and leave the issue as it is.
The original report as published on Sherlock, by 0x73696d616f. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
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 a minute. 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
The receiver's funds can be stuck for up to 24 weeks longer than intended, and if they withdraw before rewards vest again, they may lose accrued rewards to savings.
What the attacker needed
A user has an existing staking position; another user deposits to that user's address
The fix
The claim should be made to the receiver of the funds (`to`), and the `_claim()` function should be adapted to accept an `account` argument.
How it was found
User has some StakedEXA from previous deposits.
Another user deposits/mints to user 1, which increases `avgStart[user1]`, but does not claim first for user1, making the funds stuck.
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 a minute. 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
In a staking system, users earn rewards over time. The contract tracks when each user's rewards started accruing. When someone deposits tokens for another user, the contract updates that user's start time but forgets to first give them the rewards they've already earned. This means the other user's rewards get delayed or lost.
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.