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

Open
code423n4 opened this issue May 1, 2022 · 4 comments
Open

Gas Optimizations #96

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

Comments

@code423n4
Copy link
Contributor

Unnecessary constructor call

The ReentrancyGuard base contract takes no constructor arguments and can be omitted as a modifier for constructor:

constructor(
    IAToken _aToken,
    IRewardsController _rewardsController,
    IPoolAddressesProviderRegistry _poolAddressesProviderRegistry,
    string memory _name,
    string memory _symbol,
    uint8 decimals_,
    address _owner
  ) Ownable(_owner) ERC20(_name, _symbol) ReentrancyGuard() { ... }

Recommendation:

constructor(
    IAToken _aToken,
    IRewardsController _rewardsController,
    IPoolAddressesProviderRegistry _poolAddressesProviderRegistry,
    string memory _name,
    string memory _symbol,
    uint8 decimals_,
    address _owner
  ) Ownable(_owner) ERC20(_name, _symbol) { ... }

balanceOfToken can be declared as a view

The balanceOfToken function is read-only and can be declared as a view.

AaveV3YieldSource.sol#L212:

 function balanceOfToken(address _user) external override returns (uint256) {
    return _sharesToToken(balanceOf(_user));
  }

Recommendation:

 function balanceOfToken(address _user) external view override returns (uint256) {
    return _sharesToToken(balanceOf(_user));
  }

Note that this also declared incorrectly in the IYieldSource interface.

Unnecessary usage of SafeMath library

Solidity 0.8.0 introduced checked arithmetic by default, so the SafeMath library may safely be omitted.

Typo in natspec comment

inhereted should read inherited in the natspec comment on line 38.

@code423n4 code423n4 added bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels May 1, 2022
code423n4 added a commit that referenced this issue May 1, 2022
@PierrickGT PierrickGT self-assigned this May 4, 2022
@PierrickGT PierrickGT added the duplicate This issue or pull request already exists label May 4, 2022
@PierrickGT
Copy link
Member

PierrickGT commented May 4, 2022

Unnecessary constructor call

This is false, the constructor from ReentrancyGuard sets _status = _NOT_ENTERED;
That being said, the ReentrancyGuard would still work properly since the default value of _status is 0, so different from 2.
As a best practice, it is best to initialize it.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol#L40
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/14ca3aeb798d9b9be31df86ae7ef8b8f760caa4c/contracts/security/ReentrancyGuard.sol#L52

balanceOfToken can be declared as a view

Not possible since we inherit from the yield source interface.

Unnecessary usage of SafeMath library

Duplicate of: #11

Typo in natspec comment

Duplicate of: #22

@JeeberC4 JeeberC4 removed the duplicate This issue or pull request already exists label May 6, 2022
@JeeberC4 JeeberC4 reopened this May 6, 2022
@gititGoro
Copy link
Collaborator

Given the sponsor feedback, this is mostly a Gas optimization issue and has been relabelled.

@gititGoro gititGoro marked this as a duplicate and then as not a duplicate of #3 May 16, 2022
@gititGoro gititGoro added the duplicate This issue or pull request already exists label May 20, 2022
@gititGoro
Copy link
Collaborator

Duplicate of #98

@gititGoro gititGoro marked this as a duplicate of #98 May 20, 2022
@JeeberC4 JeeberC4 changed the title QA Report Gas Optimizations May 23, 2022
@JeeberC4
Copy link
Contributor

Changing name to better reflect the judging outcome.

@JeeberC4 JeeberC4 removed duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels May 23, 2022
@JeeberC4 JeeberC4 reopened this May 23, 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