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

allowToken adds token to the allowedToken list one more time if it was forbidden before #3

Open
0xmikko opened this issue Jan 10, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@0xmikko
Copy link

0xmikko commented Jan 10, 2022

Problem

CreditFilter.sol has a two functions which allow / forbid tokens in allowedTokenList.
When DAO forbids token, it set a mapping value for such address to false:

    /// @dev Forbid token. To allow token one more time use allowToken function
    /// @param token Address of forbidden token
    function forbidToken(address token)
        external
        configuratorOnly // T:[CF-1]
    {
        _allowedTokensMap[token] = false; // T: [CF-35, 36]
    }

Then, if DAO would decide to enable such a token, they should call a method function allowToken(address token, uint256 liquidationThreshold). This method has a part which could add this token twice:

  // we add allowed tokens to array if it wasn't added before
        // T:[CF-6] controls that
        if (!_allowedTokensMap[token]) {
            _allowedTokensMap[token] = true; // T:[CF-4]

            tokenMasksMap[token] = 1 << allowedTokens.length; // T:[CF-4]
            allowedTokens.push(token); // T:[CF-4]
        }

As result, it would add the same token to the allowedTokens twice, which make computation totalValue and health factor wrong.

Solution

Change this block of code to a cycle, which should go through all tokens in allowedTokens array to check has it was added or not. If not, this block of code should be executed:

tokenMasksMap[token] = 1 << allowedTokens.length; // T:[CF-4]
allowedTokens.push(token); // T:[CF-4]
@0xmikko 0xmikko added the bug Something isn't working label Jan 10, 2022
@0xmikko 0xmikko changed the title allowToken adds token to the list one more time if it was forbinned before allowToken adds token to the allowedToken list one more time if it was forbidden before Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant