Brahma - emerald7017'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: 23/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-18

External Links

Brahma Console is a non-custodial DeFi execution and management platform built on top of Gnosis Safe, leveraging Safe's battle-tested security infrastructure. The core components include:

  • Main Console - The central Safe wallet owned by the user
  • Sub-Accounts - Additional Safes owned by the Main Console for isolation of capital and risk
  • Console Hook - A Safe guard that enforces policies and security checks on transactions
  • Console Plugin - An optional Safe module that enables automation capabilities

Architecture

Separation of duties

  • Clear separation between Main Console owners who control policies and Sub-Account operators who can only execute permitted transactions. This mimics common fund structures.

  • Main Console owners hold admin rights like creating Sub-Accounts, assigning operators, and configuring granular policies. Sub-Account operators cannot modify policies or ownership.

Risk minimization

  • Sub-Accounts segregate capital and isolate smart contract risk. Approvals are siloed.

  • Automations create disposable Sub-Accounts confining exposure.

Checks-and-balances

  • The immutable Console Hook acts as an unwavering sentinel, fortifying all transactions with robust policies and security validations.

  • Simulation provides guardrails by previewing expected effects before signing.

  • Configurable whitelisting restricts contract interactions.

Overall, the architecture enforces strict controls and oversight between components, while still enabling flexible delegation and automation.

Code Quality

  • Well-structured contract inheritance promotes reusability. Core base contracts are cleanly extended.

  • Strict validation of state transitions and input data throughout. Custom errors provide clarity.

  • Liberal use of events provides transparency into state changes.

  • Code is well-commented. Natspec used extensively.

  • Good modularization via libraries like SafeHelper and TypeHashHelper.

  • Extensive unit test coverage present.

Centralization Risks

  • The AddressProvider is a central point of failure. An exploit could wreak havoc by updating critical authorized addresses like the Hook and Plugin. Suggest decentralizing ownership via a DAO or timelock.

  • Currently the AddressProvider owner sets all authorized addresses. Allowing select trusted roles like Guardian to veto critical changes could mitigate centralized control.

  • While Main Console owners control Sub-Accounts, Main Console ownership itself is not currently modifiable if compromised. Consider allowing Guardians to enact recovery or upgrades.

Mechanism Analysis

Policy Validation

  • Leverages EIP-712 typed structured data for validity signatures, ensuring integrity.

  • Expiry timestamps prevent infinite validity of signatures.

  • Signing domain isolation prevents confused deputy attacks between different validators.

  • Validity signatures guarantee policy compliance without revealing policies.

  • Allows simple validation by multiple entities like Hook and Plugin using a shared schema.

Overall the policy validation scheme is quite robust.

Access Control

  • Transaction validation logic largely lives in the immutable Hook. Great for security.

  • Sub-Account isolation limits blast radius. Capital can be constrained.

  • Operators are restricted to permitted contracts and functions.

  • Whitelists should be configurable only by Main Console owners to prevent circumvention.

The access control model provides very granular and customizable governance.

Systemic Risks

  • Asset approvals are still required for Automations. Large approvals given to disposable Sub-Accounts could pose risk. Whitelisting mitigates this somewhat but aggregate values should be limited.

  • Sub-Accounts still rely on underlying protocol contracts which may contain vulnerabilities. Isolation reduces but does not eliminate risk.

  • While the Hook is immutable, compromised Main Console owners could blacklist the Hook as a module and bypass it. Checks ensuring the Hook's retention would provide assurances.

Suggestions

  • Timelock or DAO ownership of AddressProvider instead of single owner to reduce centralization.

  • Allow Guardians to veto critical AddressProvider changes as a checks-and-balance.

  • Enable Main Console ownership modifications or recovery by Guardians as a safety net.

  • Further constrain total approvals granted within Sub-Accounts.

  • Retain the Console Hook as an immutable module that cannot be removed by Main Console owners.

  • Consider integrating delegated transaction batching schemes to optimize gas and enhance privacy.

Overall Brahma Console has excellent architecture and mechanisms for securely automating DeFi. With a few tweaks to reduce centralization and systemic risks, it would represent an excellent institutional-grade solution.

On the code quality and implementation of Brahma Console:

Modular Design

  • TypeHashHelper library contains reusable structs and functions for building EIP-712 hashes. This is cleanly separated from validation logic.

  • SafeHelper library centralizes Safe interaction logic like signature generation, MultiSend encoding, and helper getters. Prevents duplication.

  • AddressProviderService base contract implements AddressProvider fetching. Reduces boilerplate in child contracts needing authorized addresses.

Defensive Coding

  • Constructor validation prevents deployment with invalid AddressProvider reference.

  • Input validation is extensive, checking for null addresses, invalid enums, empty bytestrings etc. Custom descriptive errors make debugging clear.

  • PolicyRegistry restricts policy updates to authorized roles only.

  • Ownership checks are present throughout to gate sensitive functionality.

  • ReentrancyGuard used appropriately in state-modifying functions.

Events and Comments

  • All state changes emit events - registry updates, parameter changes, errors etc. This facilitates off-chain monitoring and oversight.

  • Natspec comments clearly document intended usage of functions, structs, and variables.

  • Complex logic blocks are preceded by comments explaining approach and expected behavior. Enhances readability.

Testing

  • Near complete unit test coverage of core logic and edge cases.

  • Mocks are used appropriately to model external contract behavior and reduce test complexity.

  • Extensive invariant checking in tests to prevent regressions.

Opportunities

  • Reduce code duplication in policy validation methods by sharing common helpers.

  • Use a common enum for error codes instead of duplicating custom errors across contracts.

  • Add integration tests covering end-to-end workflows and component interactions.

Overall the codebase exhibits well-structured design, defensive practices, clarity, and test coverage - indicative of a high-quality implementation.

Time spent:

17 hours

#0 - c4-pre-sort

2023-10-22T21:17:34Z

raymondfam marked the issue as sufficient quality report

#1 - alex-ppg

2023-10-27T13:21:46Z

The report should contain a greater number of paragraphs rather than going solely with brief bullet points. In any case, the analysis showcases a good understanding of the Brahma system.

#2 - c4-judge

2023-10-27T13:21:51Z

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