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

update stem generation implementation #64

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Jun 20, 2024

PR description

Update stem generation code in order to keep only the first 31 bytes of the generated data.

Fixed Issue(s)

Copy link

  • I thought about the changelog.

Copy link
Contributor

@thomas-quadratic thomas-quadratic left a comment

Choose a reason for hiding this comment

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

Sounds good to me.
There is just this issue with swapLastByte that seems not necessary anymore as the stem is clearly separated from the suffix in the first place.

public Bytes32 storageKey(final Bytes address, final Bytes32 storageKey) {
final Bytes stem = getStorageStem(address, storageKey);
final UInt256 suffix = getStorageKeySuffix(storageKey);
return swapLastByte(stem, suffix);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is something that I might be missing here.
It seems to me like stem is the 31-bytes prefix part of the trie-key that you get from hashing the address and storageKey.
Then, why would you need to swap the last byte ? I thought this was done on the 32nd (last) byte only.

To me, the storageKey would be just the concatenation here of stem and suffix.

return swapLastByte(base, pos.mod(VERKLE_NODE_WIDTH));
public Bytes32 codeChunkKey(final Bytes address, final UInt256 chunkId) {
final Bytes stem = getCodeChunkStem(address, chunkId);
return swapLastByte(stem, getCodeChunkKeySuffix(chunkId));
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine the same as above here applies

return swapLastByte(base, leafKey);
public Bytes32 headerKey(final Bytes address, final UInt256 leafKey) {
final Bytes stem = getHeaderStem(address);
return swapLastByte(stem, leafKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

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