Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A DSS cannot stop staking of a vault that doesn't meet its conditions #70

Open
howlbot-integration bot opened this issue Aug 1, 2024 · 6 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-21 grade-b Q-06 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_20_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-07-karak/blob/main/src/entities/Operator.sol#L128

Vulnerability details

Impact

In Operator::validateAndUpdateVaultStakeInDSS() ignoreFailure is set to true which means the DSS cannot cancel a started update even if the vault doesn't meet its conditions anymore.

HookLib.callHookIfInterfaceImplemented({
            dss: dss,
            data: abi.encodeWithSelector(dss.finishUpdateStakeHook.selector, msg.sender),
            interfaceId: dss.finishUpdateStakeHook.selector,
@->         ignoreFailure: true,
            hookCallGasLimit: self.hookCallGasLimit,
            supportsInterfaceGasLimit: self.supportsInterfaceGasLimit,
            hookGasBuffer: self.hookGasBuffer
        });

Proof of Concept

Let's look at the following example:

  1. A vault is staked to one DSS.
  2. Now the operator wants to stake the same vault to another DSS, but that DSS has a condition for accepting new vaults (for example it requires the TVL of the vault to be >= 100 000e18 tokens, assuming 18 decimal precision). The vault currently meets that requirement so the operator calls Core::requestUpdateVaultStakeInDSS() to stake that vault. The DSS accepts it (doesn't revert).
  3. There is a 9 days delay until the update can be finalized. That is a lot of time and in that time a lot can happen. For example the first DSS can execute a slashing (it takes 2 days for the slashing to finalize which is way less than the delay of the update) and now totalAssets() of the vault are <= 100 000e18 which no longer meets the second DSS requirement.
  4. The operator executes Core::finalizeUpdateVaultStakeInDSS() and even if the DSS reverts, it will not affect the transcation and the state will be updated, so now that vault is staked in both DSSs without the consent of the second one.

Notice that Core::requestUpdateVaultStakeInDSS has an ignoreFailure: !requestStakeUpdate.toStake which is correct, however when finalizing, the ignoreFailure is set to true instead of !toStake. This prevents the DSS from canceling the update if the vault changes somehow in the meantime.

Tools Used

Manual Review

Recommended Mitigation Steps

In Operator::validateAndUpdateVaultStakeInDSS() set ignoreFailure to !queuedStakeUpdate.updateRequest.toStake

    function validateAndUpdateVaultStakeInDSS(CoreLib.Storage storage self, QueuedStakeUpdate memory queuedStakeUpdate)
        external
    {
        State storage operatorState = self.operatorState[queuedStakeUpdate.operator];
        validateQueuedStakeUpdate(operatorState, queuedStakeUpdate);
        updateVaultStakeInDSS(
            operatorState,
            queuedStakeUpdate.updateRequest.vault,
            queuedStakeUpdate.updateRequest.dss,
            queuedStakeUpdate.updateRequest.toStake
        );
        delete operatorState.pendingStakeUpdates[queuedStakeUpdate.updateRequest.vault];
        IDSS dss = queuedStakeUpdate.updateRequest.dss;
        HookLib.callHookIfInterfaceImplemented({
            dss: dss,
            data: abi.encodeWithSelector(dss.finishUpdateStakeHook.selector, msg.sender),
            interfaceId: dss.finishUpdateStakeHook.selector,
-            ignoreFailure: true,
+            ignoreFailure: !queuedStakeUpdate.updateRequest.toStake
            hookCallGasLimit: self.hookCallGasLimit,
            supportsInterfaceGasLimit: self.supportsInterfaceGasLimit,
            hookGasBuffer: self.hookGasBuffer
        });
    }

Assessed type

Invalid Validation

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_20_group AI based duplicate group recommendation bug Something isn't working duplicate-54 sufficient quality report This report is of sufficient quality labels Aug 1, 2024
howlbot-integration bot added a commit that referenced this issue Aug 1, 2024
@c4-judge
Copy link
Contributor

MiloTruck marked the issue as unsatisfactory:
Out of scope

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Aug 11, 2024
@c4-judge
Copy link
Contributor

MiloTruck removed the grade

@c4-judge c4-judge removed the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Aug 11, 2024
@c4-judge
Copy link
Contributor

MiloTruck marked the issue as not a duplicate

@c4-judge c4-judge reopened this Aug 11, 2024
@c4-judge
Copy link
Contributor

MiloTruck marked the issue as duplicate of #21

@c4-judge c4-judge added duplicate-21 downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Aug 11, 2024
@c4-judge
Copy link
Contributor

MiloTruck changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

MiloTruck marked the issue as grade-b

@C4-Staff C4-Staff reopened this Aug 21, 2024
@C4-Staff C4-Staff added the Q-06 label Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-21 grade-b Q-06 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_20_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

2 participants