Skip to content
Business logic Audit finding Intermediate

No safety check in addToken

The addToken function in Manager.sol lacks a check to prevent adding the same token twice to a vault or adding a token to multiple vaults. This could cause tokens to be counted twice or break value calculations for a vault.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005, also found by hrkrshnn and 0xRajeev

Impact

There’s no safety check in Manager.sol addToken. There are two possible cases that might happen.

  1. One token being added twice in a Vault. Token would be counted doubly in the vault. Ref: Vault.sol#L293-L303. There would be two item in the array when querying manager.getTokens(address(this));.
  2. A token first being added to two vaults. The value calculation of the first vault would be broken. As vaults[_token] = _vault; would point to the other vault.

Permission keys should always be treated cautiously. However, calling the same initialize function twice should not be able to destroy the vault. Also, as the protocol develops, there’s likely that one token is supported in two vaults. The DAO may mistakenly add the same token twice. I consider this a high-risk issue.

Proof of Concept

Adding same token twice would not raise any error here.

    manager.functions.addToken(vault.address, dai.address).transact()
    manager.functions.addToken(vault.address, dai.address).transact()

Tools Used

Hardhat

Recommended Mitigation Steps

I recommend to add two checks

require(vaults[_token] == address(0));
bool notFound = True;
for(uint256 i; i < tokens[_vault].length; i++) {
    if (tokens[_vault] == _token) {
        notFound = False;
    }
}
require(notFound, "duplicate token");

transferAndCall (yAxis) confirmed and patched:

Please review https://github.com/code-423n4/2021-09-yaxis/pull/2 to verify resolution.

GalloDaSballo (judge) commented:

Lack of check for duplicates can cause undefined behaviour, sponsor mitigated by adding a require check

The original report as published on Code4rena, by jonah1005. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the addToken function lacks a check to ensure the token is not already registered for the vault or any vault.

Impact

A token added twice could be counted doubly in the vault, and a token added to two vaults could break the value calculation of the first vault.

What the attacker needed

Admin privileges to call addToken

The fix

The fix was to add a require check that the token is not already registered for any vault and not already in the vault's token list.

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 smart contract lets an admin add tokens to a vault. The function that adds tokens does not check if the token is already added. So the same token can be added twice, which might make the vault think it has more tokens than it really does, or mess up calculations if the token is added to another vault.

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.

More by jonah1005

View all

39 more disclosed reports, best first.

More from yAxis contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.