Skip to content

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

Merged
chunter-cb merged 3 commits into
style/compiler-pins-and-dedupfrom
refactor/dedupe-create-and-lock-helpers
Jul 13, 2026
Merged

refactor: dedupe create/lock/init helpers, simplify deployment-code build#35
chunter-cb merged 3 commits into
style/compiler-pins-and-dedupfrom
refactor/dedupe-create-and-lock-helpers

Conversation

@chunter-cb

Copy link
Copy Markdown
Collaborator

Summary

Five targeted dedupe/cleanup changes to AccountConfiguration.sol. No behavior change — all 355 tests pass, including the deterministic-address and max-size-bytecode create tests.

  1. _prepare() shared by createAccount + computeAddress. createAccount previously built and hashed everything twice: computeAddress derived the address (effective salt + actors commitment + deployment-code hash), then the tail rebuilt the deployment code and salt from scratch. For a max-size account that's constructing and keccak-ing a ~24KB buffer — and recomputing the actors commitment — twice. _prepare(userSalt, bytecode, initialActors) → (account, effectiveSalt, deploymentCode) does it once for both callers.
  2. _buildDeploymentCode via abi.encodePacked. Replaces the 14 indexed byte-stores + trailing bounded copy loop with a single abi.encodePacked(bytes1(0x61), bytes2(uint16(n)), hex\"600e600039\", bytes1(0x61), bytes2(uint16(n)), hex\"6000f3\", bytecode). Same loader bytes, compiles to a calldatacopy, easier to audit against the opcode comment.
  3. isActor NatSpec fix + idiom standardization. isActor promised "live" but doesn't check expiry (intentional — _revokeActor needs to revoke expired actors); corrected the doc to "authorized (possibly expired)". Standardized getActorConfig's non-zero-authenticator test on the >= K1_AUTHENTICATOR namespace idiom already used by isActor.
  4. _checkAndClearLock in terms of _isLocked. The three-branch flag decode was duplicated across _isLocked/_checkAndClearLock. Now if (_isLocked(st)) return true; then clear iff FLAG_LOCKED is still set — making the lazy-clear rule self-evident rather than re-derived.
  5. _isInitialized() helper. The localSequence != 0 || multichainSequence != 0 check (and its restated comment) was triplicated across createAccount/importAccount; centralized into one helper.

Notes

Test plan

  • forge fmt + 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 08c9a9c into style/compiler-pins-and-dedup Jul 13, 2026
3 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