Griefing attack on the Vaults is possible, withdrawing the winning side stakes
The withdraw functions in the vault contracts check that the receiver is approved by the owner, rather than the caller. This allows anyone to trigger a withdrawal for an owner who has approved any address, potentially causing the owner to lose their payout if timed just before the epoch ends.
Submitted by hyh, also found by 0x4non, 0xNazgul, Haruxe, joestakey, KIntern_NA, pauliax, peritoflores, PwnPatrol, Respx, rotcivegaf, scaraven, and Tointer
Vulnerability details
Anyone can withdraw to receiver once the receiver is isApprovedForAll(owner, receiver). The funds will be sent to receiver, but it will happen whenever an arbitrary msg.sender wants. The only precondition is the presence of any approvals.
This can be easily used to sabotage the system as a whole. Say there are two depositors in the hedge Vault, Bob and David, both trust each other and approved each other. Mike the attacker observing the coming end of epoch where no depeg happened, calls the withdraw() for both Bob and David in the last block of the epoch. Mike gained nothing, while both Bob and David lost the payoff that was guaranteed for them at this point.
Setting the severity to be high as this can be routinely used to sabotage the Y2K users, both risk and hedge, depriving them from the payouts whenever they happen to be on the winning side. Usual attackers here can be the users from another side, risk users attacking hedge vault, and vice versa.
Proof of Concept
isApprovedForAll() in withdrawal functions checks the receiver to be approved, not the caller.
SemiFungibleVault’s withdraw:
function withdraw(
uint256 id,
uint256 assets,
address receiver,
address owner
) external virtual returns (uint256 shares) {
require(
msg.sender == owner || isApprovedForAll(owner, receiver),
"Only owner can withdraw, or owner has approved receiver for all"
);
Vault’s withdraw:
function withdraw(
uint256 id,
uint256 assets,
address receiver,
address owner
)
external
override
epochHasEnded(id)
marketExists(id)
returns (uint256 shares)
{
if(
msg.sender != owner &&
isApprovedForAll(owner, receiver) == false)
revert OwnerDidNotAuthorize(msg.sender, owner);
This way anyone at any time can run withdraw from the Vaults whenever owner has some address approved.
Recommended Mitigation Steps
Consider changing the approval requirement to be for the caller, not receiver:
SemiFungibleVault’s withdraw:
function withdraw(
uint256 id,
uint256 assets,
address receiver,
address owner
) external virtual returns (uint256 shares) {
require(
- msg.sender == owner || isApprovedForAll(owner, receiver),
+ msg.sender == owner || isApprovedForAll(owner, msg.sender),
"Only owner can withdraw, or owner has approved receiver for all"
);
Vault’s withdraw:
function withdraw(
uint256 id,
uint256 assets,
address receiver,
address owner
)
external
override
epochHasEnded(id)
marketExists(id)
returns (uint256 shares)
{
if(
msg.sender != owner &&
- isApprovedForAll(owner, receiver) == false)
+ isApprovedForAll(owner, msg.sender) == false)
revert OwnerDidNotAuthorize(msg.sender, owner);
MiguelBits (Y2K Finance) confirmed and commented:
Implementing this.
Agree with the warden’s finding, and the impact of “depriving them (y2k users) from the payouts whenever they happen to be on the winning side”.
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 withdrawal functions check isApprovedForAll(owner, receiver) instead of isApprovedForAll(owner, msg.sender), allowing anyone to withdraw on behalf of an owner who has approved any address.
Impact
An attacker could routinely sabotage users by forcing withdrawals before epoch end, depriving them of payouts when they are on the winning side.
What the attacker needed
Owner has approved at least one address; attacker can call withdraw before epoch ends
The fix
The approval check should be changed to verify that the caller (msg.sender) is approved by the owner, not the receiver.
How it was found
- Bob and David each deposit into the hedge vault and approve each other.
- Mike the attacker observes that the epoch is about to end with no depeg.
- In the last block of the epoch, Mike calls withdraw() for both Bob and David.
- The withdrawals succeed because the receiver (the other user) is approved, and the funds are sent to the receivers.
- Bob and David lose the payoff they would have received for being on the winning side.
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.
In these vaults, users deposit funds and can approve others to withdraw on their behalf. The code mistakenly checks if the receiver is approved, not the person calling the withdrawal. So an attacker can call withdraw for any user who has approved someone, forcing the user's funds to be withdrawn at a bad time, like just before a payout.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.