refactor(forks/lstar): small Pythonic cleanups#809
Merged
tcoratger merged 2 commits intoJun 1, 2026
Conversation
Five no-behavior-change simplifications in the lstar spec: - Drop a redundant ternary guarding the justifications dict comprehension; enumerating an empty root list already yields an empty dict. - Replace a manual root-to-slot loop with the equivalent dict comprehension. - Convert the lookback count to int before range() instead of relying on the implicit integer coercion, matching the int() usage elsewhere. - Add a constructor that builds aggregation bits straight from a set of validator indices, route the existing index-list conversion through it, and use it in the prover path to avoid building a throwaway index list. - Trim the per-slot housekeeping comment to its load-bearing invariant: the state root is cached at most once per block, on the first empty slot. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
With the index-set logic now living in the aggregation-bits constructor, the conversion method on the index list was a pure delegating wrapper. Most of its call sites also built a throwaway index list purely to call it. Remove the wrapper, widen the constructor to accept any iterable of indices, and call it directly everywhere, dropping the intermediate index lists. The conversion test suite now exercises the constructor directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d776ae2 to
878df0a
Compare
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.
Summary
Five small, no-behavior-change Pythonic cleanups in the lstar spec.
spec.pyjustificationsdict was guarded byif state.justifications_roots else {}, but enumerating an empty root list already yields{}. Dropped the guard.root_to_slotwas built with an append loop; replaced with the equivalent one-line comprehension.int()—range(JUSTIFICATION_LOOKBACK_SLOTS)relied on implicitUint64.__index__; nowrange(int(...)), matching theint(...)convention used elsewhere in the file.process_slotscomment — ~20 lines of step narration trimmed to the one load-bearing invariant: the header's state root is empty only for the first empty slot after a block, so caching happens at most once per block.containers.pyValidatorIndices(data=sorted(all_indices)).to_aggregation_bits()allocated an intermediate SSZ list purely to convert a set of indices into a bitlist. AddedAggregationBits.from_indices(set), routed the existingto_aggregation_bitsthrough it (single source for the bit-building), and used it directly in the prover path. Result is byte-identical (the oldsorted()was discarded insideto_aggregation_bitsanyway).Testing
just lint(ruff) — passedjust typecheck(ty) — passedtest_participation,test_attestation_aggregation,test_state_process_attestations,test_state_justified_slots,test_attestation_target,test_state_aggregation) — 63 passed🤖 Generated with Claude Code