Skip to content

feat(m8): enforce session scope in TierGuardHook via AgentSessionKeyValidator#36

Open
jhfnetboy wants to merge 1 commit into
mainfrom
feat/m8-p2-session-scope-enforce
Open

feat(m8): enforce session scope in TierGuardHook via AgentSessionKeyValidator#36
jhfnetboy wants to merge 1 commit into
mainfrom
feat/m8-p2-session-scope-enforce

Conversation

@jhfnetboy
Copy link
Copy Markdown
Member

Summary

  • Part A (AAStarAirAccountV7.sol): In validateUserOp(), when routing to a module validator with ALG_SESSION_KEY (0x08), recover the session key from the 66-byte ECDSA signature and store it in transient storage via _storeSessionKey(). This bridges the validation→execution gap so TierGuardHook can access the session key during preCheck.

  • Part B (AAStarAirAccountBase.sol): Add getCurrentSessionKey() (non-consuming peek, mirrors getCurrentAlgId()). Modify _dispatchHook() to forward the full execute() calldata (msg.data) as the bytes msgData parameter, enabling the hook to parse dest and inner call selector.

  • Part C (TierGuardHook.sol): Add accountAgentValidator mapping. Extend onInstall() to accept optional 4th param (128-byte ABI-encoded format) for AgentSessionKeyValidator address (backward compatible with existing 3-param format). Add _getSessionKeyFromAccount() helper. Wire session scope enforcement in preCheck(): when agentValidator is set and algId == ALG_SESSION_KEY, call enforceSessionScope() with parsed dest and inner selector. Reverts TierGuardHookUnauthorized on forbidden call target.

This closes the TODO documented at AAStarAirAccountBase.sol:1101.

Test plan

  • forge test --match-path test/TierGuardHook.t.sol -v — all 23 tests pass (19 existing + 4 new)
    • test_PreCheck_SessionKey_enforcesCallTarget_blocks_forbidden — calling tokenB (not in allowlist) reverts
    • test_PreCheck_SessionKey_enforcesCallTarget_allows_permitted — calling tokenA (in allowlist) succeeds
    • test_PreCheck_SessionKey_noValidator_skipsEnforcement — no agentValidator → no scope check
    • test_PreCheck_SessionKey_emptyAllowlist_allowsAll — empty callTargets → any target allowed
  • forge test --match-path test/AgentSessionKeyValidator.t.sol — all 47 existing tests still pass (regression)
  • forge test — all 684 tests pass (680 existing + 4 new)

…alidator

Part A: AAStarAirAccountV7.validateUserOp — when routing to AgentSessionKeyValidator
(ALG_SESSION_KEY, 0x08), recover the session key from the 66-byte ECDSA signature and
store it in transient storage via _storeSessionKey() so TierGuardHook can access it.

Part B: AAStarAirAccountBase — add getCurrentSessionKey() (non-consuming peek) mirroring
getCurrentAlgId(), allowing hooks to read the queued session key without consuming it.
Also modify _dispatchHook() to forward the full execute() calldata (msg.data) as the
bytes msgData parameter so TierGuardHook can parse dest and inner call selector.

Part C: TierGuardHook — add accountAgentValidator mapping, extend onInstall() to accept
optional 4th param (128-byte format) for AgentSessionKeyValidator address, add
_getSessionKeyFromAccount() helper, and wire session scope enforcement in preCheck():
when agentValidator is set and algId==ALG_SESSION_KEY, call enforceSessionScope() on the
validator with the parsed dest and inner selector. Reverts TierGuardHookUnauthorized on
forbidden call target.

Tests: 4 new unit tests in TierGuardHook.t.sol covering block-forbidden, allow-permitted,
no-validator-skips, and empty-allowlist-allows-all scenarios. All 684 tests pass.

Closes TODO at AAStarAirAccountBase.sol:1101.
@jhfnetboy jhfnetboy requested a review from fanhousanbu as a code owner May 21, 2026 06:36
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