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

Open
code423n4 opened this issue Jun 3, 2022 · 1 comment
Open

Gas Optimizations #199

code423n4 opened this issue Jun 3, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

[Gas-1] No need to set 0 on uint variables

The default value of uint varibles are 0. Therefore, there is no need to set 0 on uint variables. Not setting 0 on uint variables can reduce the deployment gas cost.

Here are some examples:

https://github.com/code-423n4/2022-05-opensea-seaport/blob/main/contracts/lib/AmountDeriver.sol#L44

uint256 extraCeiling = 0;

https://github.com/code-423n4/2022-05-opensea-seaport/blob/main/contracts/lib/CriteriaResolution.sol#L56

for (uint256 i = 0; i < totalCriteriaResolvers; ++i) {

They can be modified as follows:

uint256 extraCeiling;
for (uint256 i; i < totalCriteriaResolvers; ++i) {

[Gas-2][FulfillmentApplier.sol] unchecked can be used in _applyFulfillment function

Since it has if (considerationItem.amount > execution.item.amount) check, following parts can be wrapped by unchecked like them.

https://github.com/code-423n4/2022-05-opensea-seaport/blob/main/contracts/lib/FulfillmentApplier.sol#L97-L100

        if (considerationItem.amount > execution.item.amount) {
            ...

            unchecked {
                advancedOrders[targetComponent.orderIndex]
                    .parameters
                    .consideration[targetComponent.itemIndex]
                    .startAmount = considerationItem.amount - execution.item.amount;
            }

https://github.com/code-423n4/2022-05-opensea-seaport/blob/main/contracts/lib/FulfillmentApplier.sol#L109-L112

        } else {
            ...

            unchecked {
                advancedOrders[targetComponent.orderIndex]
                    .parameters
                    .offer[targetComponent.itemIndex]
                    .startAmount = execution.item.amount - considerationItem.amount;
            }
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 3, 2022
code423n4 added a commit that referenced this issue Jun 3, 2022
@0xleastwood 0xleastwood added the invalid This doesn't seem right label Jun 23, 2022
@HardlyDifficult HardlyDifficult removed the invalid This doesn't seem right label Jul 5, 2022
@code-423n4 code-423n4 deleted a comment from 0xleastwood Jul 5, 2022
@HardlyDifficult
Copy link
Collaborator

No need to set 0 on uint variables

I tested this and got mixed results - some functions saved a tiny amount, others got a bit worse.

The other suggestion should have small savings.

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

3 participants