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

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

Gas Optimizations #144

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

Comments

@code423n4
Copy link
Contributor

Avoid decoding unused values

Severity: Gas Optimization
Context:
Description:

In Project.raiseDispute, all values are decoded from _data, but only the first two values are used. The additional logic required to decode the last three values costs significant gas without any benefit.

Remediation:

Don't decode the final three values as they're not being used to reduce gas usage from 217449 to 216464.

Use uint256 over smaller uint types when possible

Severity: Gas Optimization
Context:
Description:

In Disputes.raiseDispute, _actionType is decoded from _data and casted to a uint8 type. This is unnecessary and inefficient as the necessary logic can be performed with a uint256, and when compiled, _actionType gets casted back to uint256 costing additional gas in the process.

Remediation:

Decode _actionType as a uint256 in Disputes.raiseDispute to reduce gas usage from 217449 to 217412.

Save storage variables locally when reused

Severity: Gas Optimization
Context:
Description:

Throughout Community.sol and Project.sol, there are storage variables which are reused within the same method. This should be generally avoided as it is much more efficient to save a variable locally and retrieve from the stack or memory instead of storage.

Remediation:
  • In Community.lendToProject, save _communities[_communityId] to a local variable to reduce gas usage from 190993 to 190425.
  • In Project.lendToProject, save builder to a local variable to reduce gas usage from 108069 to 107986
  • In Project.setComplete, save tasks[_taskId] to a local variable to reduce gas usage from 93713 to 93635
  • In Project.changeOrder, save tasks[_taskId] to a local variable to reduce gas usage from 75640 to 75459

Use optimal comparison operator

Severity: Gas Optimization
Context:
  • Throughout the contracts
Description:

Throughout the contracts, suboptimal comparison operators are used.

Remediation:

Optimal comparison operators should be used as follows:

  • When checking that uints are greater than 0, use value != 0 instead of value > 0 to save 44 gas
  • When checking that a uint is less/greater than or equal to another, use, e.g. value > otherValue - 1 instead of value >= otherValue to save 38 gas
@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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants