Auditing your own system? Hackerbane runs smart contract audits. Request an audit.
Hackerbane
ZeroDev
Public research note

ZeroDev Bastion
session wallet and factory

Source review of zerodevapp/bastion 0.0.0-beta. The owner signs a 100-token budget. On the code we read, that budget can be written again after a spend, or left sitting after someone overwrites the operator. A caller-chosen chain id also opens a second 100-token session.

0Critical
2High
1Medium
2Low
2Info
DocumentHACK-AR-2026-ZERODEV-BASTION  /  public source review, EIP-7702 session + factory
What this isA research note and an opinion. ZeroDev did not hire Hackerbane for this.
Systemzerodevapp/bastion master: Bastion.sol, BastionFactory.sol, types/Structs.sol
Review commitfb1e67edf5b956a1fb2b56b1ea4faaad194d1ccc (2025-08-20)
UpstreamPR 2 (hardening patch for B01 to B07)
Date16 September 2026
RevisionR2, 5 October 2026. Renumbered from HB-AR-2026.10. No other changes.
AuthorHackerbane
hackerbane.com hello@hackerbane.com HACK-AR-2026-ZERODEV-BASTION
Hackerbane · Assessment Report HACK-AR-2026-ZERODEV-BASTION

Contents

  1. 1Executive summary
  2. 2Scope and method
  3. 3Findings summary
  4. 4HIGH-01 / B01: checkSig replay refills the budget
  5. 5HIGH-02 / B02: second init spends the leftover row
  6. 6MED-01 / B07: a second chain id mints a second session
  7. 7LOW-01 / B04 and LOW-02 / B05
  8. 8INFO-01 / B03 and INFO-02 / B06
  9. 9Remediation record
  10. 10Disclaimer

1   Executive summary

Bastion is a session wallet. If that phrase is new: the owner of a normal Ethereum account (an EOA, an externally owned account, the kind that holds a private key) signs one permission. That permission names a token, a number of tokens, and a second key called the operator. The operator is then allowed to spend up to that number from the owner, and to make calls as a derived session account. The point is to let a dapp or a bot do a limited amount of work without holding the owner’s main key.

The session account is built on EIP-7702. EIP-7702 is the Ethereum change that lets an ordinary address temporarily run contract code. Bastion does not ask the owner to type a special 7702 signature in a wallet popup. The owner signs a familiar EIP-712 typed message, an Approval. The factory recovers who signed it, then uses the same signature numbers (v, r, s) to compute the session address. Two facts fall out of one signature: who granted the spend, and which address will do the spending.

The factory then writes a second budget in its own storage:

allowance[signer][session][token] = approval.amount

That mapping is not the ERC-20 approve on the token contract. An ERC-20 allowance is the number the token itself will let a spender pull with transferFrom. Apps often leave a large ERC-20 approve on a factory. Bastion’s mapping is meant to be the real cap: how many of the owner’s tokens this session is still allowed to pull through consume. When the operator later calls executeWithAllowance, the session asks the factory to debit that mapping and transferFrom the owner, then runs a list of calls as the session.

The in-repo test is how we decided what “allowed” means. It signs amount = 100, then the owner also does a normal ERC-20 approve(factory, 5000). After two spends, the factory mapping is supposed to read 90, then 80. The README says those token allowances are limited and strictly enforced. So 100 is the lifetime budget for taking tokens out of the owner’s wallet through consume. The 5000 is leftover slack on the token contract. The official test leaves 4900 of it unused.

A few more words before the bugs, because the rest of the note uses them constantly.

A digest is the hash of the typed message the owner signed. Recovering a digest with (v, r, s) should produce exactly one signer. If the factory does not remember that a digest was already used, anyone who saw the signature can present it again.

A chain id is the number that names a network (1 for Ethereum, and so on). EIP-7702 also treats 0 as a wildcard. If the factory takes a chain id as a free argument and does not put that number in the signed digest, two different numbers can produce two different session addresses from one signature.

The EntryPoint is the ERC-4337 contract that accepts a UserOp, a packaged account-abstraction transaction, and asks the account to validate it. Bastion implements validateUserOp so a bundler can run the session that way. RIP-7212 is the precompile that checks P256 signatures (the curve used by many passkeys and secure elements). Bastion has a 64-byte operator path that is meant to talk to that precompile.

The 20-byte operator can also make the session send ETH or tokens that already live on the session address itself, for example coins moved there by an earlier consume. That is session custody. It does not give the operator a second way to take more than 100 from the owner’s wallet. The README talks about a leaked session key. If the operator leaks, pulls from the owner should still stop at 100.

We found two High vulnerabilities that break that story.

HIGH-01 (B01) is a refill. checkSig is public and does not remember that a signature was already used. After a spend, anyone who saw the Approval calldata can call checkSig again with the same (v, r, s). The factory budget jumps back to 100. The operator spends again. They can repeat that until the owner’s 5000 ERC-20 approve is empty. The inverted test required that at most 100 tokens leave the owner. 5000 left. If you never call checkSig a second time, spend stops at 100 and the next 1-token call reverts, so the extra 4900 comes from replaying the signature, not from consume by itself.

We did not call HIGH-01 Critical. A stranger can refill the factory budget. They still cannot pull tokens from the owner unless they are the current operator (or the owner, or the EntryPoint). They also need that leftover ERC-20 approve(factory). The official test has both of those conditions.

HIGH-02 (B02) is leftover factory budget after someone re-initializes the session. initialize can run more than once. A stranger takes the published (v, r, s) and a new Approval (new salt, their operator). Recovering the new digest yields some other address, not an address they pick. initialize overwrites the operator stored on the session. The factory row allowance[originalOwner][session] is not cleared. The new operator then calls factory.consume(originalOwner, leftover) and transfers those tokens out. consume looks up the budget by the owner argument you pass in, not by whoever is currently stored as owner on the session. If the leftover factory budget is still 100, the owner’s wallet goes 10000 to 9900. If they already spent 10 through the session, the leftover budget is 90 and the owner goes 9990 to 9900.

That 90 or 100 is still sitting in the owner’s wallet, waiting to be transferFrom’d. It is not the tokens that were already moved onto the session address by an earlier spend. Those already-moved tokens are the session’s own balance. The current operator could send them out anyway, so taking them is not this finding.

MED-01 (B07) is Medium. The session address is computed from the signature and a _chainId argument that checkSig takes. That argument is not part of the EIP-712 hash the owner signed. Passing the current chain id produces one Ethereum address. Passing 0 (the 7702 wildcard) produces a different Ethereum address. They are two separate accounts, each with its own Bastion storage and its own factory budget row. Calling checkSig once with the live chain id and once with 0 therefore writes two rows of 100 against the same Approval. The signed operator can spend both, so the owner loses 200 tokens after signing 100. A stranger can create the second address’s factory row. Only the signed operator can spend it. Unlike HIGH-01, this does not loop until the 5000 ERC-20 approve is gone. It is a single extra 100.

LOW-01 and LOW-02 (B04, B05) are Low. The operator can send any amount of ETH that is already on the session address. In tests that ETH is placed there with vm.deal or similar; a normal transfer to a 7702 account often reverts. The owner EOA’s ETH balance does not change. validateUserOp accepts a missingAccountFunds argument and never deposits it to the EntryPoint, so the first UserOp can fail with AA21. No tokens move to an attacker.

INFO-01 and INFO-02 (B03, B06) stay Informational. A raw EIP-7702 authorization signature can be passed into checkSig, but the README never tells a user to delegate this implementation from a funded EOA. The P256 / RIP-7212 path encodes 224 bytes; the spec wants 160. Validation fails instead of succeeding, so it does not open a spend.

Counts: Critical 0 · High 2 · Medium 1 · Low 2 · Informational 2. Red on the reviewed pin for HIGH-01, HIGH-02, and MED-01. Ticket codes B01 to B07.

2   Scope and method

TargetRefSHA / note
zerodevapp/bastion master · 2025-08-20 fb1e67edf5b956a1fb2b56b1ea4faaad194d1ccc
In-tree contracts review surface Bastion.sol, BastionFactory.sol, types/Structs.sol
EIP-712 domain factory name BastionFactory · version 0.0.0-beta · live chainid

In scope: the 7702 session wallet and the factory allowance mapping. The in-repo forge test is one happy path. Out of scope: Kernel core, the session-key SDK, the marketing site, and anything we did not name.

We pinned that commit, ran the official happy-path test, and then wrote Foundry tests that state the opposite of each bug (at most 100 tokens leave the owner; a second checkSig must not refill; a mutated Approval must not steal the leftover row; a wildcard chain id must not mint a second 100). A red assertion on the pin is a finding. A green assertion is a hold. We rescored every ticket against the same numbers the official test already ships: signed 100, ERC-20 approve 5000.

Toolchain on the pin: solc 0.8.29, Prague.

Scope

Bastion.sol, BastionFactory.sol, and types/Structs.sol at the commit above.

Out of scope

Kernel, the session-key SDK, other ZeroDev products, and live deployment configuration. This note is about the three files.

Severity

The words Critical, High, Medium, Low, and Informational mean what the table in the Disclaimer says. Colour is a label. The word is what counts.

3   Findings summary

CodeSevTitle
HIGH-01 / B01HighcheckSig permissionless replay refills allowance to the signed amount
HIGH-02 / B02HighSame (v,r,s) plus a mutated Approval overwrites the operator; leftover allowance[owner] is still spendable
MED-01 / B07MediumCaller-chosen _chainId (including 0) derives a second session row; signed operator pulls 200 against a signed 100
LOW-01 / B04Low20-byte operator Call.value is uncapped on the derived session host
LOW-02 / B05LowvalidateUserOp ignores missingAccountFunds (no deposit to the EntryPoint)
INFO-01 / B03InfoA native 7702 authorization signature is accepted as checkSig
INFO-02 / B06InfoP256 path ABI-encodes 224 bytes; RIP-7212 wants packed 160. Fail-closed

Critical: none. A stranger cannot finish consume without becoming the 20-byte operator. Leftover approve(factory) is also a precondition HIGH-01 and HIGH-02 both need. The official test already leaves 4900 unused.

Holds we checked and kept closed, in short: a new amount needs a new signature; a stranger consume underflows; a stranger executeWithAllowance reverts; high- s / v-flip does not mint a second owner session; ERC-2612 and Permit2 type strings are not Approval; the factory domain binds verifyingContract and the live chain id; an empty host initialize reverts instead of writing a ghost row; tokens already sitting on the session are executor custody, not a mapping bypass.

4   HIGH-01 / B01: checkSig replay refills the budget

HIGH-01 / B01: checkSig permissionless replay refills allowance

High replay / allowance

bastion/src/BastionFactory.sol · checkSig

Picture Alice as the owner. She signs an Approval for 100 MOCK tokens and names Bob as the 20-byte operator. The factory recovers Alice, derives a session address from the same signature, stores Bob as the operator, and writes allowance[Alice][session][MOCK] = 100. Alice has also done a normal ERC-20 approve(factory, 5000), the way the official test does it. Bob spends 10. The mapping should now be 90, and should stay 90.

checkSig has no caller gate and no memory that a digest was used. On every valid recover it assigns the signed amount again. Anyone who saw the Approval blob (mempool, logs, a helper who submitted the first call) can call checkSig with the same (v, r, s). The row goes back to 100. Bob spends again. Repeat until the 5000 ERC-20 approve is gone.

The control is the same setup without a second checkSig. Spend stops at 100. The next 1-token pull reverts. Owner 9900, session 100, mapping 0. So the extra 4900 is the replay, not consume by itself.

Why that is bad

The product promise is one signed number. Alice thought she granted 100. The leftover 4900 on the token contract was slack, not a second grant. Replay turns that slack into a working spend path for the current operator.

Why not Critical

Spend still needs the current 20-byte operator (or owner / EntryPoint / the session calling itself). The 5000 slack is the official test setup, not free permissionless theft by a stranger who is not Bob.

Recommended patch

require(allowance == 0) is not enough. After a full consume the row is 0 and replay still works. Mark the EIP-712 digest used on first success. Use Solady ECDSA.recover so a high- s signature cannot be flipped into a second session. A mutated Approval is a different digest; that is HIGH-02, and it needs its own guard in the same change set.

error AlreadyUsed();
mapping(bytes32 digest => bool used) public usedDigest;

// inside checkSig, after recover:
require(!usedDigest[digest], AlreadyUsed());
usedDigest[digest] = true;

5   HIGH-02 / B02: second init spends the leftover row

HIGH-02 / B02: same (v,r,s) plus mutated Approval overwrites operator

High reinit / leftover mapping

bastion/src/Bastion.sol · initialize · BastionFactory.consume

The session address is a function of (chainId, implementation, nonce=0, v, r, s). It does not depend on the Approval struct. A new struct under the old signature numbers still lands on the same session.

initialize has no once-flag. The factory is the only caller, but checkSig is open, so that is not a gate. A stranger reuses Alice’s published (v, r, s) with a new Approval: new salt, operator = attacker. Recovering the new digest yields some other address, not one the attacker picks. initialize overwrites the operator slot. The factory row allowance[Alice][session][token] is not deleted.

The new operator then calls executeWithAllowance with _amount = 0 and a two-call batch: factory.consume(Alice, token, leftover), then token.transfer(attacker, leftover). consume keys the row by the owner argument, not by bastion.owner(). The leftover mapping still belongs to Alice.

On a leftover-100 row, Alice goes 10000 to 9900 and the attacker receives 100. After a 10-token seed pull, Alice goes 9990 to 9900 and the attacker receives 90. The 10 tokens already sitting on the session are not this ticket. The incumbent operator could already send those.

Why that is bad

Alice’s unused factory budget is still a live transferFrom against her wallet. Changing the operator on the session should not keep that budget pointed at her.

Why not Critical

Same bar as HIGH-01: leftover approve(factory) and a 20-byte operator path. Loss stays at or under the leftover mapping (100, or 90 after a seed), not the 5000 slack. The new storage owner is a random recover, not an attacker-chosen key.

Recommended patch

Make initialize one-shot. Same owner and operator may return without writing. A different config reverts. And stop consume from taking an _owner that is not Bastion(msg.sender).owner().

error AlreadyInitialized();

function initialize(address _owner, bytes calldata _operator) external {
    require(msg.sender == address(FACTORY), OnlyFactory());
    require(_operator.length == 20 || _operator.length == 64, InvalidOperatorData());
    if (owner != address(0)) {
        require(owner == _owner, AlreadyInitialized());
        require(keccak256(operator) == keccak256(_operator), AlreadyInitialized());
        return;
    }
    owner = _owner;
    operator = _operator;
}

function consume(address _owner, address _token, uint256 _amount) external {
    require(_owner == Bastion(msg.sender).owner(), OnlyOwner());
    allowance[_owner][msg.sender][_token] -= _amount;
    ERC20(_token).transferFrom(_owner, msg.sender, _amount);
}

Rotate the operator with changeOperator (OnlyOwner). If you ever rotate through a new checkSig, delete the old row first.

6   MED-01 / B07: a second chain id mints a second session

MED-01 / B07: caller-chosen _chainId writes a second spendable row

Medium cross-chain / 7702 address

bastion/src/BastionFactory.sol · getBastionAddress

_chainId is an argument to getBastionAddress. It is not part of the EIP-712 digest the owner signed, and the factory does not require it to equal block.chainid. Passing the live chain id and passing 0 (the 7702 wildcard) therefore produce two different Ethereum addresses. Each address gets its own Bastion storage and its own factory budget row.

Same Approval, same (v, r, s): checkSig(block.chainid) then checkSig(0) writes two factory rows of 100. Both accounts initialize with the signed owner and the signed 20-byte operator. That operator executeWithAllowances both. Owner minus 200 against a signed 100. Factory ERC-20 leftover 4800. The official test always passes block.chainid, so this second row is not documented as intended.

A stranger can write the wildcard row. Only the signed operator can spend it. A stranger executeWithAllowance on either host reverts OnlyOwnerOrOperator. Direct factory.consume reverts.

Why that is Medium

This is one extra 100, not HIGH-01’s loop until the owner’s ERC-20 approve is empty. The spender is still the signed operator. Taking 200 after the owner signed 100 is still unauthorized under the same factory budget HIGH-01 uses, so this is not Info.

Recommended patch

Do not ship require(_chainId == 0 || _chainId == block.chainid). Those two values are two Ethereum addresses, which is this bug. Always derive with block.chainid. If you keep the argument for a transition, reject every other value:

require(_chainId == block.chainid, WrongChainId());
address session = getBastionAddress(_chainId, v, r, s);

If you also need the type-4 wildcard (chainId = 0) for an off-chain SET_CODE, do that only in a view helper. Still write allowance against getBastionAddress(block.chainid, v, r, s). Putting the chain id in the signed struct would also stop a relayer from swapping it. That changes the typehash, so bump the EIP-712 version string if you do it.

7   LOW-01 / B04 and LOW-02 / B05

LOW-01 / B04: uncapped Call.value on the session host

Low ETH / granted execute

bastion/src/Bastion.sol · executeWithAllowance

Approval.amount caps FACTORY.consume of the owner’s tokens. It does not cap Call.value on the derived host. The 20-byte operator runs the same Call[] surface as the owner. If ETH is already on the session (force-credited in tests with vm.deal, or sitting there before the type-4 attach), the operator can send all of it. The owner EOA’s ETH balance does not change. A normal transfer / send to a 7702 account after delegation often reverts, because the host has no receive / fallback.

Session ERC-20 already on the host is intended executor custody. Tokens parked there by an earlier consume can already be sent by the incumbent operator. This ticket is only the ETH value field.

Recommended patch

On the 20-byte operator path, revert if Call.value != 0, unless you add a signed native cap and debit it the way consume debits tokens. Owner and EntryPoint may still send value.

LOW-02 / B05: validateUserOp ignores missingAccountFunds

Low ERC-4337 / AA21

bastion/src/Bastion.sol · validateUserOp

The EntryPoint tells the account how much ETH it still needs as a deposit for this UserOp (missingAccountFunds). The usual IAccount pattern is: if the signature is good, send that amount to msg.sender (the EntryPoint) and ignore the success flag. The EntryPoint checks its own deposit. Bastion never uses the argument. The first UserOp without a paymaster or a prior deposit can fail with AA21. Nothing moves to an attacker. The official test constructs the factory with ep = address(0) and never reaches this function on a real call.

Recommended patch

After a passing signature check, send missingAccountFunds to msg.sender with gas: type(uint256).max. Do not transfer / send (2300 gas). Do not require the call to succeed inside the account. A failed signature should not prefund.

8   INFO-01 / B03 and INFO-02 / B06

INFO-01 / B03: native 7702 auth accepted as checkSig

Informational delegation / type-4

checkSig only requires a successful recover. A type-4 authorization signature over [chainId, impl, 0] recovers the authority as the session. A relayer could then checkSig with an attacker-chosen operator. Raising this would need a product user who attaches this implementation from a funded EOA. The README never asks for that. The product path is EIP-712 Approval, then a derived session. Do not SET_CODE this implementation from an EOA you fund.

Recommended patch

After recover, require signer != session and reject address(0). Use Solady ECDSA.recover. usedDigest (HIGH-01) does not fix this. The auth signature is a different hash than getDigest(approval).

INFO-02 / B06: RIP-7212 layout mismatch

Informational P256 / precompile

The 64-byte operator path ABI-encodes (hash, r, s, operator). That blob is 224 bytes. RIP-7212 / EIP-7951 want packed hash || r || s || qx || qy (160 bytes). A spec-length etch and a missing precompile both leave validateUserOp at 1, never 0. Fail-closed, so this stays Info. The comment in the source already calls the path a demo. Do not advertise the 224-byte encoding as RIP-7212.

Recommended patch

Pack 160 bytes. Copy storage operator into memory first; Solidity 0.8 cannot slice a storage bytes. Require signature length at least 64. Keep fail-closed on an empty return. If you do not want RIP-7212, delete the 64-byte branch.

9   Remediation record

Report date 16 September 2026. Review pin fb1e67edf5b956a1fb2b56b1ea4faaad194d1ccc. Recommended patches for B01 through B07 were sent to the Bastion maintainers. PR 2 on zerodevapp/bastion carries the factory usedDigest / WrongChainId / DelegationSigReuse guards, one-shot initialize, owner-checked consume, operator EthNotAllowed, UserOp prefund, and packed 160-byte RIP-7212 input. Foundry coverage for those guards lives under test/audit/ on that branch.

DateIDsCommit / statementIndependent confirmMerge
09/16/2026 B01 to B07 Patch proposed on PR 2. Not merged to master at the time this note was published. No Open

Open items: all seven findings until master carries the patch and a retest is written down. Highest priority: HIGH-01 and HIGH-02.

Combined factory order we recommended, because order matters: bind chain id, recover, reject auth reuse, consume the digest, then initialize.

function checkSig(Approval memory approval, uint256 _chainId, uint8 v, bytes32 r, bytes32 s) external {
    require(_chainId == block.chainid, WrongChainId());
    address session = getBastionAddress(_chainId, v, r, s);
    bytes32 digest = getDigest(approval);
    address signer = ECDSA.recover(digest, v, r, s);
    require(signer != address(0), InvalidSigFormat());
    require(signer != session, DelegationSigReuse());
    require(!usedDigest[digest], AlreadyUsed());
    usedDigest[digest] = true;
    Bastion(session).initialize(signer, approval.operator);
    allowance[signer][session][approval.token] = approval.amount;
}

10   Disclaimer

Read this before you treat anything above as advice.

This file is a public research note. ZeroDev did not hire Hackerbane. There is no services agreement, statement of work, or client relationship behind it. The ZeroDev name on the cover names the project we read. It is not a partnership badge.

What you have is an opinion about the files and commit named in section 2. It is not a certificate. It is not an endorsement of ZeroDev, of Bastion, or of the patch. It is not a claim that the rest of the ZeroDev stack is safe, or that it is broken.

We are not telling you to merge, deploy, buy, or sell anything. This is not investment advice, legal advice, or a security guarantee. If you ship software, you own that risk. If you run Bastion, you own that risk.

Hackerbane accepts no liability for how anyone uses this note, for bugs it does not name, or for loss that follows from relying on it. Findings can be wrong, incomplete, or already stale the day after the review commit. Code added after that commit was not reviewed. A retest covers only the checks it names.

You may share this file. Sharing it does not create a contract and does not make the reader a client.

This note is provided as-is, as available, with all faults. To the maximum extent the law allows, Hackerbane disclaims every warranty, express or implied, including merchantability, fitness for a particular purpose, title, and non-infringement. No promise that this text is accurate, complete, or free of error, or that any error will be fixed.

Nobody may rely on this note as a professional engagement. It is not financial, tax, legal, or regulatory advice. No third party is a beneficiary of it.

Severity words in this note

Critical Funds or safety, exploitable as scoped. An attacker with the access the threat model grants can take value or break a safety property now.
High Serious, less immediate than critical. Exploitable with a precondition that is realistic but not free: a specific role, a market state, a second bug.
Medium Bounded loss or a broken assumption that does not yet have an exploit path in scope. Fix before the next release.
Low Defense in depth. No direct loss path today; removes a step from a future one.
Informational An observation with no security impact as scoped. Hygiene, clarity, or a note for the next reviewer.

The coloured bars are labels. The word High or Medium is what counts.

hello@hackerbane.com · security@hackerbane.com · hackerbane.com