code-423n4 / 2022-05-factorydao-findings

1 stars 1 forks source link

Gas Optimizations #225

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Issue: Require message is to long Explanation: The messages below can be shortened to 32 characters or fewer (as shown) to save gas

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleDropFactory.sol#L90

        require(treeIndex <= numTrees, "Provided merkle index doesn't exist");

Change message to Provided merkle idx nonexistant

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleDropFactory.sol#L92

        require(!withdrawn[destination][treeIndex], "You have already withdrawn your entitled token.");

Change message to Token you entitled to already wd

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L145

        require(block.timestamp > tranche.lockPeriodEndTime, 'Must wait until after lock period');

Change message to Must wait until aft lock period

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L83

        require(minEndTime < maxEndTime, 'minEndTime must be less than maxEndTime');

Change message to minEndTime must be < maxEndTime

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleIdentity.sol#L127

        require(verifyMetadata(tree.metadataMerkleRoot, tokenId, uri, metadataProof), "The metadata proof could not be verified");

Change message to Metadata proof couldn't be ver

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L98

        require (msg.sender == _owner_, 'Identity: Only owner may call this');

Change message to Identity: Only owner may call

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L136

        require(msg.sender == destination, 'Can only initialize your own tranche');

Change message to Can only initialize own tranche

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L239

        require(isApproved(msg.sender, tokenId), 'Identity: Not authorized to approve');

Change message to Identity: Not authorized to app

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L240

        require(holder != approved, 'Identity: Approving self not allowed');

Change message to Identity: Approving self not ok

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L305

        require(owners[tokenId] == from, "Identity: Transfer of token that is not own");

Change message to Identity: Tfr of token not own

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L306

        require(to != address(0), "Identity: transfer to the zero address");

Change message to Identity: tfr to the 0 address

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L217

        require(checkOnERC721Received(from, to, tokenId, data), "Identity: transfer to non ERC721Receiver implementer");

Not sure how to shorten this message

The same require message occurs in both lines referenced below:

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L141

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L171

        require(initialized[destination][treeIndex], "You must initialize your account first.");

Change message to Must initialize your acct first

Issue: Variables should not be initialized to their default values Explanation: Initializing uint variables to their default value of 0 is unnecessary and costs gas

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L150

        uint currentWithdrawal = 0;

Recommended:

        uint currentWithdrawal;

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/VoterID.sol#L69

    uint public numIdentities = 0;

Recommended:

    uint public numIdentities;

uint currentWithdrawal is initialized to zero twice, as follows:

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L176

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L150

        uint currentWithdrawal = 0;

Recommended:

        uint currentWithdrawal;

uint public numTrees is initialized to zero three times, as follows:

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleDropFactory.sol#L17

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleVesting.sol#L16

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/MerkleResistor.sol#L24

    uint public numTrees = 0;

Recommended:

    uint public numTrees;
illuzen commented 2 years ago

all duplicates