Skip to content

Instantly share code, notes, and snippets.

@GalloDaSballo
Created November 7, 2022 14:13
Show Gist options
  • Save GalloDaSballo/2bfe8d47a2536cc833ba4a6994061776 to your computer and use it in GitHub Desktop.
Save GalloDaSballo/2bfe8d47a2536cc833ba4a6994061776 to your computer and use it in GitHub Desktop.

Obvious stuff

All tests are missing, no tests = guarantee that the code is unsafe

Personal Thoughts

Not sure why the controller was brought on, but am assuming is as pseudo-registry.

If you with to validate a vault you could compare vs the registry directly via registry.getProductionVaults

I wouldn't recommend that, and instead would recommend allowing the caller to pass in the values (unless the Router has mixed use, but you sent me no additional info so I cannot comment on this).

I would then simplify the withdrawal pattern which looks very off and will most likely cause possibility of griefing and reverts except in the most basic case (defeating the purpose of writing the code)

Badger Thoughts

Hardcoded Controller

I'm pretty sure there's more controllers and some vaults may use those.

The controller in the Registry is the main one, but other controllers do exist so using that approach may cause issues / reverts

V1.5 uses another architecture

While you can get the balance from vault and strategy in the same way, a 1.5 vault will not use the controller, so all calls to it will not work.

This means the Router is relegated to using older vaults.

Code Findings

## Odd "all shares patterns" will cause reverts https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L159-L160

            IERC20(allVaults[i]).safeTransferFrom(msg.sender, address(this), sharesToWithdraw);

If you forcefully withdraw from all vaults, and the caller only has one, they will not be able to withdraw as the transfers will fail

Odd Skip if received less than amount

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L163-L164

            if (withdrawnTotal >= amount) {

I think you want to revert here otherwise the shares have been burnt and wont be sent back

## Unconventional notation

Easier to scan if written 10_000

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L26

_MAX_BASIS = 100_00

## Unclear totalToken

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L42-L43

    function totalToken(address token) public view returns (uint256) {

The function returns the total want in the Vault + Strategy, not clear why

Odd comparison - WRONG

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L122-L123

        require(actualOutput >= before + minOutput, "Insufficient output amount");

While logically similar, it may be best to use the delta out, and do a > comparison

As the above can return true for zero

0 >= 0 + 0

## Technically strategy may have idle want as well

Although strat may charge a withdrawal fee

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L192-L203

Also assuming that the loss will be the withdrawalMaxDeviationThreshold is incorrect. The maxLoss can be that, but it may be zero.

There is no way of knowing beforehand (although 99.99999999% of vaults have zero loss mechanism)

QA Stuff

This is fine because Setts always use 18 decimals but may not work for other projects where each vault has specific decimals

https://github.com/immunefi-team/BadgerVaultRouter/blob/f0e9330b4bb92d0fcd3dd8b1802e747a4db26362/contracts/router/BadgerVaultRouter.sol#L184-L185

        return (amount * 1e18) / IBadgerVault(controller.vaults(token)).getPricePerFullShare();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment