Skip to content

Restrict Asset Hub agent from executing contract calls in V2#1788

Open
yrong wants to merge 5 commits into
mainfrom
ron/restrict-agent-call-contract
Open

Restrict Asset Hub agent from executing contract calls in V2#1788
yrong wants to merge 5 commits into
mainfrom
ron/restrict-agent-call-contract

Conversation

@yrong
Copy link
Copy Markdown
Contributor

@yrong yrong commented May 12, 2026

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.79%. Comparing base (d9107c5) to head (1b33385).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1788      +/-   ##
==========================================
- Coverage   76.90%   76.79%   -0.11%     
==========================================
  Files          24       24              
  Lines         983      987       +4     
  Branches      186      187       +1     
==========================================
+ Hits          756      758       +2     
- Misses        203      205       +2     
  Partials       24       24              
Flag Coverage Δ
solidity 76.79% <100.00%> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yrong yrong marked this pull request as ready for review May 13, 2026 03:54
vm.expectEmit(true, false, false, true);
emit IGatewayV2.InboundMessageDispatched(1, topic, true, relayerRewardAddress);

address bridgeHubAgent = IGatewayV2(address(gateway)).agentOf(Constants.BRIDGE_HUB_AGENT_ID);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a weird test to allow BH agent to make arbitrary contract calls, since this is privileged as well, right? Even if the BH agent doesn't hold funds.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing BH is expected. Yes, it’s not privilege-based — it only disables the AH agent that holds the funds.

Comment thread contracts/src/Functions.sol Outdated
}

/// Looks up an agent contract address, failing if no such mapping exists or if the agent is the primary asset hub agent
function ensureNonPrivilegedAgent(bytes32 agentID) internal view returns (address agent) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function ensureNonPrivilegedAgent(bytes32 agentID) internal view returns (address agent) {
function ensureNotAssetHubAgent(bytes32 agentID) internal view returns (address agent) {

Since it only checks AH, not other privileged origins too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@claravanstaden claravanstaden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this okay in principle. AH is the only agent that contains token transfer funds, right?

@claravanstaden
Copy link
Copy Markdown
Contributor

Added some more tests here: #1793

* Add tests for ensureNotAssetHubAgent

Strengthens coverage around the AssetHub-agent callContract block
introduced in #1788:

- positive: a v2_createAgent'd user agent can still callContract
- direct: ensureNotAssetHubAgent revert reason and allow/deny paths
  pinned via an exposed wrapper on MockGateway, including a fuzz
  invariant that only ASSET_HUB_AGENT_ID returns
  UnauthorizedPrivilegedAgent
- no-state-leak: AssetHub failure path emits no SaidHello, leaves
  agent balance and registration untouched
- dual-invariant: ASSET_HUB_AGENT_ID is rejected as a callContract
  origin AND still accepted as an unlockNativeToken recipient
- multi-command: a poisoned AssetHub-origin callContract bundled
  with a legit one fails every command; same payload from a user
  agent succeeds
- skipped: testAgentCallContractFailsForBridgeHub documents the
  latent AliasOrigin(Here) -> BRIDGE_HUB_AGENT_ID bypass that the
  current single-entry deny list does not cover

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Drop BridgeHub-block skip test

BridgeHub is intentionally non-privileged in the V2 deny list; only
ASSET_HUB_AGENT_ID is reserved. Remove the speculative
testAgentCallContractFailsForBridgeHub skip and clarify the existing
testEnsureNotAssetHubAgent_AllowsBridgeHub with a comment so future
readers know the allow is by design.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Drop ticket id from section comment

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* Drop PR reference from section comment

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants