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

Remove pieces of code which index slices by shard id #10648

Open
jancionear opened this issue Feb 22, 2024 · 0 comments
Open

Remove pieces of code which index slices by shard id #10648

jancionear opened this issue Feb 22, 2024 · 0 comments
Labels
A-stateless-validation Area: stateless validation

Comments

@jancionear
Copy link
Contributor

Many places in the code index slices by shard id, like this:

let prev_chunk_proof = prev_chunk_proofs[shard_id as usize].clone();

This is a risky thing to do, as an invalid shard id could cause a panic.
It would be safer to convert all such pieces of code so that they don't panic when they encounter an invalid shard_id:

- let prev_chunk_proof = prev_chunk_proofs[shard_id as usize].clone();
+ let prev_chunk_proof = prev_chunk_proofs
+                    .get(shard_id as usize)
+                    .ok_or(Error::InvalidShardId(shard_id))?
+                    .clone();

Stateless validation and resharding will introduce a lot of new code which will use shard ids in new ways, often dealing with untrusted data, and it's easy to accidentally use a function that doesn't handle invalid shard ids. It would be safer to just eradicate all such functions.
It would give a peace of mind that there won't be any issues like #10621

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stateless-validation Area: stateless validation
Projects
None yet
Development

No branches or pull requests

2 participants