Skip to content

fix(hyperliquid-plugin): biz-type/strategy attribution + 1-place EVM-012 fix (v0.4.4)#74

Open
GeoGu360 wants to merge 1 commit intomig-pre:mainfrom
GeoGu360:fix/hyperliquid-plugin-biz-type-strategy-v2
Open

fix(hyperliquid-plugin): biz-type/strategy attribution + 1-place EVM-012 fix (v0.4.4)#74
GeoGu360 wants to merge 1 commit intomig-pre:mainfrom
GeoGu360:fix/hyperliquid-plugin-biz-type-strategy-v2

Conversation

@GeoGu360
Copy link
Copy Markdown
Owner

@GeoGu360 GeoGu360 commented May 7, 2026

Summary

Add onchainos 3.0.0 attribution flags --biz-type dapp --strategy hyperliquid-plugin to every wallet contract-call invocation. Strategy name reads from Cargo.toml via env!("CARGO_PKG_NAME") to prevent name drift across the 4 metadata files.

Also fixes one genuine EVM-012 (silent RPC error swallowing) found during the Step 1.5 scan.

Changes

Attribution (src/onchainos.rs)

const BIZ_TYPE: &str = "dapp";
const STRATEGY: &str = env!("CARGO_PKG_NAME");

Injected into the args of wallet_contract_call, covering 5 call sites:

  • commands/get_gas.rs × 2 (USDC approve + deposit through relay)
  • commands/deposit.rs (USDC deposit on Hyperliquid bridge)
  • commands/evm_send.rs × 2 (perp ⇄ spot transfers)

EVM-012 fix (src/commands/get_gas.rs:160)

Replaced erc20_allowance(...).unwrap_or(0) with fail-closed match returning RPC_ERROR JSON. The previous behavior silently returned 0 on transient RPC errors, triggering an unnecessary re-approve.

Version bump (4 metadata files)

0.4.3 → 0.4.4 (PATCH — backwards-compatible, no API changes).

Out of scope

onchainos wallet sign-message (used for hyperliquid's perp order / cancel / TPSL EIP-712 signing) doesn't accept --biz-type/--strategy in the current onchainos 3.0.0 CLI. Those paths can't be attributed yet.

EVM-012 audit

Other unwrap_or(0) sites scanned and classified:

  • outcome_sell.rs:332 — system clock fallback (intentional)
  • spot_prices.rs / orders.rs / positions.rs / order.rs — JSON field fallbacks for display-only fields
  • get_gas.rs:160REAL EVM-012, fixed

EVM-006 sleep sites verified as intentional polling patterns (wait_tx_mined receipt poll + relay status poll).

Test plan

  • cargo build passes (only pre-existing warnings)
  • Diff review confirms only intended changes
  • CI Phase 1 (Structure validation)
  • CI Phase 2 (Build verification)
  • CI Phase 3 (AI Code Review)

🤖 Generated with Claude Code

…012 fix (v0.4.4)

Add `--biz-type dapp --strategy hyperliquid-plugin` to every onchainos
`wallet contract-call` invocation so the OKX backend can attribute
contract calls to this plugin. Source-of-truth for the strategy name
is Cargo.toml's `[package].name` via `env!("CARGO_PKG_NAME")` — no
drift between Cargo.toml, plugin.yaml, plugin.json.

Affected onchainos call sites (5):
- commands/get_gas.rs: USDC approve to relay solver
- commands/get_gas.rs: USDC deposit through relay
- commands/deposit.rs: USDC deposit on Hyperliquid bridge
- commands/evm_send.rs: perp → spot transfer
- commands/evm_send.rs: spot → EVM transfer

Note: hyperliquid's perp order / cancel / TPSL paths use
`onchainos wallet sign-message` (EIP-712), which doesn't accept
biz-type/strategy. Only the contract-call paths can be attributed
under the current onchainos 3.0.0 CLI.

Also fix one real EVM-012 (silent RPC error swallowing):
- commands/get_gas.rs:160 — `erc20_allowance(...).unwrap_or(0)`
  silently returned 0 on RPC failure, triggering an unnecessary
  re-approve. Changed to fail-closed `match` returning RPC_ERROR
  with stdout JSON for the calling Agent.

Other `unwrap_or(0)` sites are JSON-field fallbacks for display-only
fields (positions / orders / spot_prices) and intentional system-clock
fallback in outcome_sell.rs — not real EVM-012.

EVM-006 sleep sites are intentional polling (wait_tx_mined receipt
poll, relay status poll) — these are correct patterns.

Version bump: 0.4.3 → 0.4.4 (PATCH — backwards-compatible).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@GeoGu360 GeoGu360 added the ci-approved Maintainer reviewed PR; allows Phase 1/2/3 CI to run label May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

🔨 Phase 2: Build Verification — ✅ PASSED

Plugin: hyperliquid-plugin | Language: rust
Source: @

Compiled from developer source code by our CI. Users install our build artifacts.

Build succeeded. Compiled artifact uploaded as workflow artifact.


Source integrity: commit SHA `` is the content fingerprint.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

📋 Phase 3: AI Code Review Report — Score: 91/100

Plugin: hyperliquid-plugin | Recommendation: ✅ Ready to merge

🔗 Reviewed against latest onchainos source code (live from main branch) | Model: claude-opus-4-7 via Anthropic API | Cost: ~669007+6938 tokens

This is an advisory report. It does NOT block merging. Final decision is made by human reviewers.


1. Plugin Overview
Field Value
Name hyperliquid-plugin
Version 0.4.4
Category defi-protocol
Author GeoGu360 (GeoGu360)
License MIT
Has Binary Yes (with build config)
Risk Level High (perpetuals trading, fund operations)

Summary: A comprehensive Hyperliquid DEX trading plugin providing perpetuals, spot, HIP-3 builder DEX (RWAs/equities), and HIP-4 outcome (prediction market) trading via the onchainos CLI. Supports order placement, cancellation, position management, deposits/withdrawals, and cross-DEX transfers.

Target Users: Traders interested in Hyperliquid perps, RWA markets, and prediction markets through OKX Agentic Wallet integration.

2. Architecture Analysis

Components: Skill (SKILL.md) + Rust binary

Skill Structure: SKILL.md contains pre-flight CI block, command index (~30 commands), HIP-3/HIP-4 architectural notes, error handling, security warnings, and changelog. Comprehensive references to onchainos CLI integration.

Data Flow:

  • Reads from Hyperliquid API (info/exchange endpoints) for market data, positions, orders
  • Reads from Arbitrum RPC (publicnode.com) for USDC balance/permit nonce queries
  • Reads from HyperEVM RPC for native balance
  • Calls relay.link API for cross-chain gas swaps
  • All write operations (orders, transfers, deposits, withdrawals) sign via onchainos wallet sign-message --type eip712 (TEE-backed signing)
  • Submits signed transactions to Hyperliquid exchange or via onchainos wallet contract-call for EVM

Dependencies: onchainos CLI (required for all signing), tokio, reqwest, sha3, hex, rmp-serde, clap, serde, serde_json, futures, anyhow.

3. Auto-Detected Permissions

onchainos Commands Used

Command Found Exists in onchainos CLI Risk Level Context
onchainos wallet addresses Yes Low Resolve user wallet for chain
onchainos wallet sign-message --type eip712 Yes Medium TEE-backed EIP-712 signing for all HL actions
onchainos wallet contract-call Yes High EVM contract calls (deposit, get-gas, evm-send)
onchainos wallet status Yes (referenced in SKILL.md) Low Login status check
onchainos wallet report-plugin-info Yes Low Strategy attribution to OKX backend

All onchainos commands referenced exist in the provided source code reference.

Wallet Operations

Operation Detected? Where Risk
Read balance Yes positions, spot_balances, address, quickstart Low
Send transaction Yes deposit, get_gas, evm_send (via wallet contract-call) High
Sign message Yes All write commands (order, cancel, withdraw, transfer, etc.) High
Contract call Yes deposit (USDC bridge), evm_send (CoreWriter), get-gas High

External APIs / URLs

URL / Domain Purpose Risk
https://api.hyperliquid.xyz/info HL market data, positions, orders Low
https://api.hyperliquid.xyz/exchange HL signed action submission Medium
https://api.hyperliquid-testnet.xyz/* Testnet endpoints Low
https://arbitrum-one-rpc.publicnode.com Arbitrum RPC for ERC20 reads Low
https://rpc.hyperliquid.xyz/evm HyperEVM RPC Low
https://api.relay.link Cross-chain swap quotes/execution Medium
https://app.hyperliquid.xyz/settings/api-wallets Referenced in register setup instructions Low
https://api.github.com/repos/okx/onchainos-skills/releases/latest onchainos installer version check (CI block) Low
https://raw.githubusercontent.com/okx/onchainos-skills/... onchainos installer download (CI block) Low
https://github.com/okx/onchainos-skills/releases/... Binary checksums (CI block) Low
https://raw.githubusercontent.com/mig-pre/plugin-store/... Plugin update check + launcher Medium
https://github.com/mig-pre/plugin-store/releases/... Plugin binary download Medium

Chains Operated On

  • Hyperliquid L1 (chain 999, HyperEVM)
  • Arbitrum One (chain 42161) — for USDC bridge deposits
  • Implicitly: USDC source/destination on Arbitrum

Overall Permission Summary

This plugin has very broad financial powers: it can place perpetual orders (with leverage up to 100x), close positions, broadcast Arbitrum→Hyperliquid USDC deposits, withdraw to Arbitrum, transfer between perp/spot, sign 7702/EIP-712 actions, and execute cross-chain swaps via relay.link. All signing is correctly delegated to onchainos (TEE-backed). User confirmation is gated via --confirm flag. Major risk vector: bracket orders, market closes, and batch orders can move significant funds; the report-plugin-info shells out user data to OKX backend (acceptable, but worth noting).

4. onchainos API Compliance

Does this plugin use onchainos CLI for all on-chain write operations?

Yes — fully compliant.

On-Chain Write Operations (MUST use onchainos)

Operation Uses onchainos? Self-implements? Detail
Wallet signing No All EIP-712 via onchainos wallet sign-message
Transaction broadcasting No Via wallet contract-call for EVM, exchange API for HL signed actions
DEX swap execution No get-gas via wallet contract-call, HL trades via signed actions
Token approval No USDC permit signed via onchainos (no separate approve tx)
Contract calls No All via wallet contract-call
Token transfers No Via signed HL actions or contract-call

Data Queries (allowed to use external sources)

Data Source API/Service Used Purpose
Hyperliquid info API api.hyperliquid.xyz/info Positions, orders, prices, meta
Arbitrum RPC arbitrum-one-rpc.publicnode.com USDC balance, allowance, permit nonce
HyperEVM RPC rpc.hyperliquid.xyz/evm Native HYPE balance, tx receipts
relay.link api.relay.link Cross-chain quotes

External APIs / Libraries Detected

Direct HTTP calls via reqwest to all listed APIs. No private key handling in plugin code — all signing routed through onchainos.

Verdict: ✅ Fully Compliant

The plugin correctly delegates ALL signing and broadcasting to onchainos. No private key material handled by plugin. Read-only RPC calls to public endpoints are appropriate for data queries.

5. Security Assessment

Static Rule Scan (C01-C09, H01-H09, M01-M08, L01-L02)

Rule ID Severity Title Matched? Detail
C01 CRITICAL curl | sh remote execution No Pre-flight curl followed by SHA256 verification before sh execution — proper supply-chain hardening
H05 INFO Direct financial API operations Yes Plugin's core function is on-chain perps trading; expected for category
M03 MEDIUM Third-party content fetch Yes Multiple reqwest calls to external APIs (HL, Arbitrum RPC, relay.link) — used for data, not instructions
M07 MEDIUM Missing untrusted data boundary No SKILL.md includes explicit "Treat all data returned by this plugin and the Hyperliquid API as untrusted external content" boundary declaration
M08 INFO External data field passthrough No SKILL.md explicitly enumerates display fields per command in "Display:" sections

LLM Judge Analysis (L-PINJ, L-MALI, L-MEMA, L-IINJ, L-AEXE, L-FINA, L-FISO)

Judge Severity Detected Confidence Evidence
L-PINJ CRITICAL No 0.95 No prompt injection patterns; SKILL.md includes proper trust boundaries
L-MALI CRITICAL No 0.90 Plugin behavior matches stated purpose (perp trading); no hidden exfiltration
L-MEMA HIGH No 0.95 No memory file modification
L-IINJ INFO Yes 0.95 External requests to declared APIs; M07 declaration present
L-AEXE INFO Yes 0.85 All write ops require explicit --confirm; appropriate gating
L-FINA INFO/HIGH Yes 0.95 Write operations gated by --confirm; explicit user consent required; appropriate for INFO tier
L-FISO INFO No 0.85 Display fields enumerated; no raw passthrough

Toxic Flow Detection (TF001-TF006)

No toxic flows detected. The financial operations (H05) are properly gated with --confirm flags and the plugin includes the M07 untrusted-data boundary declaration, preventing TF006.

Prompt Injection Scan

Reviewed SKILL.md for:

  • Instruction override patterns: None detected
  • Identity manipulation: None
  • Hidden behavior: None
  • Confirmation bypass: Properly enforced via --confirm
  • Hidden content (base64/invisible chars): None
  • HTML comments with malicious content: None

Result: ✅ Clean

Dangerous Operations Check

The plugin involves significant financial operations: perps trading (up to 100x leverage), deposits, withdrawals, cross-DEX transfers, contract calls.

User confirmation enforcement:

  • All write operations require explicit --confirm flag
  • TEE signing via onchainos (private keys never exposed)
  • Pre-flight balance checks before order placement
  • Multiple safety guards (max-price for USDH, peg deviation checks, position size validation)
  • SL/TP price direction validation
  • Sui rewards explicitly rejected as unsupported
  • $10 minimum notional auto-bump with stderr logging

Result: ✅ Safe

Data Exfiltration Risk

report_plugin_info (src/onchainos.rs:559-579) shells out to onchainos wallet report-plugin-info with order metadata (wallet, order_id, market, amount, price, timestamp, strategy_id). This is a documented OKX backend attribution feature, not exfiltration to a third party. Data flow goes through the official onchainos CLI.

Result: ✅ No Risk

Overall Security Rating: 🟢 Low Risk

Despite the high inherent risk of perpetuals trading, the plugin's implementation is exemplary: proper onchainos delegation, explicit --confirm gating, comprehensive validation, untrusted-data boundary declaration, and no private key handling.

6. Source Code Security (if source code is included)

Language & Build Config

  • Language: Rust
  • Entry point: src/main.rs
  • Binary name: hyperliquid-plugin
  • 39 source files, well-organized into commands/ modules

Dependency Analysis

Dependency Version Notes
clap 4 Well-maintained CLI framework
tokio 1 Standard async runtime
reqwest 0.12 Standard HTTP client
serde/serde_json 1 Standard serialization
sha3 0.10 Keccak256 (used for ABI selectors and HL connection_id)
hex 0.4 Hex encoding
rmp-serde 1 MessagePack (for HL action_hash)
anyhow 1 Error handling
futures 0.3 Async utilities

All dependencies are standard, well-maintained, and appropriate for the use case. No suspicious or unmaintained packages.

Code Safety Audit

Check Result Detail
Hardcoded secrets (API keys, private keys, mnemonics) No secrets found; all signing via onchainos TEE
Network requests to undeclared endpoints All endpoints declared in plugin.yaml's api_calls and SKILL.md
File system access outside plugin scope No file I/O detected in plugin code
Dynamic code execution (eval, exec, shell commands) ⚠️ Multiple Command::new("onchainos") invocations — appropriate use for CLI delegation; no shell command construction from user input
Environment variable access beyond declared env Only HYPERLIQUID_TESTNET env var read (config.rs); appropriate
Build scripts with side effects (build.rs, postinstall) No build.rs detected
Unsafe code blocks (Rust) No unsafe blocks found in source

Note on Command::new: The plugin shells out to onchainos extensively (expected/required). Arguments are constructed from typed parameters, not raw user strings. Wallet addresses come from onchainos itself. JSON payloads are properly serialized via serde_json. No command injection vectors identified.

Endpoint declaration check: All URLs in source code (api.hyperliquid.xyz, arbitrum-one-rpc.publicnode.com, rpc.hyperliquid.xyz, api.relay.link, app.hyperliquid.xyz) are declared in plugin.yaml api_calls. ✅

Does SKILL.md accurately describe what the source code does?

Yes — SKILL.md command descriptions, parameters, and behavior match source code implementations. The HIP-3/HIP-4 architecture explanation, signing schemes (TEE EIP-712), and fee notes (e.g., $1 USDC withdrawal fee) are accurately reflected in code.

Verdict: ✅ Source Safe

7. Code Review

Quality Score: 91/100

Dimension Score Notes
Completeness (pre-flight, commands, error handling) 24/25 Excellent: pre-flight section, comprehensive command index, structured error_response helper, SHA256 verification of installers
Clarity (descriptions, no ambiguity) 23/25 Detailed command examples, clear HIP-3/HIP-4 explanations, comprehensive trigger phrases. Some sections quite long
Security Awareness (confirmations, slippage, limits) 24/25 All write ops require --confirm, slippage controls, peg deviation checks, balance pre-flight, $10 min notional auto-bump, untrusted data boundary
Skill Routing (defers correctly, no overreach) 13/15 Clear "Skill Routing" and "Do NOT Use For" sections. References related skills appropriately
Formatting (markdown, tables, code blocks) 9/10 Well-formatted tables, consistent code blocks, clear section hierarchy

Strengths

  • Exemplary onchainos integration: All signing/broadcasting goes through TEE; no private key handling in plugin code
  • Comprehensive safety guards: balance pre-flight, slippage caps, peg deviation checks, size auto-bumping, direction validation for SL/TP, mandatory --confirm for writes
  • Well-architected: clean separation of concerns (api, commands, config, onchainos, rpc, signing modules)
  • HIP-3/HIP-4 support is technically sophisticated: properly handles asset ID namespaces, separate clearinghouses, USDH funding, two coin-string encodings (#N vs +N)
  • Strong supply-chain hygiene: SHA256 verification of installers in pre-flight CI block

Issues Found

  • 🔵 Minor: report_plugin_info failures only logged to stderr — could be missed by users; consider documenting this behavior more prominently in SKILL.md
  • 🔵 Minor: Some documentation sections are very long (HIP-3/HIP-4 chapters) — consider moving to references/ files
  • 🔵 Minor: The register command intentionally submits a known-invalid order (size=0, price=0) to extract signer address from error response. This is clever but unconventional — worth a code comment explaining the technique is HL-specific
8. Language Check
File Language Detected English?
SKILL.md English
SUMMARY.md English
9. SUMMARY.md Review
Check Result
File exists
Written in English
Has Overview section
Has Prerequisites section
Has Quick Start section
Character count ≤ 17,000 ✅ 3021 chars
11. Recommendations
  1. Consider documenting report-plugin-info data flow more prominently in SKILL.md so users understand strategy attribution data is sent to OKX backend.
  2. Move the long HIP-3/HIP-4 architectural sections to references/hip3.md and references/hip4.md to improve SKILL.md scannability.
  3. Add a code comment in register.rs explaining that the size=0/price=0 trick to extract the signer is intentional.
  4. Consider adding rate limiting / retry logic for the relay.link API in get_gas.rs to handle transient failures more gracefully.
  5. The pre-flight CI block downloads from mig-pre/plugin-store (not okx/plugin-store) — verify this is the intended publisher namespace before promoting to production.
12. Reviewer Summary

One-line verdict: A well-architected, security-conscious Hyperliquid trading plugin with exemplary onchainos integration, comprehensive safety guards, and accurate documentation.

Merge recommendation: ✅ Ready to merge

Blockers (if any — list every issue that MUST be fixed before merge, each prefixed with ❌):

No blockers found.

The plugin demonstrates strong security practices: all signing delegated to onchainos TEE, mandatory --confirm flags, balance/slippage pre-flight checks, untrusted-data boundary declaration, and SHA256 verification of installers. The minor recommendations above are nice-to-haves and do not block merge. One item to verify: the mig-pre/plugin-store namespace in the auto-injected CI block — confirm this matches the intended publishing pipeline.


Generated by Claude AI via Anthropic API — review the full report before approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-reviewed ci-approved Maintainer reviewed PR; allows Phase 1/2/3 CI to run plugin-update structure-validated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant