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

feat: check partial witness metadata #11441

Merged
merged 3 commits into from
Jun 3, 2024
Merged

Conversation

pugachAG
Copy link
Contributor

This PR implements check for partial state witness metadata fields (epoch_id, shard_id, height_created) after decoding complete state witness. This is needed to protect against malicious chunk producer providing incorrect metadata in the partial witness.

Large part of this PR is about moving state witness decoding (decompression + borsh-deserialization) from client to partial witness actor. This is required to implement the check, but also a nice change on its own since wintess decompression can take several dozens of milliseconds, so it is better to avoid blocking client actor.

Closes #11303.

@pugachAG pugachAG force-pushed the check-partial-witness-metadata branch from d15ca10 to 3bfbd4c Compare May 31, 2024 12:55
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 75.86207% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 71.45%. Comparing base (936d9fd) to head (052e687).

Files Patch % Lines
...idation/partial_witness/partial_witness_tracker.rs 66.66% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11441      +/-   ##
==========================================
- Coverage   71.47%   71.45%   -0.02%     
==========================================
  Files         785      785              
  Lines      158756   158757       +1     
  Branches   158756   158757       +1     
==========================================
- Hits       113466   113445      -21     
- Misses      40398    40423      +25     
+ Partials     4892     4889       -3     
Flag Coverage Δ
backward-compatibility 0.24% <0.00%> (ø)
db-migration 0.24% <0.00%> (ø)
genesis-check 1.37% <0.00%> (-0.01%) ⬇️
integration-tests 37.50% <75.86%> (-0.10%) ⬇️
linux 68.96% <0.00%> (-0.01%) ⬇️
linux-nightly 70.90% <75.86%> (-0.03%) ⬇️
macos 52.27% <0.00%> (-0.27%) ⬇️
pytests 1.59% <0.00%> (-0.01%) ⬇️
sanity-checks 1.38% <0.00%> (-0.01%) ⬇️
unittests 66.17% <55.17%> (-0.01%) ⬇️
upgradability 0.28% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pugachAG pugachAG marked this pull request as ready for review May 31, 2024 16:48
@pugachAG pugachAG requested a review from a team as a code owner May 31, 2024 16:48
@pugachAG pugachAG requested a review from jancionear May 31, 2024 16:51
Copy link
Contributor

@shreyan-gupta shreyan-gupta left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks!

@@ -753,11 +752,10 @@ impl Client {
/// you can use the `processing_done_tracker` argument (but it's optional, it's safe to pass None there).
pub fn process_chunk_state_witness(
&mut self,
encoded_witness: EncodedChunkStateWitness,
witness: ChunkStateWitness,
raw_witness_size: ChunkStateWitnessSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked the use case of raw_witness_size and it's being used in two places

  • Validation of too large witnesses in orphan witness pool here
  • Orphan witness metrics here

For the size check, we can easily just move it to the partial witness tracker module.

I'm wondering whether it makes sense to push the metrics elsewhere (example decode_state_witness fn) so that we can have a cleaner interface and skip on sending the raw sizes everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree that passing raw_witness_size around sucks as it pollutes the interface.

I think the proper solution here would be to get rid of orphan pool and merge its functionality into partial witness tracker. That is something I want to do in the long term, so I suggest keeping this size ugliness for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

For the size check, we can easily just move it to the partial witness tracker module.

The size check is meant only for orphan witnesses. It's dangerous to apply size limit to all witnesses, as we could end up in a state when the witness is too big and we can't move the chain forward.

/// Returns size in bytes of borsh-serialized state witness.
/// NOTE: this is potentially expensive operation and should only be
/// used in tests.
pub fn borsh_size(&self) -> ChunkStateWitnessSize {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we stop caring about passing raw_size to process_chunk_state_witness fn, we can get rid of this function as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

In case this is only used in tests, can we pass some dummy value instead of implementing borsh_size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dummy value would where it doesn't matter, but most test cases are actually on orphan pool where it is actually needed
decided to completely get rid of it and just inline usage for now: 535cef9

@pugachAG pugachAG force-pushed the check-partial-witness-metadata branch from b24a33e to 052e687 Compare June 3, 2024 09:28
@pugachAG pugachAG added this pull request to the merge queue Jun 3, 2024
Merged via the queue into master with commit 96af8f7 Jun 3, 2024
27 of 29 checks passed
@pugachAG pugachAG deleted the check-partial-witness-metadata branch June 3, 2024 13:51
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.

Partial witness validation: ensure partial witness metadata fields match complete witness after decoding
3 participants