Skip to content
Smart contracts Audit finding Intermediate

Module transactions will always fail because incompatible with Safe 1.5.0

The Brahma guard contracts implement the Gnosis Safe module-transaction callback with no return value, while Safe 1.4.0 and later expect a bytes32 hash back. Any module transaction routed through these guards therefore reverts, so the Executor and SubAccount functionality does not work on those Safe versions.

T1MOH Follow with merlin and klau5

Originally disclosed on Code4rena

Submitted by T1MOH, also found by merlin and klau5

Lines of code

https://github.com/code-423n4/2023-10-brahma/blob/main/contracts/src/core/SafeModerator.sol#L80-L86 https://github.com/code-423n4/2023-10-brahma/blob/main/contracts/src/core/SafeModeratorOverridable.sol#L86-L92

Impact

GnosisSafe has concept of module. Trusted modules of GnosisSafe contract can execute arbitrary transactions without signatures once enabled. That’s the main purpose of protocol: to allow the execution of some defined action (like swap on DEX) without signatures via registering such an action in Policy commitment. Then, execute this action via Executor or Main Account without need of delegatee’s signatures, and also allow one to register SubAccounts and manage them via Main Account.

Therefore, ExecutorPlugin and Main Account are enabled as modules. The main problem is that all transactions executed via module will fail, meaning SubAccount is just another GnosisSafe without additional utility. When assessing the severity, I took into consideration protocol specific: protocol is about adding new functionality.

Users also have access to SafeSub-accounts that reduce their risk from the protocol by isolating their interactions.

But core functionality of protocol regarding ExecutorPlugin and SubAccounts doesn’t work. Due to this reasoning I submit it as High, despite there is no financial loss.

Proof of Concept

Let’s take a look on how tx from module is executed:

First, guard.checkModuleTransaction() is called, which returns bytes32 guardHash, and then transaction is executed:

https://github.com/safe-global/safe-contracts/blob/810fad9a074837e1247ca24ac9e7f77a5dffce19/contracts/base/ModuleManager.sol#L82-L104

    function execTransactionFromModule(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation
    ) public virtual returns (bool success) {
        // Only whitelisted modules are allowed.
        require(msg.sender != SENTINEL_MODULES && modules[msg.sender] != address(0), "GS104");
        // Execute transaction without further confirmations.
        address guard = getGuard();

        bytes32 guardHash;
        if (guard != address(0)) {
@>          guardHash = Guard(guard).checkModuleTransaction(to, value, data, operation, msg.sender);
        }
        success = execute(to, value, data, operation, type(uint256).max);

        if (guard != address(0)) {
            Guard(guard).checkAfterExecution(guardHash, success);
        }
        if (success) emit ExecutionFromModuleSuccess(msg.sender);
        else emit ExecutionFromModuleFailure(msg.sender);
    }

In context of Brahma, Guard contract is SafeModerator or SafeModeratorOverridable. They implement the incorrect interface IGuard, so the function checkModuleTransaction() returns nothing.

https://github.com/code-423n4/2023-10-brahma/blob/main/contracts/interfaces/external/IGnosisSafe.sol#L110-L116

    function checkModuleTransaction(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        address module
    ) external;

Here is PoC in Remix to ensure that function reverts when trying to decode output while the function doesn’t return anything:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface WithoutReturn {
      function checkModuleTransaction() external;
}

interface WithReturn {
      function checkModuleTransaction() external returns(bytes32);
}

contract Test {

  function test() external returns(bytes32) {

    address calledContract = address(new ContractWithoutReturn());

    // Reverts on decoding
    bytes32 result = WithReturn(calledContract).checkModuleTransaction();
    return result;
  }
}

contract ContractWithoutReturn is WithoutReturn {

  function checkModuleTransaction() external {}

}

As a result, the function GnosisSafe.execTransactionFromModule() will always revert.

Tools Used

Remix

Recommended Mitigation Steps

