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

Merged
merged 41 commits into from
Mar 3, 2022
Merged

Gas optimization #240

merged 41 commits into from
Mar 3, 2022

Conversation

mrsmkl
Copy link
Contributor

@mrsmkl mrsmkl commented Feb 16, 2022

Description

What could be removed

  • some parameters from conditions can be removed, this will make creating agreements at least 50% cheaper
  • in theory creating an agreement would need only one or perhaps no on-chain variables, but fulfilling the conditions still requires gas so there's probably no point in optimizing it so much
  • access agreement when condition creation is optimized: 610k (originally 1040k)
  • creating access agreement when agreement creation is optimized: 300k (also removed condition ids from storage)
  • lock 120k + approve 40k
  • fulfill escrow 100k
  • access condition 90k
  • snark proof: 300k
  • creating condition: 110k (originally 230k)

Questions:

  • should we keep condition ids in agreements (otherwise can be checked from events)
  • do we need provenance in storage or are events enough?

Adds a DoS protection for agreements similar to DIDs.

Is this PR related with an open issue?

Related to Issue #236

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Follows the code style of this project.
  • Tests Cover Changes
  • Documentation

Funny gif

Put a link of a funny gif inside the parenthesis-->

@aaitor aaitor mentioned this pull request Feb 28, 2022
6 tasks
@aaitor aaitor linked an issue Mar 1, 2022 that may be closed by this pull request
Copy link
Member

@aaitor aaitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good. There is pending a comments clean up and removing unused stuff.
That would lead to break compatibility.
I suggest apply these changes and merge into a 2.x contracts branch. Apply also the version 2.0.0-rc0 or 1.99.0

contracts/agreements/AgreementStoreLibrary.sol Outdated Show resolved Hide resolved
contracts/agreements/AgreementStoreLibrary.sol Outdated Show resolved Hide resolved
contracts/conditions/AccessCondition.sol Outdated Show resolved Hide resolved
contracts/conditions/ConditionStoreLibrary.sol Outdated Show resolved Hide resolved
test/int/nft/NFT721_e2e.Test.js Outdated Show resolved Hide resolved
test/unit/agreements/AgreementStoreManager.Test.js Outdated Show resolved Hide resolved
test/unit/agreements/AgreementStoreManager.Test.js Outdated Show resolved Hide resolved
test/unit/agreements/AgreementStoreManager.Test.js Outdated Show resolved Hide resolved
test/unit/conditions/LockPaymentCondition.Test.js Outdated Show resolved Hide resolved
@mrsmkl mrsmkl marked this pull request as ready for review March 2, 2022 15:47
@mrsmkl mrsmkl requested review from a team as code owners March 2, 2022 15:47
@aaitor aaitor changed the base branch from master to develop March 2, 2022 16:01
Copy link
Member

@aaitor aaitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mrsmkl mrsmkl merged commit 9cf297c into develop Mar 3, 2022
@mrsmkl mrsmkl deleted the feat/gas-optimization branch March 3, 2022 12:32
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

Successfully merging this pull request may close these issues.

Analyze gas cost of typical service agreement flows
2 participants