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

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

Gas Optimizations #19

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

Comments

@code423n4
Copy link
Contributor

Don't Initialize Variables with Default Value

description

Uninitialized variables are assigned with the types default value.

Explicitly initializing a variable with it's default value costs unnecesary gas.

findings

File: Cally.sol
94:     uint256 public feeRate = 0;
95:     uint256 public protocolUnclaimedFees = 0;
282: uint256 fee = 0;

require statements should be checked first

description

require statements can be placed earlier to reduce gas usage on revert
ie move require to the top of the function if possible

findings

File: Cally.sol
269:         require(block.timestamp < vault.currentExpiration, "Option has expired");
272:         require(msg.value == vault.currentStrike, "Incorrect ETH sent for strike");

do not cache variable used only once

description

for variables only used once, changing it to inline saves gas

findings

File: Cally.sol
265: uint256 vaultId = optionId - 1;
333: uint256 optionId = vaultId + 1;
File: CallyNft.sol
44: address from = _ownerOf[id];

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