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

Open
code423n4 opened this issue Jul 16, 2022 · 0 comments
Open

Gas Optimizations #45

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

Comments

@code423n4
Copy link
Contributor

gas optimization

G01: COMPARISONS WITH ZERO FOR UNSIGNED INTEGERS

problem

0 is less gas efficient than !0 if you enable the optimizer at 10k AND you’re in a require statement. Detailed explanation with the opcodes https://twitter.com/gzeon/status/1485428085885640706

prof

'Witch.sol', 254, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 299, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 357, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 392, ' if (liquidatorCut > 0) {
'Witch.sol', 397, ' if (auctioneerCut > 0) {
'Witch.sol', 415, ' require(auction_.start > 0, "Vault not under auction");

G02: custom error save more gas

problem

Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met) while providing the same amount of information, as explained https://blog.soliditylang.org/2021/04/21/custom-errors/.
Custom errors are defined using the error statement.

prof

'Witch.sol', 83, ' require(param == "ladle", "Unrecognized");
'Witch.sol', 101, ' require(initialOffer <= 1e18, "InitialOffer above 100%");
'Witch.sol', 102, ' require(proportion <= 1e18, "Proportion above 100%");
'Witch.sol', 103, ' require(
'Witch.sol', 107, ' require(proportion >= 0.01e18, "Proportion below 1%");
'Witch.sol', 188, ' require(cauldron.level(vaultId) < 0, "Not undercollateralized");
'Witch.sol', 199, ' require(limits_.sum <= limits_.max, "Collateral limit reached");
'Witch.sol', 254, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 255, ' require(cauldron.level(vaultId) >= 0, "Undercollateralized");
'Witch.sol', 299, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 312, ' require(liquidatorCut >= minInkOut, "Not enough bought");
'Witch.sol', 327, ' require(baseJoin != IJoin(address(0)), "Join not found");
'Witch.sol', 357, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 364, ' require(liquidatorCut >= minInkOut, "Not enough bought");
'Witch.sol', 394, ' require(ilkJoin != IJoin(address(0)), "Join not found");
'Witch.sol', 415, ' require(auction_.start > 0, "Vault not under auction");
'Witch.sol', 436, ' require(

G03: X += Y COSTS MORE GAS THAN X = X + Y FOR STATE VARIABLES

prof

'Witch.sol', 258, ' limits[auction_.ilkId][auction_.baseId].sum -= auction_.ink;

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