Ensure cell indices are sorted in recover_cells_and_kzg_proofs#594
Merged
asn-d6 merged 6 commits intoethereum:mainfrom Sep 3, 2025
Merged
Ensure cell indices are sorted in recover_cells_and_kzg_proofs#594asn-d6 merged 6 commits intoethereum:mainfrom
recover_cells_and_kzg_proofs#594asn-d6 merged 6 commits intoethereum:mainfrom
Conversation
This would work with partial inputs but not when all cells were provided.
recover_cells_and_kzg_proofs to support shuffled indicesrecover_cells_and_kzg_proofs
asn-d6
reviewed
Aug 27, 2025
asn-d6
reviewed
Aug 27, 2025
src/eip7594/eip7594.c
Outdated
Comment on lines
228
to
230
| for (size_t i = 0; i < CELLS_PER_EXT_BLOB; i++) { | ||
| uint64_t index = cell_indices[i]; | ||
| recovered_cells[index] = cells[i]; |
Contributor
There was a problem hiding this comment.
I see why this is a bit nicer than the blind memcpy, but IMO it's also a bit confusing.
It's confusing because at this point we are past all the initial checks and we also have num_cells == CELLS_PER_EXT_BLOB, and hence we MUST be certain that cell_indices = [0, 1, ..., CELLS_PER_EXT_BLOB-1].
The problem is that this new code introduces index and sorta implies it's a free ranging index, whereas in reality it should be very very constrainted.
For me, the following would be more descriptive:
Suggested change
| for (size_t i = 0; i < CELLS_PER_EXT_BLOB; i++) { | |
| uint64_t index = cell_indices[i]; | |
| recovered_cells[index] = cells[i]; | |
| for (size_t i = 0; i < CELLS_PER_EXT_BLOB; i++) { | |
| /* At this point we know that all cells are in the right order */ | |
| assert(cell_indices[i] == i); | |
| recovered_cells[i] = cells[i]; |
Contributor
There was a problem hiding this comment.
Tried this after our discussion. It does not use an assert but it also does not introduce a new index: 65ebfdd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will reject inputs to the recovery function if the cell indices are not in ascending order. With this check, we remove the
fr_is_nullduplicate checks below. I've kept thememcpychange because I prefer how the new version reads.See also the specifications update related to this:
recover_cells_and_kzg_proofsconsensus-specs#4519Thanks to @asanso for pointing this out.