Skip to content

feat: [MUSD-445] add build delegations step to money upgrade#8621

Draft
Jwhiles wants to merge 8 commits intomainfrom
musd-445
Draft

feat: [MUSD-445] add build delegations step to money upgrade#8621
Jwhiles wants to merge 8 commits intomainfrom
musd-445

Conversation

@Jwhiles
Copy link
Copy Markdown
Contributor

@Jwhiles Jwhiles commented Apr 28, 2026

Explanation

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 28, 2026

Warning

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Warn Low
Potential code anomaly (AI signal): npm ox is 100.0% likely to have a medium risk anomaly

Notes: This module implements parallel WebAssembly computation using Node worker_threads and browser Web Workers, including dynamic worker script execution (Node eval:true and browser Blob URL). It communicates only via postMessage and does not show network exfiltration, credential theft, or persistence within this snippet. The main risks are supply-chain/execution boundary concerns from dynamic worker code and potential CPU/DoS impact if the mining parameters are attacker-influenced. Overall: likely intended for compute work, but should be reviewed and guarded with strict input controls and hardened worker creation.

Confidence: 1.00

Severity: 0.60

From: ?npm/@myx-trade/sdk@0.1.265npm/ox@0.14.20

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/ox@0.14.20. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm ox is 100.0% likely to have a medium risk anomaly

Notes: This fragment is primarily a CPU-intensive proof-of-work/salt-mining implementation using worker-thread parallelism plus an async fallback. It includes input validation, structured error propagation, and abort handling, and it does not show classic malware behaviors (no network/file/process/persistence or dynamic execution in the snippet). The dominant security concern is potential resource-exhaustion/DoS if untrusted callers can control workerCount/count/chunkSize, and secondary concern is leakage of progress/rate metrics into application callbacks/logging. Overall: likely intended PoW functionality but potentially abuse-prone in the wrong threat model.

Confidence: 1.00

Severity: 0.60

From: ?npm/@myx-trade/sdk@0.1.265npm/ox@0.14.20

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/ox@0.14.20. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm ox is 100.0% likely to have a medium risk anomaly

Notes: This dependency is a worker-based “salt mining”/proof-of-work compute engine that loads an embedded WebAssembly payload and runs a CPU-intensive loop in Node worker_threads or browser Web Workers, communicating progress and results via postMessage. There is no direct evidence in this fragment of network exfiltration, credential access, persistence, or system modification. The main security concerns are (1) dynamic worker code execution (Node worker eval:true and browser Blob URL execution) and (2) cryptomining-like resource consumption that can be abused for CPU exhaustion. The embedded WASM module itself should be reviewed to confirm it contains only the expected computation and no hidden side effects.

Confidence: 1.00

Severity: 0.60

From: ?npm/@myx-trade/sdk@0.1.265npm/ox@0.14.20

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/ox@0.14.20. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm ox is 100.0% likely to have a medium risk anomaly

Notes: This dependency is a cross-platform worker harness that executes embedded WebAssembly to perform a “salt mining” computation and returns progress/results to the caller via message passing. In this file, there is no clear evidence of classic malware behaviors such as network exfiltration, credential theft, or filesystem/system sabotage. The most notable supply-chain/security concerns are dynamic code execution patterns (Node Worker with eval:true and browser Blob URL worker scripts) and the potential for CPU-intensive abuse (computational mining-like workload) if invoked in an unauthorized context or with adversarial parameters. Overall: moderate security risk driven by execution surface and availability impact rather than direct data-stealing.

Confidence: 1.00

Severity: 0.60

From: ?npm/@myx-trade/sdk@0.1.265npm/ox@0.14.20

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/ox@0.14.20. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm viem is 100.0% likely to have a medium risk anomaly

Notes: The code implements a cross-chain deposit flow with proper validations, artifact reads, and on-chain interactions. There is no evidence of hidden backdoors, data exfiltration, or malware. The main security considerations relate to token approval logic and correct configuration of flags to avoid granting excessive allowances. Overall, the module appears legitimate for a bridge deposit flow, with moderate risk primarily around configuration of approvals and correct handling of gas/fees.

Confidence: 1.00

Severity: 0.60

From: ?npm/@myx-trade/sdk@0.1.265npm/viem@2.48.4

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/viem@2.48.4. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

const MAX_UINT256 =
'115792089237316195423570985008687907853269984665640564039457584007913129639935';

// Sourced from https://github.com/MetaMask/snap-cash-account-poc/blob/70709e15ddc56288dd9eefa45b425a756f25d2fb/packages/snap/src/api/config.ts#L39-L40
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.

not sure if this the correct address here - I sourced this from the POC - but it might be that this value should also come from the chomp service details endpoint

@Jwhiles Jwhiles force-pushed the musd-445 branch 3 times, most recently from 33e853a to 16087d2 Compare May 5, 2026 11:05
to: delegateAddress,
caveats: [
{ type: 'redeemer', redeemers: [vedaVaultAdapterAddress] },
{ type: 'valueLte', maxValue: 0n },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So if you are using scope then valueLte will automatically be added to the delegation. No need to specify it here.

But maybe a better way would be to not use @metamask/smart-accounts-kit which is a bit bigger package but use @metamask/delegation-core to construct the delegation. Its should still be simple enough but will have much less dependencies then SAK.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think here is an example of using delegation core: https://github.com/MetaMask/metamask-extension/pull/41809/changes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

delegatorImplAddress: Hex;
erc20TransferAmountEnforcer: Hex;
musdTokenAddress: Hex;
redeemerEnforcer: Hex;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we defining the enforcer addresses here and overriding them? I think we should use the ones provided from the package?

readonly #steps: Step[] = [
associateAddressStep,
eip7702AuthorizationStep,
buildDelegationStep,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we actually have to build 2 delegations. Both are pretty much the same except the token address is different. One is for deposits (mUSD) and second is for withdrawals (vmUSD => the boringVaultAddress)

);
}

return 'completed';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we need to also store the delegation then into user authenticated storate + send it to chomp API and intent (delegation hash and some metadata). Not sure if that is means as part of another step.

@Jwhiles Jwhiles changed the title feat: add build delegations step to money upgrade feat: [MUSD-445] add build delegations step to money upgrade May 6, 2026
@Jwhiles Jwhiles force-pushed the musd-445 branch 3 times, most recently from 55a57a7 to c4c6220 Compare May 8, 2026 16:08
@Jwhiles
Copy link
Copy Markdown
Contributor Author

Jwhiles commented May 8, 2026

@metamaskbot publish-preview

Jwhiles added 8 commits May 11, 2026 10:52
Adds a third step to the upgrade sequence that builds, signs, and
submits the auto-deposit delegation that authorises CHOMP's delegate to
move mUSD into the Veda vault on the user's behalf. The step:

- Looks up existing delegations via
  AuthenticatedUserStorageService:listDelegations and skips when one
  matches the configured (delegator, delegate, chain, token).
- Builds a per-call 32-byte salt and constructs the delegation with
  redeemer + valueLte + erc20TransferAmount caveats.
- Signs as EIP-712 V4 typed data via KeyringController:signTypedMessage.
- Submits to ChompApiService:verifyDelegation; throws on rejection.

The `InitConfig` passed to `init()` carries the delegator-impl and
caveat-enforcer addresses; the messenger gains the three new allowed
actions.
…yments

Replaces the @metamask/smart-accounts-kit dependency with the lower-level
@metamask/delegation-core (caveat-term encoders) and
@metamask/delegation-deployments (Delegation Framework contract registry).

- `init()` now takes only a chainId; the EIP-7702 delegator-impl and
  caveat-enforcer addresses are resolved from
  `DELEGATOR_CONTRACTS['1.3.0'][chainId]` rather than being passed in.
  `InitConfig` is no longer exported.
- The build-delegation step builds the three caveats directly with
  delegation-core's `createERC20TransferAmountTerms` /
  `createValueLteTerms` / `createRedeemerTerms`, and constructs the
  EIP-712 typed-data message inline (13 lines).
- Drops a duplicate `valueLteEnforcer` caveat that the smart-accounts-kit
  `erc20TransferAmount` scope helper was inadvertently appending on top
  of the explicit one we passed in.

Net dependency size: ~3 MB → ~650 kB. No behaviour change beyond the
duplicate-caveat fix.
Hands off delegation signing (and DelegationManager address resolution)
to @metamask/delegation-controller, which the wallet client already
wires up globally with a `getDelegationEnvironment` callback.

