Skip to content

fix: TrustGateHook — selector mismatch, caller auth, admin events#32

Open
JhiNResH wants to merge 1 commit intoerc-8183:mainfrom
JhiNResH:fix/trust-gate-hook
Open

fix: TrustGateHook — selector mismatch, caller auth, admin events#32
JhiNResH wants to merge 1 commit intoerc-8183:mainfrom
JhiNResH:fix/trust-gate-hook

Conversation

@JhiNResH
Copy link
Copy Markdown

Fixes the blocking issues raised in review of PR #9.

Changes

CRITICAL fix — FUND_SEL selector

The original hook computed keccak256("fund(uint256,bytes)") but AgenticCommerce.fund is fund(uint256,uint256,bytes). The selector never matched, so client trust was never checked at the fund stage.

Fix: Inherit BaseERC8183Hook instead of raw IACPHook. This gives correct selector constants for free (they live in BaseERC8183Hook and match AgenticCommerce). The hook now overrides _preFund/_preSubmit/_postComplete/_postReject virtual functions — no manual selector dispatch needed.

HIGH fix — caller authentication

BaseERC8183Hook provides the onlyERC8183(jobId) modifier, which validates that msg.sender is the ERC-8183 core or the job's registered hook. Inheriting it adds this guard automatically. No extra code required.

MEDIUM fixes

  • agentId == 0 collision — added mapping(address => bool) public registered to track existence separately from the agentId value. Wallets with agentId = 0 can now be registered correctly.
  • Admin eventssetAgentId, setAgentIds, setThreshold, and setOracle now emit AgentIdSet, ThresholdUpdated, and OracleUpdated respectively.
  • Oracle zero-address guardrequire(oracle_ != address(0)) in constructor and setOracle.

LOW fixes

  • README: link now points to TrustGateHook.sol (was RNWYTrustGateHook.sol).

Constructor change (breaking)

The constructor gains a new first parameter:

// Before
constructor(address oracle_, uint8 threshold_, uint256 chainId_, string memory registry_)

// After
constructor(address erc8183Contract_, address oracle_, uint8 threshold_, uint256 chainId_, string memory registry_)

erc8183Contract_ is required by BaseERC8183Hook and stored as immutable. This is the AgenticCommerce core address (or MultiHookRouter address if used behind a router).

…ents

Critical:
- Inherit BaseERC8183Hook instead of raw IACPHook — fixes FUND_SEL
  selector (was fund(uint256,bytes), must be fund(uint256,uint256,bytes))
  and adds onlyERC8183 caller authentication for free
- Override _preFund/_preSubmit/_postComplete/_postReject virtual functions
  instead of hand-rolling beforeAction/afterAction dispatch

High:
- Remove manual selector constants (now inherited from BaseERC8183Hook)
- Remove manual supportsInterface (handled by BaseERC8183Hook + ERC165)

Medium:
- Add registered mapping to track agentId existence separately from value
  (fixes agentId=0 collision with Solidity default mapping)
- Emit AgentIdSet, ThresholdUpdated, OracleUpdated on all admin mutations
- Add zero-address guard on oracle in constructor and setOracle

Low:
- Fix README: TrustGateHook.sol (was RNWYTrustGateHook.sol)
- Constructor now requires erc8183Contract_ address (BaseERC8183Hook param)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rnwy added a commit to rnwy/hook-contracts that referenced this pull request Apr 17, 2026
- Inherit BaseERC8183Hook for correct selector routing, data decoding,
  and onlyERC8183 caller authentication
- Add registered mapping so agentId = 0 is a valid registered value
- Add AgentIdSet, ThresholdUpdated, OracleUpdated admin events
- Add zero-address guards on constructor and setOracle
- Document wallet-risk vs. agent-quality trust boundary in header

Addresses review feedback from @JhiNResH in erc-8183#32 and coordination
request from @psmiratisu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant