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

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

Gas Optimizations #204

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

Comments

@code423n4
Copy link
Contributor

Gas Report for OpenSea by Perito Flores

[G-00] Unnecessary initialization of integers to zero

In for loops

conduit\Conduit.sol:        for (uint256 i = 0; i < totalStandardTransfers; ) {
conduit\Conduit.sol:        for (uint256 i = 0; i < totalStandardTransfers; ) {
lib\BasicOrderFulfiller.sol:        for (uint256 i = 0; i < totalAdditionalRecipients; ) {
lib\BasicOrderFulfiller.sol:        for (uint256 i = 0; i < totalAdditionalRecipients; ) {
lib\CriteriaResolution.sol:            for (uint256 i = 0; i < totalCriteriaResolvers; ++i) {
lib\CriteriaResolution.sol:            for (uint256 i = 0; i < totalAdvancedOrders; ++i) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalOrders; ++i) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalOrders; ++i) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalOfferFulfillments; ++i) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalConsiderationFulfillments; ++i) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalOrders; ++i) {
lib\OrderCombiner.sol:        for (uint256 i = 0; i < executions.length; ) {
lib\OrderCombiner.sol:            for (uint256 i = 0; i < totalFulfillments; ++i) {
lib\OrderFulfiller.sol:            for (uint256 i = 0; i < orderParameters.offer.length; ) {
lib\OrderFulfiller.sol:            for (uint256 i = 0; i < orderParameters.consideration.length; ) {
lib\OrderFulfiller.sol:            for (uint256 i = 0; i < totalOrders; ++i) {
lib\OrderValidator.sol:            for (uint256 i = 0; i < totalOrders; ) {
lib\OrderValidator.sol:            for (uint256 i = 0; i < totalOrders; ) {



lib\CriteriaResolution.sol:                for (uint256 j = 0; j < totalItems; ++j) {
lib\CriteriaResolution.sol:                for (uint256 j = 0; j < totalItems; ++j) {
lib\OrderCombiner.sol:                for (uint256 j = 0; j < offer.length; ++j) {
lib\OrderCombiner.sol:                for (uint256 j = 0; j < consideration.length; ++j) {
lib\OrderCombiner.sol:                for (uint256 j = 0; j < consideration.length; ++j) {

Variable extraCeling

lib\AmountDeriver.sol:            uint256 extraCeiling = 0;

[G-01] ++i and (++j) costs less gas compared to i++ (j++)

At many parts of your code (especially for loops) you are using i++. I suggest change all for ++i.

@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
@HardlyDifficult
Copy link
Collaborator

HardlyDifficult commented Jun 23, 2022

Unnecessary initialization of integers to zero

This should be optimized by the compiler automatically. I tested this and confirmed it's not beneficial - some functions save a tiny amount, others got a bit worse.

++i and (++j) costs less gas compared to i++ (j++)

True, small savings here.

@HardlyDifficult HardlyDifficult added the invalid This doesn't seem right label Jun 23, 2022
@HardlyDifficult HardlyDifficult removed the invalid This doesn't seem right label Jul 4, 2022
@JeeberC4 JeeberC4 reopened this Jul 14, 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

3 participants