- Adds `@metamask/delegation-controller` as a dependency.
- Swaps `KeyringController:signTypedMessage` for
  `DelegationController:signDelegation` in the messenger allowlist.
- Drops `delegationManager` from `UpgradeConfig` / `StepContext`; this
  controller no longer needs to know the DelegationManager address —
  DelegationController resolves it.
- Removes the inlined `SIGNABLE_DELEGATION_TYPED_DATA` and salt
  hex→bigint conversion from build-delegations (~25 lines).

The build-delegation step still resolves enforcer + EIP-7702 impl
addresses from `@metamask/delegation-deployments` directly, since those
are statically typed and DelegationController only exposes them via a
string-keyed bag.
The build-delegation step now signs two delegations per upgrade — one
authorising transfers of mUSD (deposit-side) and one authorising
transfers of the Veda boring vault share token vmUSD (withdrawal-side).
Both delegations share delegator, delegate, and redeemer (the Veda
vault adapter); only the ERC20TransferAmount caveat's token differs.

The "already-done" check runs per-token, so re-running the upgrade
after a partial failure only re-signs the missing delegation. Signing
is sequential, deposit before withdrawal, so the user sees one prompt
at a time.

The withdrawal-side token is the Veda boring vault contract address.
This is hardcoded per chain in the controller (mainnet only) until the
CHOMP service-details API exposes it; misconfigured chains throw at
init() time.
After CHOMP verifies a delegation, the build-delegation step now also
calls AuthenticatedUserStorageService:createDelegation so the signed
delegation is stored against the user's profile. Without this the
listDelegations matcher on the next run would never find a stored
record and we'd re-sign on every upgrade attempt.

Order is verify-then-store: if storage fails after CHOMP verification,
nothing is persisted and the next run rebuilds from scratch with a
fresh salt. The inverse (store-then-verify) would risk persisting a
delegation CHOMP later rejects.

Metadata records the per-token symbol (mUSD / vmUSD), the cash-deposit
/ cash-withdrawal intent type, MAX_UINT256 as the allowance, and a
delegationHash derived from @metamask/delegation-core's hashDelegation.
@Jwhiles
Copy link
Copy Markdown
Contributor Author

Jwhiles commented May 11, 2026

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.3.0-preview-2fdaa18
@metamask-previews/accounts-controller@38.0.0-preview-2fdaa18
@metamask-previews/address-book-controller@7.1.1-preview-2fdaa18
@metamask-previews/ai-controllers@0.6.3-preview-2fdaa18
@metamask-previews/analytics-controller@1.0.1-preview-2fdaa18
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-2fdaa18
@metamask-previews/announcement-controller@8.1.0-preview-2fdaa18
@metamask-previews/app-metadata-controller@2.0.1-preview-2fdaa18
@metamask-previews/approval-controller@9.0.1-preview-2fdaa18
@metamask-previews/assets-controller@7.0.0-preview-2fdaa18
@metamask-previews/assets-controllers@106.0.0-preview-2fdaa18
@metamask-previews/authenticated-user-storage@1.0.0-preview-2fdaa18
@metamask-previews/base-controller@9.1.0-preview-2fdaa18
@metamask-previews/base-data-service@0.1.1-preview-2fdaa18
@metamask-previews/bridge-controller@72.0.1-preview-2fdaa18
@metamask-previews/bridge-status-controller@71.1.1-preview-2fdaa18
@metamask-previews/build-utils@3.0.4-preview-2fdaa18
@metamask-previews/chain-agnostic-permission@1.6.0-preview-2fdaa18
@metamask-previews/chomp-api-service@3.0.0-preview-2fdaa18
@metamask-previews/claims-controller@0.5.0-preview-2fdaa18
@metamask-previews/client-controller@1.0.1-preview-2fdaa18
@metamask-previews/compliance-controller@2.0.0-preview-2fdaa18
@metamask-previews/composable-controller@12.0.1-preview-2fdaa18
@metamask-previews/config-registry-controller@0.3.0-preview-2fdaa18
@metamask-previews/connectivity-controller@0.2.0-preview-2fdaa18
@metamask-previews/controller-utils@11.20.0-preview-2fdaa18
@metamask-previews/core-backend@6.2.1-preview-2fdaa18
@metamask-previews/delegation-controller@3.0.0-preview-2fdaa18
@metamask-previews/earn-controller@12.1.0-preview-2fdaa18
@metamask-previews/eip-5792-middleware@3.0.3-preview-2fdaa18
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.0-preview-2fdaa18
@metamask-previews/eip1193-permission-middleware@2.0.0-preview-2fdaa18
@metamask-previews/ens-controller@19.1.1-preview-2fdaa18
@metamask-previews/eth-block-tracker@15.0.1-preview-2fdaa18
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-2fdaa18
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-2fdaa18
@metamask-previews/foundryup@1.0.1-preview-2fdaa18
@metamask-previews/gas-fee-controller@26.2.0-preview-2fdaa18
@metamask-previews/gator-permissions-controller@4.1.0-preview-2fdaa18
@metamask-previews/geolocation-controller@0.1.2-preview-2fdaa18
@metamask-previews/json-rpc-engine@10.5.0-preview-2fdaa18
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-2fdaa18
@metamask-previews/keyring-controller@25.5.0-preview-2fdaa18
@metamask-previews/logging-controller@8.0.1-preview-2fdaa18
@metamask-previews/message-manager@14.1.1-preview-2fdaa18
@metamask-previews/messenger@1.2.0-preview-2fdaa18
@metamask-previews/messenger-cli@0.2.0-preview-2fdaa18
@metamask-previews/money-account-balance-service@1.0.0-preview-2fdaa18
@metamask-previews/money-account-controller@0.3.0-preview-2fdaa18
@metamask-previews/money-account-upgrade-controller@1.3.1-preview-2fdaa18
@metamask-previews/multichain-account-service@9.0.0-preview-2fdaa18
@metamask-previews/multichain-api-middleware@3.1.0-preview-2fdaa18
@metamask-previews/multichain-network-controller@3.1.0-preview-2fdaa18
@metamask-previews/multichain-transactions-controller@7.1.0-preview-2fdaa18
@metamask-previews/name-controller@9.1.1-preview-2fdaa18
@metamask-previews/network-controller@30.1.0-preview-2fdaa18
@metamask-previews/network-enablement-controller@5.1.0-preview-2fdaa18
@metamask-previews/notification-services-controller@23.1.0-preview-2fdaa18
@metamask-previews/passkey-controller@2.0.1-preview-2fdaa18
@metamask-previews/permission-controller@13.1.0-preview-2fdaa18
@metamask-previews/permission-log-controller@5.1.0-preview-2fdaa18
@metamask-previews/perps-controller@6.0.0-preview-2fdaa18
@metamask-previews/phishing-controller@17.1.1-preview-2fdaa18
@metamask-previews/polling-controller@16.0.4-preview-2fdaa18
@metamask-previews/preferences-controller@23.1.0-preview-2fdaa18
@metamask-previews/profile-metrics-controller@3.1.3-preview-2fdaa18
@metamask-previews/profile-sync-controller@28.0.2-preview-2fdaa18
@metamask-previews/ramps-controller@13.3.0-preview-2fdaa18
@metamask-previews/rate-limit-controller@7.0.1-preview-2fdaa18
@metamask-previews/react-data-query@0.2.0-preview-2fdaa18
@metamask-previews/remote-feature-flag-controller@4.2.0-preview-2fdaa18
@metamask-previews/sample-controllers@4.0.4-preview-2fdaa18
@metamask-previews/seedless-onboarding-controller@9.1.0-preview-2fdaa18
@metamask-previews/selected-network-controller@26.1.1-preview-2fdaa18
@metamask-previews/shield-controller@5.1.1-preview-2fdaa18
@metamask-previews/signature-controller@39.2.0-preview-2fdaa18
@metamask-previews/snap-account-service@0.0.0-preview-2fdaa18
@metamask-previews/social-controllers@2.2.0-preview-2fdaa18
@metamask-previews/storage-service@1.0.1-preview-2fdaa18
@metamask-previews/subscription-controller@6.1.2-preview-2fdaa18
@metamask-previews/transaction-controller@65.2.0-preview-2fdaa18
@metamask-previews/transaction-pay-controller@22.1.0-preview-2fdaa18
@metamask-previews/user-operation-controller@41.2.0-preview-2fdaa18

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.

2 participants