Skip to content

Implement encoding proof node values#2819

Merged
mergify[bot] merged 9 commits intoparitytech:mainfrom
tomaka:encode-proof-node
Oct 4, 2022
Merged

Implement encoding proof node values#2819
mergify[bot] merged 9 commits intoparitytech:mainfrom
tomaka:encode-proof-node

Conversation

@tomaka
Copy link
Copy Markdown
Contributor

@tomaka tomaka commented Oct 4, 2022

Necessary in order to finish #1166

Right now we can decode items from Merkle proofs. This PR implements encoding back these items.

While implementing encoding, I've discovered several cases where the decoding was too lenient and was accepting as valid things that shouldn't really be valid. I've fixed this as part of this PR. See the changes in src/util.rs and at the bottom of src/trie/proof_node_codec.rs.

When I say "shouldn't really be valid" I mean that there were multiple different sequences of bytes that could lead to the same decoded struct. Since we're hashing things a lot here and there, it is important that there is a bijection of decoded <-> encoded. The Substrate implementation does the same. cc paritytech/substrate#12417

Copy link
Copy Markdown
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
Copy Markdown
Contributor

github-actions Bot commented Oct 4, 2022

twiggy diff report

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


 Delta Bytes │ Item
─────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       +1453 ┊ smoldot::trie::proof_node_codec::decode::h8c2a3387e8fd00db
       -1398 ┊ smoldot::trie::proof_node_decode::decode::h3c802fc74e097b79
        +309 ┊ <&T as core::fmt::Display>::fmt::hc61d54e835a5e55a
        +306 ┊ <smoldot::trie::proof_node_codec::Error as core::fmt::Debug>::fmt::h771dc1f7d38ceb18
        -267 ┊ <&T as core::fmt::Display>::fmt::hede33647e967f354
        -264 ┊ <smoldot::trie::proof_node_decode::Error as core::fmt::Debug>::fmt::h52238c6df391e999
        +257 ┊ <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h24d08d1fb54a1500
        -257 ┊ <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter::h505ccd594b2d1511
        -176 ┊ alloc::vec::Vec<T,A>::extend_desugared::h2508a4c0bc10f95c
        +176 ┊ alloc::vec::Vec<T,A>::extend_desugared::hdafe000385f163e9
        -119 ┊ <smoldot::trie::nibble::nibbles_to_bytes_extend::Iter<I> as core::iter::traits::iterator::Iterator>::next::hcceeebdd458373a3
        +119 ┊ <smoldot::trie::nibble::nibbles_to_bytes_suffix_extend::Iter<I> as core::iter::traits::iterator::Iterator>::next::hfb9289ced9322d6a
        +111 ┊ <smoldot::trie::proof_node_codec::PartialKey as core::iter::traits::iterator::Iterator>::next::hf090f35ddcd91518
        -111 ┊ <smoldot::trie::proof_node_decode::PartialKey as core::iter::traits::iterator::Iterator>::next::h7efb59290db7c70f
        +107 ┊ smoldot::trie::proof_node_codec::Decoded::children_bitmap::h47da02d2a0a90f55
        -107 ┊ smoldot::trie::proof_node_decode::Decoded::children_bitmap::hebf4eaa59ed5d772
         +98 ┊ smoldot::util::nom_scale_compact_usize::h78e936afad2da3eb
         +98 ┊ smoldot::util::nom_scale_compact_usize::hf6e357ea1a4d52cf
         +83 ┊ <smoldot::trie::proof_node_codec::PartialKey as core::clone::Clone>::clone::he6bae938fa7cc5af
         -83 ┊ <smoldot::trie::proof_node_decode::PartialKey as core::clone::Clone>::clone::h2e2a851a709e4791
         +97 ┊ ... and 14 more.
        +453 ┊ Σ [34 Total Rows]

Copy link
Copy Markdown
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Oct 4, 2022
@mergify mergify Bot merged commit 1777378 into paritytech:main Oct 4, 2022
@tomaka tomaka deleted the encode-proof-node branch October 4, 2022 15:20
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.

2 participants