20,000 USDC
View results
Submission Details
Severity: gas
Valid

Use predefined address instead of `address(this)`

Summary

Instead of using address(this), it is more gas-efficient to pre-calculate and use the predefined address. Foundry's script.sol and Solmate's LibRlp.sol contracts can help pre-determine the address (see computeCreateAddress). The address can be passed in via a constructor argument and assigned to an immutable variable (rather than using a hardcoded constant) so that the code can remain the same across deployments on different networks.

Vulnerability Details

There are 13 instances of this issue.

View 13 Instances
File: src/Fees.sol
28: uint256 amount = IERC20(_profits).balanceOf(address(this));
35: recipient: address(this),
43: IERC20(WETH).transfer(staking, IERC20(WETH).balanceOf(address(this)));
File Link Instance Count Instance Links
Fees.sol 3 28,35,43

File: src/Lender.sol
154: address(this),
189: address(this),
273: address(this),
319: address(this),
644: address(this),
665: address(this),
File Link Instance Count Instance Links
Lender.sol 6 154,189,273,319,644,665

File: src/Staking.sol
39: TKN.transferFrom(msg.sender, address(this), _amount);
57: balance = WETH.balanceOf(address(this));
62: uint256 totalSupply = TKN.balanceOf(address(this));
64: uint256 _balance = WETH.balanceOf(address(this));
File Link Instance Count Instance Links
Staking.sol 4 39,57,62,64

Impact

650 gas

Tools Used

baudit: a custom static code analysis tool; manual review

Recommendations

Use predefined address instead of address(this).

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.