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

Fix Merkle proof whose trie root node is inferior to 32 bytes being considered as invalid #3046

Merged
merged 6 commits into from
Nov 28, 2022

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Nov 28, 2022

Right now, we either hash each proof entry or take its inline value if it is too small.

This isn't correct, for two reasons:

  • The root node is always hashed, meaning that right now if the root node of a proof is < 32 bytes, its hash won't be found in our array.
  • Nodes that are < 32 bytes should be inlined. There's no situation where a node whose length is < 32 bytes has its own proof entry.

Consequently, we don't care about inline values and just hash the node entries.
We also check whether hashed nodes shouldn't have been inlined, although this is very secondary.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 28, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────
       +2565 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::h1cffd33ed69ebc9d
       +2506 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::h9ffc573852081119
       -2463 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::h5c31ae1fa26995f9
       -2405 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::habbc8cd40df51711
       +2251 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::he41abb3713a2be8a
       -2160 ┊ smoldot::trie::proof_decode::decode_and_verify_proof::h7e12c78f2c78eca0
        +925 ┊ hashbrown::raw::RawTable<T,A>::reserve_rehash::ha0af7cf21503f8b1
        -925 ┊ hashbrown::raw::RawTable<T,A>::reserve_rehash::hced81ff0d47e0d3b
        -359 ┊ <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold::h81672765b8599dba
        -359 ┊ <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold::hb7e1198b11f51578
        +351 ┊ <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold::h2fe9e27552cf89e9
        +351 ┊ <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold::h4812cb82e4b0423b
        +323 ┊ hashbrown::map::HashMap<K,V,S,A>::insert::h2de84c1dd47abab3
        -293 ┊ hashbrown::map::HashMap<K,V,S,A>::insert::h46aeb76ef17f9cc4
        +279 ┊ <&T as core::fmt::Display>::fmt::h6b203cc1a0222d54
        +274 ┊ <smoldot::trie::proof_decode::Error as core::fmt::Display>::fmt::h276ea898fd96ccac
        -255 ┊ <&T as core::fmt::Display>::fmt::h75b017ebb1232177
        -250 ┊ <smoldot::trie::proof_decode::Error as core::fmt::Display>::fmt::h2f3cbe64314f996c
        +229 ┊ <smoldot::trie::proof_decode::Error as core::fmt::Debug>::fmt::hb8cd282f4114f61a
        -205 ┊ <smoldot::trie::proof_decode::Error as core::fmt::Debug>::fmt::h254a73bc70e22e14
        -444 ┊ ... and 68 more.
        -814 ┊ Σ [88 Total Rows]

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Nov 28, 2022
@mergify mergify bot merged commit af7b25c into paritytech:main Nov 28, 2022
@tomaka tomaka deleted the handle-inline-properly branch November 29, 2022 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant