You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
uint256 premium =getPremium(vaultId);
require(msg.value>= premium, "Incorrect ETH amount sent");
Can become
require(msg.value >= getPremium(vaultId), "Incorrect ETH amount sent");
Variable premium is not needed as it is only used once. Saves 2600 gas in deployment and 12 gas in buyoption().
2. File:Cally.sol#227
uint32 auctionStartTimestamp = vault.currentExpiration;
require(block.timestamp>= auctionStartTimestamp, "Auction not started");
Can become
require(block.timestamp>= vault.currentExpiration, "Auction not started");
auctionStartTimestamp varable is not needed as vault.currentExpiration is only used once in the function. Saves 1800 gas in deployment and 4 gas in buyOption
This can save quite of bit of gas as the whole Vault struct doesnt have to be copied into memory. 42252 gas is saved on deployment and 733 gas in buyOption() when getPremium() is called.
This can be bumped to a medium severity issue:
Using == operator is 3 gas cheaper than >=. This also keeps people from acedently overpaying when buying an option: #84
Gas optimizations
Can become
Variable premium is not needed as it is only used once. Saves 2600 gas in deployment and 12 gas in buyoption().
2. File:Cally.sol#227
Can become
auctionStartTimestamp varable is not needed as vault.currentExpiration is only used once in the function. Saves 1800 gas in deployment and 4 gas in buyOption
Can become
return premiumOptions[_vaults[vaultId].premiumIndex];
This can save quite of bit of gas as the whole Vault struct doesnt have to be copied into memory. 42252 gas is saved on deployment and 733 gas in buyOption() when getPremium() is called.
4.File: Cally.sol#444
Can become
The calcuation can be done in the if statement to save 1400 gas on deployment and 13 from transferFrom().
Using == operator is 3 gas cheaper than >=. This also keeps people from acedently overpaying when buying an option.
Summary
Implementing each of these would reduce the deploymnt cost from 5,431,682 to 5,387,621 and reduces buyOption from 75,765 to 75,013.
The text was updated successfully, but these errors were encountered: