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 #92

Open
code423n4 opened this issue May 1, 2022 · 1 comment
Open

Gas Optimizations #92

code423n4 opened this issue May 1, 2022 · 1 comment
Assignees
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Gas Optimization for PoolTogether Apr-2022 by PeritoFlores

[G-01] Remove OZ SafeMath library to save gas

As you are using the version 0.8 of solidity compiler there is no need to use OZ SafeMath library.

The built-in checks of overflow/underflow in the compiler is much cheaper.

Sample issue

https://issueantenna.com/repo/code-423n4/2022-01-insure-findings/issues/38

Recommended

Make the following changes

#L14

[-] import { SafeMath } from "@openzeppelin/contracts/utils/math/SafeMath.sol";

#L26

 [-] using SafeMath for uint256; 

#L262

[-] uint256 _balanceDiff = _afterBalance.sub(_beforeBalance);
[+] uint256 _balanceDiff = _afterBalance-_beforeBalance;

#L361

[-] return _supply == 0 ? _tokens : _tokens.mul(_supply).div(aToken.balanceOf(address(this)));
[+] return _supply == 0 ? _tokens : _tokens*_supply/aToken.balanceOf(address(this));

#L373

[-]    return _supply == 0 ? _shares : _shares.mul(aToken.balanceOf(address(this))).div(_supply); 
[+]    return _supply == 0 ? _shares : _shares*(aToken.balanceOf(address(this))/_supply;
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 1, 2022
code423n4 added a commit that referenced this issue May 1, 2022
@PierrickGT PierrickGT self-assigned this May 4, 2022
@PierrickGT
Copy link
Member

Duplicate of #11

@PierrickGT PierrickGT marked this as a duplicate of #11 May 4, 2022
@PierrickGT PierrickGT added the duplicate This issue or pull request already exists label May 4, 2022
@JeeberC4 JeeberC4 removed the duplicate This issue or pull request already exists label May 6, 2022
@JeeberC4 JeeberC4 reopened this May 6, 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

3 participants