Skip to content
Business logic Audit finding Intermediate

BaseAuth.recoverSapientSignature returns a constant instead of signer image hash, breaking sapient signer flows

BaseAuth.recoverSapientSignature returns a hardcoded constant instead of the signer's image hash, contrary to the ISapient interface. When a Sequence wallet is used as a sapient signer, the wrong value is fed into the Merkle leaf calculation, so the reconstructed wallet image hash does not match and signature validation fails, making those configurations unusable.

Agontuk Follow with 0xnija, axelot and 2 others

Originally disclosed on Code4rena

Submitted by Agontuk, also found by 0xnija, axelot, francoHacker, and Nora

https://github.com/code-423n4/2025-10-sequence/blob/ccc328beeadd28fdbde53b034098c865104fcaf3/src/modules/auth/BaseAuth.sol#L120-L140

https://github.com/code-423n4/2025-10-sequence/blob/ccc328beeadd28fdbde53b034098c865104fcaf3/src/modules/interfaces/ISapient.sol#L1-L39

Finding Description

BaseAuth.recoverSapientSignature() violates the ISapient interface contract by returning a constant value instead of the signer’s imageHash. The ISapient interface specifies that sapient signers “return their own imageHash” for the provided payload and signature via recoverSapientSignature(...). However, the implementation in BaseAuth.recoverSapientSignature() unconditionally returns bytes32(uint256(1)).

Walkthrough and root cause:

  • BaseAuth.recoverSapientSignature():

    • Mutates _payload.parentWallets by appending msg.sender.
    • Calls signatureValidation(...) to validate the signature.
    • On success, it returns bytes32(uint256(1)) rather than the actual sapient signer image hash.
  • ISapient.recoverSapientSignature() contract:

    • recoverSapientSignature communicates that the function must return the correct signer image hash.
  • Downstream consumer:

    • BaseSig.recoverBranch() consumes the return value from ISapient(addr).recoverSapientSignature(...) as a real image hash to construct the Merkle leaf via _leafForSapient(...).
    • When BaseAuth.recoverSapientSignature() returns 0x...01, BaseSig incorporates this incorrect “image hash” into the merkle calculation, corrupting the final image hash.

Highest-impact scenario: If a Sequence wallet is configured to use another Sequence wallet (or itself) as a sapient signer, any signature path that relies on BaseAuth.recoverSapientSignature() will produce an incorrect sapient leaf (imageHash = 0x...01), causing the overall wallet image hash to mismatch the expected configuration. This results in signature validation failure (denial of service) for those flows, making such configurations unusable.

Impact

Medium. The bug violates a public interface contract and deterministically breaks configurations where a Sequence wallet is used as a sapient signer. This leads to denial of service / mis-integration (not a direct privilege escalation), but it renders a supported path unusable. It undermines the correctness of merkle image reconstruction, a core invariant of the system.

Likelihood

Medium. Sapient signers are a first-class feature and used in complex configs. Any integration using BaseAuth as a sapient signer will consistently hit this bug. The issue triggers deterministically whenever recoverSapientSignature() is invoked and the signature validates, because the function always returns the constant.

Recommended mitigation steps

Return the actual signer image hash from BaseAuth.recoverSapientSignature() to conform to ISapient and maintain merkle image correctness.

Two straightforward approaches:

  • Extend signatureValidation(...) to also return the derived imageHash (it already computes it in the dynamic branch via BaseSig.recover(...)) and return that from recoverSapientSignature().
  • Or directly call BaseSig.recover(_payload, _signature, false, address(0)) inside recoverSapientSignature() and return the imageHash.

Proof of Concept

Add PoC test into test/modules/BaseSig.t.sol (BaseSigTest), import BaseAuth.sol, Add a helper contract MinimalSapient

+ import { BaseAuth } from "../../src/modules/auth/BaseAuth.sol";

Helper contract:

contract MinimalSapient is BaseAuth {
  function _updateImageHash(bytes32) internal override {}
  function _isValidImage(bytes32) internal view override returns (bool) { return true; }
}

PoC test:

  function test_BaseAuth_recoverSapientSignature_ReturnsConstant() external {
    MinimalSapient sap = new MinimalSapient();

    Payload.Decoded memory payload;
    // Minimal dynamic signature:
    // - signatureFlag = 0x00 (no chain id, no checkpoint bytes, 1-byte threshold)
    // - threshold byte = 0x00 (threshold = 0)
    // - no branch content -> weight defaults to 0, passes since threshold=0
    bytes memory innerSig = hex"0000";

    bytes32 ret = sap.recoverSapientSignature(payload, innerSig);
    assertEq(ret, bytes32(uint256(1)));
  }

Before running the test, run a server using the following command:

cd ../sequence.js
pnpm build:packages
pnpm dev:server

Then run the test from repo root:

forge test --mt test_BaseAuth_recoverSapientSignature_ReturnsConstant -vvv
  • The new helper contract MinimalSapient inherits BaseAuth, implements _updateImageHash() and _isValidImage() trivially to allow calls.
  • The PoC test deploys MinimalSapient, crafts a minimal valid dynamic base-auth signature with threshold = 0 and no branch content so it passes signatureValidation(), then calls recoverSapientSignature(...).
  • Asserts that the function returns bytes32(uint256(1)), demonstrating the incorrect constant return instead of a real image hash.

Test result: Test passes, confirming the function returns a constant rather than a true image hash.


The original report as published on Code4rena, by Agontuk. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The implementation returns a hardcoded constant rather than the actual signer image hash, violating the ISapient interface contract.

Impact

Configurations where a Sequence wallet is used as a sapient signer deterministically fail signature validation, causing a denial of service for that supported path; the report states this is not a direct privilege escalation.

What the attacker needed

Wallet configured with a sapient signer; signature path uses recoverSapientSignature

The fix

The function should return the real signer image hash, either by having signatureValidation also return the derived image hash or by calling BaseSig.recover directly and returning its image hash.

How it was found

  1. Deploy a minimal contract inheriting BaseAuth with trivial image hash and validity overrides.
  2. Craft a minimal valid dynamic base-auth signature with threshold zero and no branch content.
  3. Call recoverSapientSignature with that payload and signature.
  4. Observe that the returned value is the constant one rather than a real image hash.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A wallet can be set up so that another wallet acts as one of its signers. To check such a signature, the code asks the signer wallet for a short fingerprint of itself, called an image hash, and uses it to rebuild the wallet's overall fingerprint. Here the signer wallet always answers with the same fixed number instead of its real fingerprint, so the rebuilt fingerprint never matches and the signature is rejected.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Agontuk

View all

3 more disclosed reports, best first.

More from Sequence

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.