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

Tree is fixed depth 8 #32

Open
slvrfn opened this issue Nov 14, 2022 · 8 comments
Open

Tree is fixed depth 8 #32

slvrfn opened this issue Nov 14, 2022 · 8 comments

Comments

@slvrfn
Copy link

slvrfn commented Nov 14, 2022

It appears the tree is of a fixed length of 8. This code appears to be easily modified to produce a tree of variable depth

@TimDaub
Copy link
Member

TimDaub commented Nov 14, 2022

yeah I can't remember anymore what were all steps to increase the size, but it may be as easy as forking and changing the constants on top of the file

@slvrfn
Copy link
Author

slvrfn commented Nov 14, 2022

Excellent thats what i was thinking!

Also, wouldn't this also require updating the bitmap function? I was thinking it would be something like the following for a DEPTH=14:


uint256 constant BUFFER_LENGTH = 1;
uint256 constant DEPTH = 14;
uint256 constant SIZE = (2**DEPTH)-1;

function bitmap(uint256 index) internal pure returns (uint256) {
    uint256 bytePos = (BUFFER_LENGTH - 1) - (index / DEPTH);
    return bytePos + 1 << (index % DEPTH);
}

@slvrfn
Copy link
Author

slvrfn commented Nov 14, 2022

could you also give some insight into what the purpose of BUFFER_LENGTH is?

@TimDaub
Copy link
Member

TimDaub commented Nov 14, 2022

The magic constant "8" in the bitmap, I think, refers to the number of bits present in a byte.

@slvrfn
Copy link
Author

slvrfn commented Nov 14, 2022

if the uint8 is maintained, wouldnt the _bits inside compute get set to all 0's if a DEPTH > 8 is used?

_bits = _bits >> 1;

@TimDaub
Copy link
Member

TimDaub commented Nov 14, 2022

if the uint8 is maintained, wouldnt the _bits inside compute get set to all 0's if a DEPTH > 8 is used?

yes I think so.

I'm currently trying to remember where I got the idea of this code from. How embarrassing! Anyways, I remember parsing the compression and decompression code of Vitalik here and then breaking it down for uint8 values: https://ethresear.ch/t/optimizing-sparse-merkle-trees/3751

Here is code you might find helpful:

@TimDaub
Copy link
Member

TimDaub commented Nov 14, 2022

could you also give some insight into what the purpose of BUFFER_LENGTH is?

no idea anymore. I think it is not significant and potentially badly named so that it's misleading the reader of the code...

@TimDaub
Copy link
Member

TimDaub commented Jan 15, 2023

@slvrfn has your problem been solved?

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