Skip to content

refactor(forks/lstar): small Pythonic cleanups#809

Merged
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/lstar-pythonic-cleanups
Jun 1, 2026
Merged

refactor(forks/lstar): small Pythonic cleanups#809
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/lstar-pythonic-cleanups

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

Five small, no-behavior-change Pythonic cleanups in the lstar spec.

spec.py

  • Redundant ternary — the justifications dict was guarded by if state.justifications_roots else {}, but enumerating an empty root list already yields {}. Dropped the guard.
  • Manual loop → dict comprehensionroot_to_slot was built with an append loop; replaced with the equivalent one-line comprehension.
  • Explicit int()range(JUSTIFICATION_LOOKBACK_SLOTS) relied on implicit Uint64.__index__; now range(int(...)), matching the int(...) convention used elsewhere in the file.
  • Oversized process_slots comment — ~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.py

  • Throwaway round-tripValidatorIndices(data=sorted(all_indices)).to_aggregation_bits() allocated an intermediate SSZ list purely to convert a set of indices into a bitlist. Added AggregationBits.from_indices(set), routed the existing to_aggregation_bits through it (single source for the bit-building), and used it directly in the prover path. Result is byte-identical (the old sorted() was discarded inside to_aggregation_bits anyway).

Testing

  • just lint (ruff) — passed
  • just typecheck (ty) — passed
  • Impacted unit tests (test_participation, test_attestation_aggregation, test_state_process_attestations, test_state_justified_slots, test_attestation_target, test_state_aggregation) — 63 passed

🤖 Generated with Claude Code

tcoratger and others added 2 commits June 1, 2026 10:50
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>
@tcoratger tcoratger force-pushed the refactor/lstar-pythonic-cleanups branch from d776ae2 to 878df0a Compare June 1, 2026 08:51
@tcoratger tcoratger merged commit c2b7d07 into leanEthereum:main Jun 1, 2026
13 checks passed
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.

1 participant