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

Add compressed claim function to Quest contracts #244

Merged
merged 10 commits into from
Dec 28, 2023

Conversation

waynehoover
Copy link
Contributor

@waynehoover waynehoover commented Dec 25, 2023

This will bring our calldata down from 212 bytes to 116 (with a referrer) a saving of 45.28%.

  • Adds a highly calldata optimized claim function to the Quest and Quest1155 contracts via the abstract contract QuestClaimable.
  • Overloads the create functions to include the txHashChainId in quest creation.
  • Includes some small refactors
  • As usual, this is backwards compatible.

@waynehoover waynehoover marked this pull request as ready for review December 26, 2023 00:19
@waynehoover waynehoover requested a review from a team as a code owner December 26, 2023 00:19
@waynehoover waynehoover changed the title compressed claim function from Quest Add compressed claim function to Quest contracts Dec 26, 2023
Copy link
Member

@Quazia Quazia left a comment

Choose a reason for hiding this comment

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

LGTM - that new claim without any calldata is crazy can you comment that some more? I don't fully understand how the L1 will account for that/how the gas used will be calculated.
Small nit Depricated is spelled wrong a few places.


function getQuestId() public view virtual returns (string memory);

function claim() external payable {
Copy link
Member

Choose a reason for hiding this comment

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

How does this get handled when settled to L1 and how does the gas used work in this call?

Copy link
Contributor Author

@waynehoover waynehoover Dec 27, 2023

Choose a reason for hiding this comment

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

We can still access calldata in this function via msg.data or calldataload(offset) in assembly, both of which are done here in this function.

So as you can see in the tests we need to send a raw tx call for this to work, we can't call the function normally. We send the raw tx call prefixed with the 4 byte claim() function selector and then the rest of the bytes in the calldata can be accessed via msg.data[4:]. So from a L1 perspective it's all the same: it's a transaction with calldata.

So essentially what this does is remove the need to abi encode the calldata as a dynamic bytes array saving us two words (because encoding a bytes array adds two words when abi encoded to encode its length and data start position) ((granted they are mostly zeros but any savings is good here)).

@waynehoover waynehoover merged commit 36801ca into main Dec 28, 2023
2 checks passed
@waynehoover waynehoover deleted the better_compact_calldata branch December 28, 2023 00:02
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.

2 participants