# Morpho Authorization Scope (Mode A)

If you use **Mode B (`Morfa Vault / mfUSDC`)**, you **never** grant `Morpho.setAuthorization`; this page applies **exclusively to Mode A (`Direct Wallet` automation)**.

## What `Morpho.setAuthorization` Grants in Morpho Blue

Morpho Blue's native authorization primitive (`Morpho.setAuthorization(address authorized, bool newIsAuthorized)`) is **binary and wallet-wide** across Morpho Blue:

* Morpho Blue itself does **not** have per-market or supply-only authorization flags.
* When you authorize a contract address on Morpho Blue, Morpho Blue relies on the **authorized contract's own bytecode** to enforce what actions can and cannot be executed on your behalf.

## How `MorfaRebalancer.sol` Restricts Its Own Power

Because `MorfaRebalancer.sol` ([`0x2135195643CCC32513Da3baDC6394FbaB8Fb9cfA`](https://etherscan.io/address/0x2135195643CCC32513Da3baDC6394FbaB8Fb9cfA#code)) is **immutable and non-upgradeable** (no proxy, no `delegatecall`, no arbitrary external calls), its exact permitted behavior is fixed permanently in deployed Ethereum bytecode:

* **What `MorfaRebalancer` CAN do on Morpho Blue:**
  * Withdraw your USDC supply position from a whitelisted `Active` or `WithdrawOnly` Morpho Blue USDC market (`loanToken == USDC`) and re-supply `received - fee` back into a whitelisted `Active` Morpho Blue USDC market **on behalf of your same wallet address**, strictly inside your personal `maxFeeBps`, `cooldown`, and resetting 30-day `periodFeeCap`.
* **What `MorfaRebalancer` CANNOT do:**
  * It **cannot** call `Morpho.borrow(...)`.
  * It **cannot** call `Morpho.withdrawCollateral(...)`.
  * It **cannot** move non-USDC loan tokens (`loanToken != USDC` reverts).
  * It **cannot** send withdrawn USDC to any recipient other than re-supplying it to Morpho Blue on your own address (minus the capped rebalance fee retained inside the contract).
  * It **cannot** be upgraded to add new functions later.

***

## Wallets with Active Morpho Blue Borrows or Collateral

:::danger[Use a Dedicated Wallet or Mode B Vault If You Borrow on Morpho Blue]
Even though `MorfaRebalancer.sol` contains no `borrow` or `withdrawCollateral` code paths, granting a wallet-wide `Morpho.setAuthorization` on an address that manages active leveraged loans or collateral adds unnecessary blast-radius coupling if an undiscovered bug were ever present.

`morfa.finance` automatically scans your connected wallet for any open Morpho Blue borrow or collateral positions (`hasAnyBorrowOrCollateral`) and displays a high-visibility warning if any are detected. **Best practice:**

1. Deposit into **Mode B (`Morfa Vault / mfUSDC`)**, which requires **zero** `Morpho.setAuthorization`, **or**
2. Use a **separate dedicated Ethereum address** exclusively for Mode A USDC lending.
:::

***

## `enableWithSig` Front-Running & Replay Protection

When an EOA wallet enables Mode A automation in one transaction via `MorfaRebalancer.enableWithSig(maxFeeBps, cooldown, periodFeeCap, auth, sig)`:

1. **Front-run resilience:** Because Morpho's `setAuthorizationWithSig` can be submitted by anyone holding a valid signed authorization payload, an attacker could attempt to front-run your `enableWithSig` transaction in the public mempool to make `setAuthorizationWithSig` revert on a reused nonce. `MorfaRebalancer` handles this cleanly: if `MORPHO.isAuthorized(msg.sender, address(this))` is already `true` and Morpho's nonce matches the expected post-authorization state, `enableWithSig` proceeds safely to save your configuration.
2. **Post-revocation replay defense:** If you previously authorized `MorfaRebalancer`, later revoked authorization (`setAuthorization(rebalancer, false)`), and someone tried to replay an old `Authorization` signature, Morpho Blue's incrementing per-authorizer nonce rejects the stale signature on-chain.

***

## Instant Revocation Paths

You can revoke Mode A automation at any time, **even if `MorfaRebalancer` is paused or `morfa.finance` is offline**:

| Method | Where to Call | Effect |
| --- | --- | --- |
| **Protocol-level revoke (strongest)** | `Morpho.setAuthorization(0x2135195643CCC32513Da3baDC6394FbaB8Fb9cfA, false)` on [Morpho Blue Etherscan](https://etherscan.io/address/0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb#writeContract) or `morfa.finance` | Immediately removes all Morpho Blue authorization from `MorfaRebalancer`. |
| **Contract-level off-switch** | `MorfaRebalancer.disable()` on `morfa.finance` or Etherscan | Immediately sets `enabled = false` and increments `configVersion`, invalidating any in-flight keeper transaction. Callable even while paused. |
