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

Calculate the balance difference consistently #105

Open
gpersoon opened this issue Oct 12, 2021 · 0 comments
Open

Calculate the balance difference consistently #105

gpersoon opened this issue Oct 12, 2021 · 0 comments

Comments

@gpersoon
Copy link

Vulnerability details

The function function convert of GeneralConverter.sol calculates the number of tokens to be transferred by subtracting the balance after with the balance before.

                   uint256 _before = xxx.balanceOf(address(this));
                   // action
                   uint256 _after = xxx.balanceOf(address(this));
                    _outputAmount = _after.sub(_before);
                    xxx.safeTransfer(msg.sender, _outputAmount);

However this only happens in the first 2 pieces of the code (e.g. swapping to or from tokenCRV).
When swapping between 2 of the underlying tokens this pattern isn't used.

Proof of concept

_outputAmount = IERC20(_output).balanceOf(address(this));
IERC20(_output).safeTransfer(msg.sender, _outputAmount);

Recommended mitigation steps

Use the pattern to calculate the balance difference also when swapping between 2 of the underlying tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant