Skip to content

Commit b17c82d

Browse files
tcoratgerclaude
andauthored
refactor(testing): drop dead scheme_name params on key manager (leanEthereum#903)
The key manager only ever operates on the single active scheme from LEAN_ENV. Two scheme_name parameters were dead weight: - The constructor default "test" was never relied on — the sole caller, the shared cache builder, always passed LEAN_ENV. The default could silently diverge from the active scheme. - The signing-state reset parameter was never supplied; all callers invoke it with no argument. Both now derive the scheme from LEAN_ENV directly. The instance scheme_name attribute stays, since the on-disk-keys error messages still reference it (audit finding CORE-02). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ed10c59 commit b17c82d

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

  • packages/testing/src/consensus_testing

packages/testing/src/consensus_testing/keys.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ def shared(cls, max_slot: Slot = DEFAULT_MAX_SLOT) -> XmssKeyManager:
201201
return cached
202202

203203
# No suitable cached manager exists. Build a new one and cache it.
204-
manager = cls(max_slot=max_slot, scheme_name=LEAN_ENV)
204+
manager = cls(max_slot=max_slot)
205205
cls._cache[LEAN_ENV] = manager
206206
return manager
207207

208208
@classmethod
209-
def reset_signing_state(cls, scheme_name: str | None = None) -> None:
209+
def reset_signing_state(cls) -> None:
210210
"""
211211
Clear advanced secret-key state from the cached manager.
212212
@@ -216,26 +216,19 @@ def reset_signing_state(cls, scheme_name: str | None = None) -> None:
216216
217217
Only the mutable signing state is cleared. The JSON and public-key
218218
caches are immutable and preserved to avoid expensive re-loading.
219-
220-
Args:
221-
scheme_name: Scheme entry to reset. Defaults to the current LEAN_ENV.
222219
"""
223-
cached = cls._cache.get(LEAN_ENV if scheme_name is None else scheme_name)
220+
cached = cls._cache.get(LEAN_ENV)
224221
if cached is not None:
225222
cached._secret_state.clear()
226223

227-
def __init__(
228-
self,
229-
max_slot: Slot = DEFAULT_MAX_SLOT,
230-
scheme_name: str = "test",
231-
) -> None:
232-
"""Initialize with a scheme name and maximum slot for key validity."""
233-
if scheme_name not in LEAN_ENV_TO_SCHEMES:
234-
raise ValueError(f"Unknown scheme: {scheme_name!r}")
224+
def __init__(self, max_slot: Slot = DEFAULT_MAX_SLOT) -> None:
225+
"""Initialize with the active scheme and a maximum slot for key validity."""
226+
if LEAN_ENV not in LEAN_ENV_TO_SCHEMES:
227+
raise ValueError(f"Unknown scheme: {LEAN_ENV!r}")
235228
self.max_slot = max_slot
236-
self.scheme_name = scheme_name
237-
self.scheme = LEAN_ENV_TO_SCHEMES[scheme_name]
238-
self._keys_directory = get_keys_directory(scheme_name)
229+
self.scheme_name = LEAN_ENV
230+
self.scheme = LEAN_ENV_TO_SCHEMES[LEAN_ENV]
231+
self._keys_directory = get_keys_directory(LEAN_ENV)
239232

240233
# Raw JSON cache: nested dict of hex-encoded SSZ strings, very lightweight.
241234
self._json_cache: dict[ValidatorIndex, dict[str, dict[str, str]]] = {}

0 commit comments

Comments
 (0)