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

Open
code423n4 opened this issue Feb 16, 2022 · 1 comment
Open

Gas Optimizations #75

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

Comments

@code423n4
Copy link
Contributor

1. Title : multiple .length call on byteHandle

Summary

It is cheaper to save the length value of the byteHandle
in a local variable than call the .length in every
if condition and loop

POC
https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/libraries/PublishingLogic.sol#L400-L403

2. Title : many function calculation called with the same result

Summary

this function called many times when user interacting with LensHub.
therefore it is cheaper to save the value to a variable in constructor

POC
https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/base/LensNFTBase.sol#L173

3. Title : many boolean operation with the same result

Summary

It is cheaper to save boolean operation result in the local memory when It is going to be used many times.

POC
https://github.com/code-423n4/2022-02-aave-lens/blob/main/contracts/core/FollowNFT.sol#L231-L264

before

function _moveDelegate( address from, address to, uint256 amount ) internal {
        unchecked {
            if (from != address(0)) {
		//statement
	    }
	    if (to != address(0)) {
	    	if (from == address(0)) {
			//statement
		}
	    }
	    else{
	    	if(from != address(0)){
			//statement
		}
	    }
	}
    }

after

function _moveDelegate( address from, address to, uint256 amount ) internal {
        unchecked {
	    bool fromZero = from == address(0);
            if (!fromZero) {
		//statement
	    }
	    if (to != address(0)) {
	    	if (fromZero) {
		     //statement
		}
	    }
	    else{
	    	if(!fromZero){
		     //statement
		}
	    }
	}
    }
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 16, 2022
code423n4 added a commit that referenced this issue Feb 16, 2022
@Zer0dot
Copy link
Collaborator

Zer0dot commented Mar 24, 2022

Great! Except for the 2nd point, although this is valid, we're opting to keep the domain separator calculation as is, it's future-proof, but perhaps down the line in a contract upgrade we can optimize this. All in this PR: lens-protocol/core#80

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

2 participants