Skip to content
Access control Audit finding Advanced

Any public vault without a delegate can be drained

A public vault created without a delegate has its delegate set to the zero address. Because ecrecover returns the zero address for invalid signatures, an attacker can craft a fake lien request with strategist set to zero, pass signature checks, and borrow all vault funds against a worthless NFT.

obront Follow with HonorLt, rvierdiiev and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/69

Found by

obront, HonorLt, rvierdiiev, cryptphi, yixxas, zzykxx

Summary

If a public vault is created without a delegate, delegate will have the value of address(0). This is also the value returned by ecrecover for invalid signatures (for example, if v is set to a position number that is not 27 or 28), which allows a malicious actor to cause the signature validation to pass for arbitrary parameters, allowing them to drain a vault using a worthless NFT as collateral.

Vulnerability Detail

When a new Public Vault is created, the Router calls the init() function on the vault as follows:

Solidity
VaultImplementation(vaultAddr).init(
  VaultImplementation.InitParams(delegate)
);

If a delegate wasn't set, this will pass address(0) to the vault. If this value is passed, the vault simply skips the assignment, keeping the delegate variable set to the default 0 value:

Solidity
if (params.delegate != address(0)) {
  delegate = params.delegate;
}

Once the delegate is set to the zero address, any commitment can be validated, even if the signature is incorrect. This is because of a quirk in ecrecover which returns address(0) for invalid signatures. A signature can be made invalid by providing a positive integer that is not 27 or 28 as the v value. The result is that the following function call assigns recovered = address(0):

Solidity
    address recovered = ecrecover(
      keccak256(
        encodeStrategyData(
          params.lienRequest.strategy,
          params.lienRequest.merkle.root
        )
      ),
      params.lienRequest.v,
      params.lienRequest.r,
      params.lienRequest.s
    );

To confirm the validity of the signature, the function performs two checks:

Solidity
require(
  recovered == params.lienRequest.strategy.strategist,
  "strategist must match signature"
);
require(
  recovered == owner() || recovered == delegate,
  "invalid strategist"
);

These can be easily passed by setting the strategist in the params to address(0). At this point, all checks will pass and the parameters will be accepted as approved by the vault.

With this power, a borrower can create params that allow them to borrow the vault's full funds in exchange for a worthless NFT, allowing them to drain the vault and steal all the user's funds.

Impact

All user's funds held in a vault with no delegate set can be stolen.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/AstariaRouter.sol#L537-L539

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/VaultImplementation.sol#L118-L124

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/VaultImplementation.sol#L167-L185

Tool used

Manual Review, Foundry

Recommendation

Add a require statement that the recovered address cannot be the zero address:

Solidity
require(recovered != address(0));

Discussion

sherlock-admin

Escalate for 1 USDC

Disagree with high. Requires a external factors and a bit of phishing to make this work. User would have to voluntarily make a lien position that has strategist == address(0) which should raise red flags. Medium seems more fitting.

Relevant lines:

https://github.com/sherlock-audit/2022-10-astaria/blob/7d12a5516b7c74099e1ce6fb4ec87c102aec2786/src/VaultImplementation.sol#L178-L181

You've deleted an escalation for this issue.

zobront

Escalate for 5 USDC

This may be the most severe flaw in the whole protocol. Definitely deserves to be a high.

I’m not sure why it was downgraded, but the deleted escalation seems to think that the strategist needs to be address(0). This isn’t the case. We just need to set the strategist to address(0) in our fake data to make the signature pass.

The delegate is a separate role that can be given access, and any user that doesn’t set a delegate will default to delegate being set to address(0).

Any of these vaults can be drained for every single dollar in the vault due to this flaw.

As you can see from the dups, every single one that realized this exploit marked it as a high. The only mediums are the ones that caught the zero address gap but didn’t understand how it was exploitable.

sherlock-admin

Escalate for 5 USDC

This may be the most severe flaw in the whole protocol. Definitely deserves to be a high.

I’m not sure why it was downgraded, but the deleted escalation seems to think that the strategist needs to be address(0). This isn’t the case. We just need to set the strategist to address(0) in our fake data to make the signature pass.

The delegate is a separate role that can be given access, and any user that doesn’t set a delegate will default to delegate being set to address(0).

Any of these vaults can be drained for every single dollar in the vault due to this flaw.

As you can see from the dups, every single one that realized this exploit marked it as a high. The only mediums are the ones that caught the zero address gap but didn’t understand how it was exploitable.

You've created a valid escalation for 5 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Evert0x

Escalation accepted

sherlock-admin

Escalation accepted

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

The original report as published on Sherlock, by obront. 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.

How it worked

Root cause

The vault does not reject the zero address as a valid signer, and ecrecover returns the zero address for invalid signatures, so a missing delegate allows any signature to pass.

Impact

All user funds held in a vault with no delegate set can be stolen.

What the attacker needed

A public vault with no delegate set; attacker can submit a lien request

The fix

The code should add a require statement that the recovered address cannot be the zero address.

How it was found

  1. Create a public vault without setting a delegate, so the delegate remains the zero address.
  2. Craft a lien request with the strategist field set to the zero address and an invalid signature (v not 27 or 28).
  3. Submit the request; ecrecover returns the zero address, which matches both the strategist and the delegate, so the checks pass.
  4. Borrow the vault's full funds using a worthless NFT as collateral, draining the vault.

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.

A vault is a smart contract that holds other people's money. It checks signatures to make sure a request is approved. If no delegate is set, the vault treats the zero address as the delegate. The signature check function returns the zero address when a signature is invalid, so an attacker can make a fake request look approved and take the money.

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.

More by obront

View all

46 more disclosed reports, best first.

More from Astaria

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.