code-423n4 / 2022-06-nibbl-findings

1 stars 0 forks source link

Gas Optimizations #238

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. Title : Value can be caching in calldata instead of memory

File : EIP712Base.sol Line.15

    function INIT_EIP712(string memory name, string memory version) internal {
  1. Title : Using ++i than i++ for saving more gas

Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.

Tools Used

Manual Review

Occurances

main/contracts/Basket.sol#L43        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L70        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L93        for (uint256 i = 0; i < _tokens.length; i++) {

2.) Title : change uint256 i = 0 into uint i for saving more gas

using this implementation can saving more gas for each loops.

Tool Used

Manual Review

Recommended Mitigation

Change it

Occurances

main/contracts/Basket.sol#L43        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L70        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L93        for (uint256 i = 0; i < _tokens.length; i++) {

4.) Title : Caching array length can saving more gas

This implementation can be saving more gas, since if caching the array length is more gas efficient. just because access to a local variable in solidity is more efficient.

Tool Used

Manual Review

Occurances

main/contracts/Basket.sol#L43        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L70        for (uint256 i = 0; i < _tokens.length; i++) {
main/contracts/Basket.sol#L93        for (uint256 i = 0; i < _tokens.length; i++) {
mundhrakeshav commented 2 years ago

2, #3, #6, #7, #8, #15