Skip to content

refactor: dedupe create/lock/init helpers, simplify deployment-code build#36

Merged
chunter-cb merged 3 commits into
mainfrom
refactor/dedupe-helpers-on-main
Jul 13, 2026
Merged

refactor: dedupe create/lock/init helpers, simplify deployment-code build#36
chunter-cb merged 3 commits into
mainfrom
refactor/dedupe-helpers-on-main

Conversation

@chunter-cb

@chunter-cb chunter-cb commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • _prepareDeployment() shared by createAccount + computeAddress. createAccount previously derived the address via computeAddress, then rebuilt the deployment code and effective salt from scratch — constructing and keccak-ing a ~24KB buffer (and recomputing the actors commitment) twice per creation. Now done once for both callers.
  • _buildDeploymentCode via abi.encodePacked. Replaces 14 indexed byte-stores + a trailing bounded copy loop with a single packed encode of the loader + bytecode (same loader bytes, compiles to a calldatacopy, easier to audit).
  • isActor NatSpec fix + idiom standardization. isActor reports authorization, not liveness (it does not check expiry — intentional, _revokeActor relies on it); doc corrected to "authorized (possibly expired)". getActorConfig standardized on the >= K1_AUTHENTICATOR namespace idiom.
  • _checkAndClearLock in terms of _isLocked. Removes the duplicated three-branch flag decode; the lazy-clear rule ("FLAG_LOCKED still set but no longer locked") is now self-evident.
  • _isInitialized() helper. Centralizes the triplicated localSequence || multichainSequence initialized check across createAccount/importAccount.
  • Small stuff. ERC1271_SELECTOR marked internal constant (was the only constant without explicit visibility); documented why _authorizeActor accepts a non-zero-but-codeless authenticator (counterfactual/sentinel authenticators, fails closed at auth time).

Test plan

  • forge build clean on 0.8.36
  • forge test — 355 passed, 0 failed

…uild

- Add _prepare() shared by createAccount and computeAddress so the
  effective salt, deployment code, and address are built and hashed once
  instead of twice (avoids constructing/keccak-ing the ~24KB code buffer
  and the actors commitment a second time per creation).
- Rebuild _buildDeploymentCode with a single abi.encodePacked of the
  14-byte loader + bytecode, dropping the byte-by-byte copy loop.
- Add _isInitialized() and use it in createAccount/importAccount,
  removing the triplicated localSequence/multichainSequence check and
  restated "localSequence doubles as the initialized flag" comment.
- Rewrite _checkAndClearLock in terms of _isLocked so the lazy-clear rule
  ("LOCKED still set but no longer locked") is self-evident.
- Fix isActor NatSpec: it reports authorization, not liveness (no expiry
  check); standardize getActorConfig on the >= K1_AUTHENTICATOR idiom.
…henticator

- Mark ERC1271_SELECTOR `internal constant` (was the only constant with
  no explicit visibility), matching SECP256K1_HALF_ORDER.
- Document why _authorizeActor accepts a non-zero authenticator with no
  code: authenticators may be counterfactual or intentionally codeless
  sentinels, so it fails closed at authentication time by design.
@chunter-cb chunter-cb merged commit 942bc68 into main Jul 13, 2026
5 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