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

Audit fix 94 one approve #17

Merged
merged 4 commits into from Jul 12, 2021
Merged

Conversation

aodhgan
Copy link

@aodhgan aodhgan commented Jul 2, 2021

///@notice Approve SUSHI to spend infinite sushiBar (xSUSHI)
/// @dev No initializer flag required
function intialize() external {
sushiAddr.safeApprove(address(sushiBar), type(uint256).max);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe or do we need the intiailizer modifier?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asselstine Is it safe to have public access to this function?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the SushiBar is an immutable contract that is very simple


///@notice Approve SUSHI to spend infinite sushiBar (xSUSHI)
/// @dev No initializer flag required
function intialize() external {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be called 'approveMax' or something

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the function here: 40953c8
We need to use safeIncreaseAllowance, otherwise approve will always revert with SafeERC20: approve from non-zero to non-zero allowance cause we've already approved the max amount in the constructor.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should we add the sponsor and transferERC20 functions?
This way we gonna have to add the onlyOwnerOrAssetManager modifier and we can then use the isOwner function for approveMaxAmount.


mapping(address => uint256) public balances;

constructor(ISushiBar _sushiBar, ISushi _sushiAddr) public {
constructor(ISushiBar _sushiBar, IERC20 _sushiAddr) public {
sushiBar = _sushiBar;
sushiAddr = _sushiAddr;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should approve max here in the constructor as well, so that the yield source is ready

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 40953c8

@PierrickGT PierrickGT force-pushed the audit-fix-94-one-approve branch 2 times, most recently from 4030e79 to 40953c8 Compare July 8, 2021 14:27
/// @return The actual amount of tokens that were redeemed. This may be different from the amount passed due to the fractional math involved.
function redeemToken(uint256 amount) public override returns (uint256) {
/// @return The actual amount of tokens that were redeemed. This may be different from the amount passed due to the fractional math involved.
function redeemToken(uint256 amount) external override returns (uint256) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use a reentrancy guard....is this covered elsewhere?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR yes: #10

@PierrickGT PierrickGT changed the base branch from master to fixes/c4-audit July 12, 2021 14:45
@PierrickGT PierrickGT merged commit a9666b4 into fixes/c4-audit Jul 12, 2021
@PierrickGT PierrickGT deleted the audit-fix-94-one-approve branch July 12, 2021 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants