# Your agent's vault checks tx.origin. A malicious contract can pay itself.

> Source: <https://dev.to/kestrova/your-agents-vault-checks-txorigin-a-malicious-contract-can-pay-itself-m28>
> Published: 2026-11-30 23:03:41+00:00

**Recommendation:** Authenticate agent vault payments with msg.sender, not tx.origin, and check the return value of every ETH transfer so a reverted payment cannot be recorded as paid.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Agents are starting to hold money. A common pattern is a small vault: the owner funds it, an AI agent calls `pay()` when it needs an API or a service, and an allowlist keeps the agent from paying just anyone.

It is also the kind of contract a coding agent writes in a few seconds when you ask for one. Here is a version that compiles, passes a happy-path test and looks reasonable at a glance:

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// A small vault an AI agent uses to pay for API calls on its owner's behalf.
contract AgentVault {
    address public owner;
    mapping(address => bool) public allowedPayee;

    constructor() {
        owner = msg.sender;
    }

    function allow(address payee) external {
        require(tx.origin == owner, "not owner");
        allowedPayee[payee] = true;
    }

    function pay(address payee, uint256 amount) external {
        require(tx.origin == owner, "not owner");
        require(allowedPayee[payee], "payee not allowed");
        payee.call{value: amount}("");
    }

    receive() external payable {}
}
```

There are two problems in it, and both are the kind that survive a quick review because the code "has a require".

I ran this file through the free Kestrova preview (automated Slither analysis, no account and no wallet). The result, unedited:

The preview names each issue and explains why it matters. It doesn't give the file, line or fix, but in a 25-line contract you don't need them.

`tx.origin` is the externally owned account that started the transaction, not the contract or account that called you directly. `msg.sender` is the direct caller.

So `require(tx.origin == owner)` really says: "allow this if the owner started the transaction, whatever path it took to get here." Picture the owner's wallet, or an agent signing with the owner's key, calling some other contract: a token claim, a swap router, an "airdrop checker" a tool suggested. If that contract is malicious, it can call `AgentVault.allow(attacker)` and then `pay(attacker, balance)` in the same transaction. Both checks pass, because `tx.origin` is still the owner.

Agents make this easier to trigger, not harder. They interact with many contracts, often ones they found a minute ago, and they sign more transactions than a careful human would. Any of those transactions can carry a hidden call back into your vault.

That is also why the scanner raises **arbitrary-send-eth** to High. `pay()` sends ETH to an address the caller chooses, and the only thing protecting it is a weak check. The allowlist doesn't help, because the attacker can add itself through `allow()` first.

`payee.call{value: amount}("")` returns a success flag. The contract ignores it. If the payee reverts (a contract with no `receive`, an out-of-gas callback), `pay()` still succeeds.

For a person that's an annoyance. For an agent it's a logic bug: the agent sees a successful transaction, marks the API call as paid and moves on, while the money never left. Some agents will then retry with a fresh payment, and the books stop matching reality.

```
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract AgentVault {
    address public immutable owner;
    mapping(address => bool) public allowedPayee;

    error NotOwner();
    error PayeeNotAllowed();
    error PaymentFailed();

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) revert NotOwner();
        _;
    }

    function allow(address payee) external onlyOwner {
        allowedPayee[payee] = true;
    }

    function pay(address payable payee, uint256 amount) external onlyOwner {
        if (!allowedPayee[payee]) revert PayeeNotAllowed();
        (bool ok, ) = payee.call{value: amount}("");
        if (!ok) revert PaymentFailed();
    }

    receive() external payable {}
}
```

Three changes:

`msg.sender` instead of `tx.origin`, in one `onlyOwner` modifier. A contract in the middle of the call chain is now the caller, so it fails the check.`owner` is `immutable`, which removes a storage read and makes it clear it never changes.
Running the fixed file through the same preview gives: High 0, Medium 0, one Informational note (`low-level-calls`), which just records that the contract uses `.call`. That's expected here, since `.call` is the recommended way to send ETH.

If the agent itself should be able to pay, give the agent its own key and check `msg.sender == agent` for `pay()` only, keeping `allow()` owner-only. Never solve it by going back to `tx.origin`.

The useful part isn't this one contract. It's making the check happen every time an agent writes or changes Solidity, before anyone deploys.

`https://kestrova-api.onrender.com/mcp` to Claude Code, Cursor, VS Code, Claude.ai or ChatGPT (no sign-in). The agent can call `scan_solidity_preview` after editing a contract and fix what it finds before showing you the diff.`scan_contract_address_preview`.
This is automated Slither analysis, not an audit. It catches known patterns like the ones above. It won't prove the vault is correct, and it says nothing about business logic, key management or whether the payees are honest. A clean result means "no known pattern was found", nothing more.

Paste the first contract above into the scanner at [https://kestrova.dev](https://kestrova.dev) and compare the result with the fixed version. If you're building agents that hold or move funds, I'd like to hear which checks you run before an agent touches a contract.
