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 optimization for contracts/TalentLayerEscrow.sol #127

Closed
Pfed-prog opened this issue Feb 17, 2023 · 6 comments
Closed

Gas optimization for contracts/TalentLayerEscrow.sol #127

Pfed-prog opened this issue Feb 17, 2023 · 6 comments

Comments

@Pfed-prog
Copy link

Pfed-prog commented Feb 17, 2023

The initial struct in contracts/TalentLayerEscrow.sol

        uint256 id;
        address sender;
        address receiver;
        address token;
        uint256 amount;
        uint256 serviceId;
        uint256 proposalId;
        uint16 protocolEscrowFeeRate;
        uint16 originServiceFeeRate;
        uint16 originValidatedProposalFeeRate;
        uint256 disputeId;
        uint256 senderFee;
        uint256 receiverFee;
        uint256 lastInteraction;
        Status status;
        Arbitrator arbitrator;
        bytes arbitratorExtraData;
        uint256 arbitrationFeeTimeout;
    }

change to

    struct Transaction {
        Arbitrator arbitrator;
        bytes arbitratorExtraData;
        uint16 protocolEscrowFeeRate;
        uint16 originServiceFeeRate;
        uint16 originValidatedProposalFeeRate;
        uint256 id;
        address sender;
        address receiver;
        address token;
        uint256 amount;
        uint256 serviceId;
        uint256 proposalId;
        uint256 disputeId;
        uint256 senderFee;
        uint256 receiverFee;
        uint256 lastInteraction;
        Status status;
        uint256 arbitrationFeeTimeout;
    }

#126

further reduced gas estimate to 5096571 from 5198083

There are definitely more gas optimizations

@Pfed-prog
Copy link
Author

Pfed-prog commented Feb 17, 2023

optimisation of

event Payment(
        uint256 _transactionId,
        PaymentType _paymentType,
        uint256 _amount,
        address _token,
        uint256 _serviceId
    );

to

    event Payment(
        PaymentType _paymentType,
        uint256 _transactionId,
        uint256 _amount,
        address _token,
        uint256 _serviceId
    );

reduces gas to 5095482

@Pfed-prog Pfed-prog changed the title Gas optimization for struct Transaction Gas optimization for contracts/TalentLayerEscrow.sol Feb 17, 2023
@Pfed-prog
Copy link
Author

reduction to 5095470

    event OriginValidatedProposalFeeRateReleased(
        address indexed _token,
        uint256 _platformId,
        uint256 _serviceId,
        uint256 _amount
    );

@Pfed-prog
Copy link
Author

to 5093526

    event TransactionCreated(
        Arbitrator _arbitrator,
        bytes _arbitratorExtraData,
        uint16 _protocolEscrowFeeRate,
        uint16 _originServiceFeeRate,
        uint16 _originValidatedProposalFeeRate,
        uint256 _transactionId,
        uint256 _senderId,
        uint256 _receiverId,
        address _token,
        uint256 _amount,
        uint256 _serviceId,
        uint256 _arbitrationFeeTimeout
    );

@Pfed-prog
Copy link
Author

Pfed-prog commented Feb 18, 2023

5092038

function submitEvidence(
        string memory _evidence,
        uint256 _profileId,
        uint256 _transactionId
    )

function claim(address _tokenAddress, uint256 _platformId)

@Pfed-prog
Copy link
Author

further areas for optimization:

  • fixed size bytes array rather than string or bytes[]
  • custom errors to save deployment and runtime costs in case of revert

@0xRomain
Copy link
Contributor

As the deployment of the contract will cost only 0,9$ on Polygon, we will ponderate any deployment optimization that impact deployment gas only and which have impacts on code readability. In most of case here, it reduce the readability here. For example, on struct Transaction it's more readable to start with id, sender, receiver, token, amount..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants