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

Gas Optimizations #183

Open
code423n4 opened this issue May 8, 2022 · 2 comments
Open

Gas Optimizations #183

code423n4 opened this issue May 8, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Wrap transfer ERC20 transaction into require

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L198

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L230

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L233

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L252

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L269

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L144

  • removing a bool success will save some gas and best practice is to wrap transfer ERC20 transactions to require directly.

Use

require(IERC20(pool.depositToken).transferFrom(msg.sender, address(this), amount), 'Token transfer failed');

Instead of

bool success = IERC20(pool.depositToken).transferFrom(msg.sender, address(this), amount);
require(success, 'Token transfer failed');

Remove unnecessary uint tax

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/PermissionlessBasicPoolFactory.sol#L266-L270

Use

success = success && IERC20(pool.rewardTokens[i]).transfer(globalBeneficiary,  taxes[poolId][i]);
taxes[poolId][i] = 0;

Instead of

uint tax = taxes[poolId][i];
taxes[poolId][i] = 0;
success = success && IERC20(pool.rewardTokens[i]).transfer(globalBeneficiary, tax);
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 8, 2022
code423n4 added a commit that referenced this issue May 8, 2022
@illuzen
Copy link
Collaborator

illuzen commented May 12, 2022

all duplicates

@illuzen illuzen closed this as completed May 12, 2022
@itsmetechjay itsmetechjay reopened this May 12, 2022
@gititGoro gititGoro added the invalid This doesn't seem right label Jun 5, 2022
@gititGoro
Copy link
Collaborator

gititGoro commented Jun 5, 2022

For the uint tax item, the developer is intentionally avoiding a reentrancy threat by ordering the state updates in this manner. That item is therefore invalid.

@gititGoro gititGoro removed the invalid This doesn't seem right label Jun 5, 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 G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

4 participants