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

Open
code423n4 opened this issue Feb 23, 2022 · 1 comment
Open

Gas Optimizations #117

code423n4 opened this issue Feb 23, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

GAS :
1.
Title : Its cheaper using delete

Impact :
In the removeLiquidity function if the diff value is 0, its cheaper to use delete instead setting the pos, vAsset, vUSD, dToken to zero, this can save +- 3 gas

POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L243-L246

Mitigation :

	delete __maker.pos;
	delete __maker.vAsset;
	delete __maker.vUSD;
	delete __maker.dToken;

Title : its cheaper to save length value to a local variable

Impact : when using a loop, its cheaper to save the length value of an array to a variable, so the loop didn't have to read the storage length in each loop, but comparing with the length that was already save in the local variable. For an array that has a length 10 it can save +- 1800 gas.

POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L122
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L130
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L170
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L194

Title : its cheaper to use block.timestamp directly

Impact :
Its cheaper to use block.timestamp directly instead calling it through a _blocktimestamp() function.

POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/Oracle.sol#L65

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Feb 23, 2022
code423n4 added a commit that referenced this issue Feb 23, 2022
@atvanguard
Copy link
Collaborator

Good report.

@atvanguard atvanguard added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Feb 26, 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) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

2 participants