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

feat(store): optimize storage location hash #1509

Merged
merged 5 commits into from
Sep 16, 2023

Conversation

Boffee
Copy link
Contributor

@Boffee Boffee commented Sep 15, 2023

The existing storage location hash encodes all parameters using abi.encode and hashes the result with keccak256. The 2 optimizations are:

  1. Move non-user dependent parameters (everything except keyTuple and tableId) outside of the hash and xor against the hash.
  2. Use abi.encodePacked because it produces a shorter encoding which reduces the gas cost for keccak256.

@Boffee Boffee requested review from alvrs and dk1a as code owners September 15, 2023 20:43
@changeset-bot
Copy link

changeset-bot bot commented Sep 15, 2023

🦋 Changeset detected

Latest commit: 22caf56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@latticexyz/store Patch
@latticexyz/world Patch
@latticexyz/cli Patch
@latticexyz/dev-tools Patch
@latticexyz/react Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

tableId are strings that the user define, not hashes. If this is used to
resolve storage location a user can access any storage location by
picking the right tableId
@Boffee Boffee force-pushed the boffee/optimize-storage-location-hash branch from 357a71f to 063e28d Compare September 15, 2023 23:39
@alvrs alvrs added this to the Contracts stable milestone Sep 16, 2023
alvrs
alvrs previously approved these changes Sep 16, 2023
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

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

🔥🔥🔥

@alvrs alvrs requested a review from holic as a code owner September 16, 2023 17:31
@alvrs alvrs merged commit be31306 into latticexyz:main Sep 16, 2023
alvrs added a commit to Boffee/mud that referenced this pull request Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants