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

Owner can add more tokens than MAX_TOKENS in BasketFacet #278

Open
code423n4 opened this issue Dec 19, 2021 · 1 comment
Open

Owner can add more tokens than MAX_TOKENS in BasketFacet #278

code423n4 opened this issue Dec 19, 2021 · 1 comment
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Handle

Czar102

Vulnerability details

Impact

In BasketFacet::addToken(...), the MAX_TOKENS check is done before possible reentrancy in the balance(...) function, which is done before adding the token to bs.

An owner can pass ownership to the contract, which adds contracts as tokens, whose balanceOf(...) function allows the attacker contract to call addToken(...) again. The MAX_TOKENS check then passes, because the first added token hasn't been added to bs yet. Thus, an attacker owner can add any number of tokens, being constrained only by block gas limit and stack depth.

Tools Used

Manual analysis

Recommended Mitigation Steps

Consider making the reentrant call a part of the first check in the function.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 19, 2021
code423n4 added a commit that referenced this issue Dec 19, 2021
@loki-sama loki-sama added the help wanted Extra attention is needed label Dec 22, 2021
@loki-sama loki-sama added question Further information is requested sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue and removed help wanted Extra attention is needed question Further information is requested labels Jan 4, 2022
@0xleastwood
Copy link
Collaborator

There is no attack vector. The protectedCall modifier is restricted to a defaultController account. Even then, there is nothing that can be done by reentering the function.

Additionally, I'm not sure if reentrancy is fully understood here. An external call is made to _token, which has to be a contract that the owner controls. There is no benefit by adding useless tokens, except to deny other tokens from being added. But they are the only ones allowed to add tokens, so they are DOS'ing themselves.

Marking as non-critical as it is good practice to implement the checks-effects pattern.

@0xleastwood 0xleastwood added 0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 (Non-critical) Code style, clarity, syntax, versioning, off-chain monitoring (events etc), exclude gas optimisation bug Something isn't working sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

3 participants