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

Open
code423n4 opened this issue May 11, 2022 · 0 comments
Open

Gas Optimizations #53

code423n4 opened this issue May 11, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Making the uint[19] because they never change and the compiler doesn't know when the array is going to stop.So make them static and that will save gas and confusion.
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L86
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L88
With out the change 0.01354192ETH
With change 0.01339456ETH

Non Initialized variables are already zero bec the slot is not filled and when inlinzed gets stored in storage which is a lot of gas (sstore opcode which is 25000 gas)
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L91
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L90
https://github.com/code-423n4/2022-05-cally/blob/1849f9ee12434038aa80753266ce6a2f2b082c59/contracts/src/Cally.sol#L126
https://github.com/code-423n4/2022-05-cally/blob/1849f9ee12434038aa80753266ce6a2f2b082c59/contracts/src/Cally.sol#L363
—---------------------------------------------------------------------------------------------------------------------
Onlyowner function should be payable because payable does not check msg.value = 0
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L115
https://github.com/code-423n4/2022-05-cally/blob/a2eefbbe6db5b65e81bd1ecb992a401be217a3e6/contracts/src/Cally.sol#L120

Cally.sol gas report

Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 5376231 ┆ 23430 ┆ ┆ ┆ ┆
╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ setFee ┆ 2538 ┆ 16152 ┆ 24531 ┆ 24531 ┆ 5 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌
withdrawProtocolFees ┆ 2490 ┆ 4985 ┆ 4985 ┆ 7480 ┆ 2

Cally.sol gas report with all the changes

Deployment Cost ┆ Deployment Size ┆ ┆ ┆ ┆ │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ 5371031 ┆ 23404 ┆ ┆ ┆ ┆ │

├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
│ setFee ┆ 2514 ┆ 16128 ┆ 24507 ┆ 24507 ┆ 5 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌

withdrawProtocolFees ┆ 2466 ┆ 4961 ┆ 4961 ┆ 7456 ┆ 2

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 11, 2022
code423n4 added a commit that referenced this issue May 11, 2022
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

1 participant