hats-finance / Palmera-0x5fee7541ddcd51ba9f4af606f87b2c42eea655be

Palmera hierarchical module
0 stars 1 forks source link

Gas report #63

Open hats-bug-reporter[bot] opened 4 days ago

hats-bug-reporter[bot] commented 4 days ago

Github username: @Jelev123 Twitter username: zhulien_zhelev Submission hash (on-chain): 0x4c6cba4c222829db06204d8010d6186be8cc3c3f58093abf9bb29f19cff44fcf Severity: gas saving

Description: Description\ [Gas-21]Using private rather than public for constants, saves gas

If needed, the values can be read from the verified contract source code, or if there are multiple values there can be a single getter function that returns a tuple of the values of all currently-public constants. Saves 3406-3606 gas in deployment gas due to the compiler not having to create non-payable getter functions for deployment calldata, not having to store the bytes of the value outside of where it's used, and not adding another entry to the method ID table - link

[GAS-2] Cache array length outside of loop

If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation (3 additional gas for each iteration except for the first). - link

[GAS-3]Use calldata instead of memory for function arguments that do not get mutated

When a function with a memory array is called externally, the abi.decode() step has to use a for-loop to copy each index of the calldata to the memory index. Each iteration of this for-loop costs at least 60 gas (i.e. 60 * .length). Using calldata directly bypasses this loop.

If the array is passed to an internal function which passes the array to another internal function where the array is modified and therefore memory is used in the external call, it's still more gas-efficient to use calldata when the external function uses modifiers, since the modifiers may prevent the internal functions from being called. Structs have the same overhead as an array of length one. Saves 60 gas per instance - link

GAS-4]Use != 0 instead of > 0 for unsigned integer comparison link

0xmahdirostami commented 4 days ago

thanks, but gas submission is different in hats.

Please remember the following instructions:

Users need to clone the repository, make changes, and then upload it to their private repository. In their report, they should include the link to their private repository. After that, they will need to invite sponsors to their private repository. The winner will be chosen based on the average gas savings in tests. There are some rules to consider: if any test fails due to changes, the submission is invalid. Additionally, if a user employs assembly, the submission is also invalid. Please read competition scope for more details.