8000 feat(optimistic_block): shuffle incoming receipts based on prev hash by Longarithm · Pull Request #12777 · near/nearcore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(optimistic_block): shuffle incoming receipts based on prev hash #12777

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

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

Longarithm
Copy link
Member
@Longarithm Longarithm commented Jan 23, 2025

#10584

There is another unexpected dependency on block hash during chunk application - it is used in shuffle_receipt_proofs to shuffle new receipts targeting our shard. As block hash is unknown in optimistic block, I replace it with prev block hash with a protocol upgrade.

Additionally, use Chunks instead of Block in collect_incoming_receipts_from_chunks - it will be useful for optimistic block execution flow later.

Security

Some block producer can brute force hashes to get salt which gives more desirable order. But block hash is prone to that as well, prev hash has equivalent safety.

Upgrade

I use BlockHeightForReceiptId feature because it has similar goal and it is going to be released soon. Adding separate feature makes code harder to read I think.

Testing

IMO it makes sense only to check consistency of the shuffling, I don't see much value in checking that specific salt is used. So I claim that running existing tests is enough to test that change.

< 8000 svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-repo-push">
Copy link
Contributor
@VanBarbascu VanBarbascu left a comment

Choose a reason for hiding this comment

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

Given that the prev block hash is known at the chunk creation time, even the chunk producers can now estimate/influence the order of the receipts that they produce.

@Longarithm
Copy link
Member Author
Longarithm commented Jan 23, 2025

Given that the prev block hash is known at the chunk creation time, even the chunk producers can now estimate/influence the order of the receipts that they produce.

Could you elaborate?
For transactions, chunk producer always has the freedom to include them in arbitrary order.
But receipts execution order is fixed by the protocol.
Only the block producer can influence the order of receipts by bruteforcing a hash.

In fact, this shuffling is only about order of source shards from which receipts are taken, receipts within a shard don't change their order. Yeah CPs will know order of source shards when they produce chunk, but I don't see how this can be used maliciously.

Copy link
Contributor
@VanBarbascu VanBarbascu left a comment

Choose a reason for hiding this comment

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

I took a better look at this, and it seems that the receipts that we are working with here are generated in the previous block (or older), and we are using the prev block hash.
This prev block hash is unknown to the chunk producers for those heights.
Given this, it looks safe.

@Longarithm
Copy link
Member Author

receipts that we are working with here are generated in the previous block

Yeah that's also true :)

@Longarithm Longarithm enabled auto-merge January 23, 2025 16:17
@Longarithm Longarithm added this pull request to the merge queue Jan 23, 2025
Copy link
codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 79.48718% with 8 lines in your changes missing coverage. Please review.

Project coverage is 70.51%. Comparing base (59627f6) to head (86c2635).
Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
chain/chain/src/chain.rs 79.16% 0 Missing and 5 partials ⚠️
tools/replay-archive/src/cli.rs 0.00% 2 Missing ⚠️
chain/chain/src/sharding.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12777      +/-   ##
==========================================
- Coverage   70.51%   70.51%   -0.01%     
==========================================
  Files         846      846              
  Lines      174633   174649      +16     
  Branches   174633   174649      +16     
==========================================
+ Hits       123149   123157       +8     
- Misses      46254    46259       +5     
- Partials     5230     5233       +3     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.35% <0.00%> (-0.01%) ⬇️
linux 68.91% <76.92%> (+<0.01%) ⬆️
linux-nightly 70.12% <79.48%> (+0.01%) ⬆️
pytests 1.65% <0.00%> (-0.01%) ⬇️
sanity-checks 1.46% <0.00%> (-0.01%) ⬇️
unittests 70.35% <79.48%> (-0.01%) ⬇️
upgradability 0.20% <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.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2025
@Longarithm Longarithm added this pull request to the merge queue Jan 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 24, 2025
@Longarithm Longarithm added this pull request to the merge queue Jan 24, 2025
Merged via the queue into near:master with commit 532d157 Jan 24, 2025
28 checks passed
@Longarithm Longarithm deleted the receipts-prev branch January 24, 2025 04:13
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.

4 participants
0