Brahma - 0xbrett8571's results

Brahma Console is a custody and DeFi execution environment.

General Information

Platform: Code4rena

Start Date: 13/10/2023

Pot Size: $31,250 USDC

Total HM: 4

Participants: 51

Period: 7 days

Judge: 0xsomeone

Id: 295

League: ETH

Brahma

Findings Distribution

Researcher Performance

Rank: 25/51

Findings: 1

Award: $113.54

Analysis:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

113.5407 USDC - $113.54

Labels

analysis-advanced
grade-a
sufficient quality report
A-17

External Links

Overview

Brahma Console is a custody and DeFi execution environment that aims to provide a secure way for users to interact with DeFi protocols. It does this by deploying Gnosis Safe accounts for users and enabling policy-based approvals for transactions.

The core components of Brahma Console include:

  • AddressProvider - Single source of truth for resolving addresses of core components and external contracts

  • Registries - Keep track of wallets, policies, and executors

  • SafeDeployer - Deploys new Console accounts (Gnosis Safes) and sub-accounts

  • TransactionValidator - Validates transactions against policies before and after execution

  • SafeModerator - A Guard contract that ensures only policy-abiding transactions can execute

  • ExecutorPlugin - Allows execution of batch transactions via a module

Architecture

Brahma Console follows a modular architecture, with core components inheriting from AddressProviderService. This provides a standardized way to resolve addresses of other components through the AddressProvider.

The AddressProvider acts as the single source of truth, being the only contract that needs to be deployed initially. Other components are then added by governance, with their addresses stored in the AddressProvider.

This is a robust and extensible pattern, allowing easy swapping out of components as needed, while maintaining a consistent address resolution mechanism.

The core registries like PolicyRegistry and WalletRegistry are separated from the main logic contracts, keeping the system decoupled. Application logic is further divided into domains like account deployment, transaction validation, and execution.

Code Quality

Overall the code is well structured, making use of appropriate inheritance, libraries, and interfaces. Naming conventions are followed throughout. Comments provide ample explanation of logic and architecture.

Error handling is done properly with custom errors instead of generic revert calls. Input validation ensures bad data does not enter the system. Access controls via _onlyGov modifiers restrict sensitive functionality.

There is extensive test coverage of core components like AddressProvider, SafeDeployer, TransactionValidator and ExecutorPlugin. Mocks are used appropriately to isolate unit tests.

Some opportunities for improvement:

  • Reduce code duplication between SafeModerator and SafeModeratorOverridable contracts

  • Use events more consistently to make transactions easily traceable

  • Validate policy signatures on chain instead of relying on off-chain backend

  • Add integration tests covering end-to-end workflow

Centralization Risks

The AddressProvider governance account has a lot of power, being able to update any authorized address. This is mitigated by supporting a pending governance pattern, where governance changes must be accepted by the new account.

No timelocks are imposed on governance changes, so the AddressProvider could be pointed to malicious contracts instantly. A timelock would make the system more resilient.

The backend Signer that generates policy signatures is also a central point of failure. Signing should ideally happen on-chain to remove this trust assumption.

Mechanism Review

Account Creation

Console accounts and sub-accounts are created by deploying Gnosis Safe proxies in a deterministic way using create2. Salts are used to generate a nonce and owners are sorted to generate the same deployment address consistently.

This predictable account generation enables easy porting of accounts across chains. It does introduce some risk of nonce manipulation, which is mitigated by checking for pre-computed addresses and bumping the nonce if needed.

Setup transactions are bundled to enable modules, register accounts, and set policies in one call using GnosisMultiSend.

Transaction Validation

The TransactionValidator checks transactions against policies in a modular way, supporting both Guard and module flows. Policies take the form of a commit hash, with the actual validation happening off-chain. This avoids expensive on-chain policy validation.

The SafeModerator Guard implements the checkTransaction hook to validate transactions pre-execution. It provides flexibility for Console accounts to override policies by removing the Guard if needed.

The ExecutorPlugin module conducts similar policy checks for batch transactions. A standardized transactionStructHash is passed from the plugin for validation.

Post-execution checks on critical account states provide additional security guarantees.

Systemic Risks

Since custom Guard contracts can be added by governance, care must be taken to avoid introducing vulnerable or malicious guards into the core system.

There is also a risk of funds being locked if a console owner account loses access to its private key, given the social recovery design.

The backend signer has broad power to generate policy signatures that allow arbitrary transactions. Strict controls need to govern this component to prevent compromise.

Recommendations

  • Move policy signature generation on-chain to minimize trust assumptions

  • Implement a timelock mechanism for AddressProvider governance changes

  • Conduct comprehensive smart contract audits on all core components before launch

  • ProvideTOOLS to help users understand and set policies easily

  • Build integration testing suite covering complete end-to-end scenarios

  • Introduce a escape hatch mechanism like Safe's "Disable Module" to unblock funds in emergency

  • Document key operational processes & ownership controls related to signature generation

  • Consider allowing users to select their preferred Guard contract for customizability

Some enhancements around decentralization, testing, and documentation would help improve security and transparency further. With proper controls governing the operational aspects, Brahma Console could provide a robust DeFi execution platform for users.

Time spent:

19 hours

#0 - c4-pre-sort

2023-10-22T21:17:09Z

raymondfam marked the issue as sufficient quality report

#1 - alex-ppg

2023-10-27T13:22:44Z

The report is nicely formatted, well worded, and details solid one-line recommendations at the end that the Brahma project should follow.

#2 - c4-judge

2023-10-27T13:22:49Z

alex-ppg marked the issue as grade-a

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter