Skip to content

ERC-1271 Signature Verification on a Safe: The One Read evmquery Can't Resolve

evmquery's ABI auto-resolution can't call isValidSignature on a Gnosis Safe, because the check lives on the fallback handler, not the Safe's own contract. Verified live, with the raw viem call that still works.

evmquery team8 min read
Try it: Gnosis Safe InspectorOwners, threshold, nonce and version on Ethereum, Base, BNB Smart Chain, Polygon. Free, no signup.

A dapp asks a Safe to sign something off-chain — a Permit, a Snapshot vote, an attestation — and now needs to check whether the signature is real. ecrecover doesn’t help: a Safe has no private key, so there’s nothing to recover a signer from. The real check is ERC-1271’s isValidSignature, a read-only call the Safe itself answers. Every other field on a Safe (owners, threshold, nonce, modules) reads cleanly through evmquery in the owners/threshold guide on this blog. isValidSignature doesn’t, and the reason is specific enough to be worth writing down.

TL;DR

evmquery’s ABI auto-resolution lints safe.isValidSignature(...) as “no matching overload” on every Safe version, because GnosisSafe.sol never defines the function itself — it lives on the separate CompatibilityFallbackHandler contract, reached through the Safe’s fallback. A raw viem readContract call with a hand-written ABI fragment resolves it fine, verified live against a real signed message on mainnet.

What's verified in this post

  • isValidSignature is not part of GnosisSafe.sol in either the Safe v1.3.0 or v1.4.1 source (confirmed against the safe-global/safe-smart-account tags). It’s implemented on CompatibilityFallbackHandler.sol and reached only through the Safe’s fallback() forwarding, which is why evmquery’s resolved ABI for a Safe proxy never includes it.

  • The legacy ERC-1271 magic value is 0x20c13b0b (the isValidSignature(bytes,bytes) overload’s own selector), not the newer 0x1626ba7e (isValidSignature(bytes32,bytes)) most docs quote — Safe’s fallback handler still returns the legacy value internally and only translates to the new one on the bytes32 entrypoint.

  • Live-verified on Ethereum, Safe 0x0DA0C3e52C977Ed3cBc641fF02DD271c3ED55aFe, block 26,425,158: isValidSignature(0x9caa5088...051c, "0x") returns 0x20c13b0b for a message this Safe actually signed via SignMessageLib, and reverts Hash not approved for a message it never signed.

  • evmquery’s REST API silently ignores a custom abi field on a schema.contracts entry — confirmed by passing a fabricated function name and getting the identical “no matching overload” lint error. There’s no way to hand evmquery an ABI fragment it didn’t resolve itself.

What isValidSignature actually checks

ERC-1271 gives any smart contract a way to answer “did I approve this?” without a private key. The interface is one view function:

function isValidSignature(bytes32 _hash, bytes memory _signature) external view returns (bytes4 magicValue);

A correct implementation returns 0x1626ba7e — bytes4(keccak256("isValidSignature(bytes32,bytes)")), the function’s own selector by design — if the signature is valid for that hash, and anything else otherwise. For contracts that predate the final spec, there’s an older sibling that takes the raw signed data instead of its hash:

function isValidSignature(bytes memory _data, bytes memory _signature) public view returns (bytes4 magicValue);

Its magic value is 0x20c13b0b. A Safe’s fallback handler implements the older interface natively and the newer one as a thin wrapper around it, which is the first thing worth knowing before reading any example that cites one magic value and not the other.

Reaching for evmquery first

Every other Safe field on this blog reads through one evmquery expression, so the natural first move is to try the same thing here:

curl -s -X POST https://api.evmquery.com/api/v1/query \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"chain": "evm_ethereum",
"schema": { "contracts": { "safe": { "address": "0x0DA0C3e52C977Ed3cBc641fF02DD271c3ED55aFe" } } },
"expression": "safe.isValidSignature(hexBytes(\"0x9caa50881aed6c349917d540a3f83ac2b708eea2b977d3fc4e4c58fac1ed051c\"), hexBytes(\"0x\"))"
}'
{
"errors": [
{
"code": "QUERY__EXPRESSION_INVALID",
"detail": "Expression invalid:\n- error: found no matching overload for 'SEL_Contract_safe.isValidSignature(bytes, bytes)'",
"status": "400"
}
]
}

Run live, on the same Safe, right after a VERSION() call that succeeds normally:

{ "result": { "value": "1.3.0", "type": "string" }, "meta": { "blockNumber": "26425149" } }

Same contract, same request shape, one field resolves and the other doesn’t — and it isn’t a syntax mistake. Every bytes32/bytes and bytes/bytes argument combination lints the same way, and passing a fabricated abi array inside the contracts entry changes nothing: evmquery ignores it and resolves the ABI itself regardless of what’s supplied. This isn’t a quirk of this one Safe, either — the proxy-vs-singleton trap the owners/threshold guide documents is a storage problem; this is a resolution problem that applies to every Safe proxy on any evmquery chain, because none of them define isValidSignature in their own bytecode.

Why: the function lives on the fallback handler, not the Safe

A Safe proxy delegates its core logic (getOwners, getThreshold, checkSignatures) to a shared singleton implementation, confirmed for GnosisSafe.sol directly against the safe-global/safe-smart-account v1.3.0 tag: there’s no isValidSignature function anywhere in that file. It’s defined on a separate contract, CompatibilityFallbackHandler.sol:

// CompatibilityFallbackHandler.sol, v1.3.0 and v1.4.1 alike
function isValidSignature(bytes calldata _data, bytes calldata _signature) public view override returns (bytes4) {
GnosisSafe safe = GnosisSafe(payable(msg.sender));
bytes32 messageHash = getMessageHashForSafe(safe, _data);
if (_signature.length == 0) {
require(safe.signedMessages(messageHash) != 0, "Hash not approved");
} else {
safe.checkSignatures(messageHash, _data, _signature);
}
return EIP1271_MAGIC_VALUE; // 0x20c13b0b
}

A Safe reaches this code through fallback(): any call the Safe’s own bytecode doesn’t recognize gets forwarded to whatever contract setFallbackHandler points at (the CompatibilityFallbackHandler by default, for every Safe deployed through the standard factory). From the caller’s side this is invisible — eth_call the Safe’s address with isValidSignature’s selector and it just works, same as calling any other function the Safe defines directly. evmquery’s ABI resolution doesn’t see it that way: it resolves the Safe proxy’s ABI from its actual implementation contract (the same resolution that makes VERSION() work and getOwners() revert against the wrong address in the owners/threshold guide), and isValidSignature is never in that ABI, because GnosisSafe.sol itself never declares it. The lint check runs before any request reaches the chain, so evmquery rejects the expression on a function it has no way to know the fallback handler will actually answer.

VERSION() and isValidSignature fail for opposite reasons

VERSION() is a hardcoded constant baked into the implementation’s own bytecode — it resolves on the proxy, the singleton, anywhere, because it never touches storage or a fallback. isValidSignature isn’t missing because of storage; it’s missing from the ABI evmquery resolves in the first place. Two different failure classes that happen to involve the same contract.

The raw viem call that works

viem doesn’t resolve a contract’s ABI for you — you supply one, and it trusts you. That’s normally the trade-off these migration posts are written about (evmquery infers; viem makes you be exact), but here it’s the thing that makes the call possible at all:

import { createPublicClient, http, type Abi } from "viem";
import { mainnet } from "viem/chains";
const client = createPublicClient({ chain: mainnet, transport: http() });
// Not GnosisSafe's own ABI — this is CompatibilityFallbackHandler's
// interface, called through the Safe's fallback(). evmquery never
// resolves this ABI for a Safe proxy; viem doesn't need it to.
const COMPATIBILITY_FALLBACK_HANDLER_ABI = [
{
name: "isValidSignature",
type: "function",
stateMutability: "view",
inputs: [
{ name: "_data", type: "bytes" },
{ name: "_signature", type: "bytes" },
],
outputs: [{ name: "", type: "bytes4" }],
},
{
name: "getMessageHash",
type: "function",
stateMutability: "view",
inputs: [{ name: "message", type: "bytes" }],
outputs: [{ name: "", type: "bytes32" }],
},
] as const satisfies Abi;
const SAFE: `0x${string}` = "0x0DA0C3e52C977Ed3cBc641fF02DD271c3ED55aFe";
async function isSafeApproved(data: `0x${string}`): Promise<boolean> {
try {
const magicValue = await client.readContract({
address: SAFE,
abi: COMPATIBILITY_FALLBACK_HANDLER_ABI,
functionName: "isValidSignature",
args: [data, "0x"],
});
return magicValue === "0x20c13b0b";
} catch {
return false; // reverts "Hash not approved" for anything unsigned
}
}

Run live against a real Safe transaction history: 0x0DA0C3e52C977Ed3cBc641fF02DD271c3ED55aFe is a 3-of-5 Safe that executed a SignMessageLib.signMessage() delegatecall in 2024, approving the raw data 0x9caa50881aed6c349917d540a3f83ac2b708eea2b977d3fc4e4c58fac1ed051c (sourced from the Safe Transaction Service’s public API for this Safe, not fabricated for this post). At block 26,425,158:

getMessageHash: 0x64495e442a9bb86cf409bb45da704663ce6646230d89c6306ef9d478a1901dc4
isValidSignature (signed message): 0x20c13b0b
isValidSignature (never signed): reverts "Hash not approved"

The magic value and the revert reason match the source exactly, because this is the actual require string from CompatibilityFallbackHandler.sol surfacing through the error. The empty signature ("0x") is deliberate, not a stand-in for a real signature — it’s what tells the fallback handler to check signedMessages[messageHash] directly instead of trying to recover ECDSA signers from an empty byte array.

A Safe's own execTransaction signatures don't work here

It’s tempting to reuse the signatures blob from an already-executed Safe transaction (the owners clearly did sign something) as _signature against an arbitrary hash. It fails with GS026: Invalid owner provided, because execTransaction’s signatures are computed over the EIP-712 SafeTx struct, not the SafeMessage struct isValidSignature hashes internally — two different signing domains, same owners, same ecrecover, structurally incompatible digests. The only way to produce a signature isValidSignature accepts is to sign (or approveHash, or signMessage) the exact message you intend to verify.

What this means for building on top of evmquery

Nothing else about evmquery’s Safe support is wrong, narrowly scoped, or worth avoiding — owners, threshold, nonce, and modules all resolve correctly, in one batched request, for the overwhelming majority of what anyone checking a Safe actually needs. isValidSignature is the one read that needs a hand-rolled ABI and a direct RPC call (or a library that already ships the fallback handler’s ABI), because it depends on bytecode a Safe doesn’t own and evmquery has no reason to go looking for. If your dapp verifies Safe-signed messages, keep viem (or ethers, or any client that lets you supply an arbitrary ABI) in the stack specifically for this one call, and reach for evmquery for developers for everything else a Safe, or any other contract, actually declares itself.

Next steps

Share

For everything else on a Safe, evmquery still works

Owners, threshold, nonce, modules, VERSION — all of it resolves in one request. isValidSignature is the one exception, and now you know why.