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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal _flashFee without validation to ERC20FlashMint #3331

Closed
mazenkhalil opened this issue Apr 9, 2022 · 11 comments 路 Fixed by #3551
Closed

Add internal _flashFee without validation to ERC20FlashMint #3331

mazenkhalil opened this issue Apr 9, 2022 · 11 comments 路 Fixed by #3551
Labels
good first issue Low hanging fruit for new contributors to get involved!
Milestone

Comments

@mazenkhalil
Copy link
Contributor

馃 Motivation

I have came across the below function where implementers can to override to customize the functionality.
The thing is the validation within the base implementation. Basically as a developer, I would expect the function to act as getter returning the fee amount while keeping all validations in place. But overriding this function leads to overriding the default validations as well.

    function flashFee(address token, uint256 amount) public view virtual override returns (uint256) {
        require(token == address(this), "ERC20FlashMint: wrong token");
        // silence warning about unused variable without the addition of bytecode.
        amount;
        return 0;
    }

Similar case can be seen in the below function. But this time the base implementation has assumption than can be overloaded as well.

    function maxFlashLoan(address token) public view virtual override returns (uint256) {
        return token == address(this) ? type(uint256).max - ERC20.totalSupply() : 0;
    }

I believe such flow (validation/assumption within override functions) is dangerous and should be addressed to mitigate the risks that could arise in implementation contracts.

@frangio
Copy link
Contributor

frangio commented Apr 11, 2022

A fix for this would be to define an internal function _flashFee to be the one that should be overriden.

@mazenkhalil
Copy link
Contributor Author

mazenkhalil commented Apr 12, 2022

Is it ok to make a major change? Adding _flashFee function would require implementers to change their current implementation upon upgrade. (considering that override modifier will be removed from current function)

@frangio frangio changed the title Overloaded functions with validation Add internal _flashFee without validation to ERC20FlashMint Jun 27, 2022
@frangio frangio added this to the 4.8 milestone Jun 27, 2022
@frangio
Copy link
Contributor

frangio commented Jul 4, 2022

Just seeing the question in the last comment.

(considering that override modifier will be removed from current function)

The override modifier shouldn't be removed.

@frangio frangio added the good first issue Low hanging fruit for new contributors to get involved! label Jul 6, 2022
@nirban256
Copy link
Contributor

Hey @frangio I would like to work on this issue, can I start working on it?

@frangio
Copy link
Contributor

frangio commented Jul 8, 2022

Yes go ahead.

@nirban256
Copy link
Contributor

ok

@nirban256
Copy link
Contributor

Hey @frangio do I need to write the tests or is it fine if I push the code directly?

@Amxx
Copy link
Collaborator

Amxx commented Jul 12, 2022

the new code need to be covered by test. Existing one may or may not be enough. In this case, we will probably want some small tests.
Also, we will need a changelog entry.

@nirban256
Copy link
Contributor

the new code need to be covered by test. Existing one may or may not be enough. In this case, we will probably want some small tests. Also, we will need a changelog entry.

What type of test will be needed?
Like the function _flashFee is calling another function flashFee inside it which is returning the amount, so what type of test needs to be written like the amount that is being returned by the flashFee function is equal to the amount that is received by the _flashFee function?

@frangio
Copy link
Contributor

frangio commented Jul 14, 2022

@nirban256 Please just do your best effort to test it and open a PR, we will leave feedback in the PR.

@nirban256
Copy link
Contributor

nirban256 commented Jul 15, 2022

ok @frangio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Low hanging fruit for new contributors to get involved!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants