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

Optimize merkle #90

Open
wants to merge 20 commits into
base: stylus
Choose a base branch
from
Open

Optimize merkle #90

wants to merge 20 commits into from

Conversation

tsahee
Copy link
Contributor

@tsahee tsahee commented Jul 19, 2023

split func to a mostly-empty additional-data merkle and condensed opcode merkle.
Optimize mostly-empty merkles.
Note: the last commit, caching and reusing empty hashes across merkles, doesn't seem to save time.

contract upgrade required: OffchainLabs/stylus-contracts#6

@codecov
Copy link

codecov bot commented Jul 20, 2023

Codecov Report

Merging #90 (a8ae255) into stylus (2fb726d) will increase coverage by 0.32%.
The diff coverage is 85.06%.

@@            Coverage Diff             @@
##           stylus      #90      +/-   ##
==========================================
+ Coverage   54.78%   55.11%   +0.32%     
==========================================
  Files         247      247              
  Lines       37558    37604      +46     
==========================================
+ Hits        20576    20725     +149     
+ Misses      14614    14506     -108     
- Partials     2368     2373       +5     

@tsahee tsahee marked this pull request as ready for review July 20, 2023 18:14
empty_hash: Bytes32,
min_depth: usize,
) -> Merkle {
pub fn get_empty(ty: MerkleType, layer: usize) -> Bytes32 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: moving from each markle storing it's own empty_layers vec to all sharing the same one didn't save any time on generating proofs. I still like it - but might be worth considering if added complexity is worth it.

MerkleType::Empty => panic!("attempted to fetch empty-layer value from empty merkle"),
MerkleType::Memory => Memory::MEMORY_LAYERS,
MerkleType::Opcode => 2,
MerkleType::ArgumentData => 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: not sure if it's necessary. I gave opcode and argument data min_depth 2 to avoid short functions producing a "root" that's not hashed at all.

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.

1 participant