code-423n4 / 2022-02-concur-findings

2 stars 0 forks source link

Gas Optimizations #245

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. considered using != instead of > can save gas https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L236 // gas cost 45422

Change to:

 if (_amount != 0) {

// gas cost 45419

========================================================================

  1. using calldata can save gas https://github.com/code-423n4/2022-02-concur/blob/main/contracts/EasySign.sol#L51 // gas cost 23523

Change to:

function tryRecover(bytes32 hash, bytes calldata signature)

// gas cost 23056

========================================================================

  1. considered using require instead of if can save gas https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L118 // gas cost 24404

Change to:

        require (block.number > pool.lastRewardBlock);
        require (lpSupply != 0); 

// gas cost 24392

========================================================================

  1. considered using require instead of && can save gas https://github.com/code-423n4/2022-02-concur/blob/main/contracts/Shelter.sol#L45 // gas cost 24475

Change to:

        require(activated[_token] != 0);
        require (activated[_token] + GRACE_PERIOD > block.timestamp, "too late");

// gas cost 24162

GalloDaSballo commented 2 years ago

considered using != instead of > can save gas

Not true with optimizer, only valid for require

using calldata can save gas

467 gas

considered using require instead of if can save gas

Require would save gas at cost of functionality, not an optimization

considered using require instead of && can save gas

Pretty sure you're getting savings only on the first revert, because this optimizes for the "bad path" will give it 0 gas savings

Total Gas Saved: 467