Update interface IGuard:

    function checkModuleTransaction(
        address to,
        uint256 value,
        bytes memory data,
        Enum.Operation operation,
        address module
-   ) external;
+   ) external returns(bytes32);

Note:

The protocol is meant to use 1.5.0; the feature with callback to guard in module transactions was introduced in 1.5.0 recently. I also advise to add tests for different safe Versions; now only 1.3.0 is used in tests

The sponsor said they took interface from this PR because GnosisSafe 1.5.0. is still in development. In further discussion, they noted mistake in the interface.

Assessed type

Error

0xad1onchain (Brahma) commented:

Protocol is clearly marked to use safe 1.3.0 and has been mentioned in codebase natspac, tests and clarified multiple times on discord chat.

0xad1onchain (Brahma) confirmed and commented:

Valid, thanks for informing us about this issue. Safe 1.5.0 is still a PR and their specifications keep changing. We will remove support for it until it’s released.

0xsomeone (judge) decreased severity to Medium and commented:

The Sponsor initially maintained that Gnosis Safe v1.5.0 is of no concern, however, the documentation of the SafeModerator::checkModuleTransaction / SafeModeratorOverridable::checkModuleTransaction clearly states that it has been introduced to facilitate support for v1.5.0.

However, as the Sponsor has clearly specified, version 1.5.0 of Gnosis Safe is actively undergoing changes meaning that the interface (although highly unlikely) is subject to change; rendering no course of action as correct except for simply marking that 1.5.0 is not supported until proper support for it has been introduced.

I think the confusion arises from the fact that the various modules of Brahma (i.e. SafeModerator) are meant to be compatible with more versions than the one actually in use by the SubAccount systems etc., given that they represent Gnosis Safe modules that can be attached to any instance, further evidenced by the ability to register any wallet in the WalletRegistry.

As the main version the system supports is 1.3.0, which is fully compatible with the present code, I am inclined to judge this exhibit as a “Medium” rather than a “High”. To note, the bytes32 return value was introduced in Gnosis Safe versions 1.4.0 and up, meaning that the exhibit is applicable to a version that has been released and not only to unreleased versions. In general, the bug will manifest when the module is introduced outside the scope of the repository to a Gnosis Safe with a version of 1.4.0>=.

The Sponsor should either:

  • Incorporate the return function signature change in their system to support Gnosis Safes 1.4.0>= and potentially 1.5.0.
  • Mark versions 1.4.0 and 1.4.1 in addition to 1.5.0 as not supported by the system.

0xad1onchain (Brahma) commented:

Fixed, removed support for safe wallet v1.5.0.


The original report as published on Code4rena, by T1MOH. 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 IGuard interface used by the guards declares checkModuleTransaction with no return value, but Safe 1.4.0+ decodes a bytes32 return value from that call, so the call reverts.

Impact

Module-driven actions such as swaps and SubAccount management fail on Safe 1.4.0 and later, so the protocol's core functionality is unusable there; the report notes no direct financial loss, and the judge rated it Medium because the main supported version 1.3.0 is unaffected.

What the attacker needed

Safe wallet version 1.4.0 or later; Brahma guard enabled on the Safe; A module enabled on the Safe

The fix

The interface was updated to declare a bytes32 return value, and the sponsor later removed support for Safe 1.5.0.

How it was found

  1. Enable the Brahma guard on a Safe running version 1.4.0 or later.
  2. Enable a module such as the Executor plugin on that Safe.
  3. Trigger a transaction from the module.
  4. The Safe calls the guard's checkModuleTransaction and tries to decode a bytes32 result.
  5. The call reverts because the guard returns nothing, so the module transaction fails.

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 'module' is an add-on contract that a Safe wallet trusts to move funds without asking for signatures each time. Before running such a transaction, the Safe asks a 'guard' contract to check it and expects an answer (a hash) back. Here the guard gave no answer, so the Safe's attempt to read the answer failed and the whole transaction was cancelled.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by T1MOH

View all

11 more disclosed reports, best first.

More from Brahma

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.