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

Open
code423n4 opened this issue Aug 5, 2022 · 0 comments
Open

Gas Optimizations #109

code423n4 opened this issue Aug 5, 2022 · 0 comments

Comments

@code423n4
Copy link
Contributor

code423n4 commented Aug 5, 2022

->X = X + Y IS CHEAPER THAN X += Y (ALSO X= X - Y IS CHEAPER THAN X -= Y)

https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=be%20re%2Dused.-,hashChangeNonce%20%2B%3D%201%3B,-emit%20HashUpdated(_hash
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=local%20task%20counter.-,_taskCount%20%2B%3D%201%3B,-//%20Check%20task%20cost
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=be%20re%2Dused.-,hashChangeNonce%20%2B%3D%201%3B,-emit%20TaskHashUpdated(_taskID
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=totalAllocated%20%2B%3D%20_newCost%20%2D%20_taskCost%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=totalAllocated%20%2D%3D%20_taskCost%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=cost%20from%20_costToAllocate-,_costToAllocate%20%2D%3D%20_taskCost%3B,//%20Mark%20the%20task%20as%20allocated,-tasks%5B_changeOrderedTask%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=_cost%20%2B%3D%20tasks%5B_taskID%5D.cost%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=totalLent%20%2D%3D%20_amount%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Community.sol#:~:text=.totalLent%20%2B%3D%20_amountToProject%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Community.sol#:~:text=.lentAmount%20%2B%3D%20_lendingAmount%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/libraries/SignatureDecoder.sol#:~:text=%3C%2027)%20%7B-,v%20%2B%3D%2027%3B,-%7D

-> ++i costs less gas compared to i++ or i += 1 (Also --i costs less gas compared to i--- or i -= 1)

https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-_replaceImplementation(_contractNames%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-_generateProxy(allContractNames%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-_generateProxy(allContractNames%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-_replaceImplementation(_contractNames%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-//%20Increment%20local%20task
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-_inviteSC(_taskList%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B)%20%7B,-tasks%5B_taskList%5Bi
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=_taskID%20%3C%3D%20_length%3B-,_taskID%2B%2B)%20%7B,-require(tasks%5B_taskID
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=_changeOrderedTask.length%3B-,i%2B%2B)%20%7B,-//%20Local%20instance%20of
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=%3D%20_changeOrderedTask%5Bi%5D%3B-,//%20Increment%20loop%20counter,_loopCount%2B%2B%3B,-%7D
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=j%20%3C%3D%20taskCount%3B-,j%2B%2B)%20%7B,-//%20Local%20instance%20of
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=_loopCount%5D%20%3D%20j%3B-,//%20Increment%20loop%20counter,_loopCount%2B%2B%3B,-%7D
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=_taskID%20%3C%3D%20_length%3B-,_taskID%2B%2B)%20%7B,-_cost%20%2B%3D%20tasks
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Community.sol#:~:text=Increment%20community%20counter-,communityCount%2B%2B%3B,-//%20Store%20community%20details
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Community.sol#:~:text=_communities%5B_communityID%5D.memberCount%3B-,i%2B%2B)%20%7B,-_members%5Bi%5D
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/libraries/Tasks.sol#:~:text=i%20%3C%20_length%3B-,i%2B%2B),-_alerts%5Bi%5D

->SPLITTING REQUIRE() STATEMENTS THAT USE && SAVES GAS

https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=uint256%20_disputeID)%20%7B-,require(,)%3B,-_%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=_actionType%20is%20invalid-,require(,)%3B,-//%20Store%20dispute%20details
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=emit%20DisputeRaised(-,disputeCount%2B%2B,-%2C%20_reason)%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Community.sol#:~:text=is%20already%20lent-,require(,)%3B,-//%20Store%20updated%20detail

-> USAGE OF UINTS/INTS SMALLER THAN 32 BYTES (256 BITS) INCURS OVERHEAD

https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/DebtToken.sol#:~:text=memory%20symbol_%2C-,uint8,-decimals_
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=upgradable%20contracts%20initials-,bytes2%5B%5D,-public%20allContractNames%3B
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=function%20upgradeMultipleImplementations(-,bytes2%5B%5D,-calldata%20_contractNames%2C
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=uint256%20_taskID%2C-,uint8%20_actionType%2C,-bytes%20memory%20_actionData
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=%26%26%20_actionType%20%3C%3D-,uint8,-(ActionType.TaskPay)%2C
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Disputes.sol#:~:text=%2C%20uint256%2C-,uint8,-%2C%20bytes%2C
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=function%20_replaceImplementation(-,bytes2,-_contractName%2C
https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=%2C%20uint256%2C-,uint8%2C,-bytes%2C%20bytes

->USING > 0 COSTS MORE GAS THAN != 0 WHEN USED ON A UINT IN A REQUIRE() STATEMENT

https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=require(_cost%20%3E%200%2C%20%22Project%3A%3A!value%3E0%22)%3B

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Aug 5, 2022
code423n4 added a commit that referenced this issue Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants