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
Rank: 45/51
Findings: 1
Award: $14.47
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: niroh
Also found by: 0xDetermination, 0xSmartContract, 0xbrett8571, 0xdice91, 0xweb3boy, Bauchibred, Bube, DadeKuma, JCK, K42, LinKenji, Myd, SAAJ, ZanyBonzy, albahaca, castle_chain, catellatech, digitizeworx, emerald7017, fouzantanveer, hunter_w3b, invitedtea, m4ttm, rahul, xiao
14.466 USDC - $14.47
Brahma Console is a custody and DeFi execution environment that allows users to manage crypto assets in a secure manner. The codebase implements core components like registries, validators, and libraries to enable key functionality.
The architecture follows a service-oriented design with clear separation of concerns. Key components include:
AddressProvider - Single source of truth for resolving addresses of core components and external contracts.
Registries - Manage mappings of accounts, policies, executors etc.
WalletRegistry - Maps wallet addresses to sub-accounts.
PolicyRegistry - Maps accounts to policy commits.
ExecutorRegistry - Maps sub-accounts to approved executors.
Validators - Validate transactions and signatures against policies.
PolicyValidator - Checks transaction signatures against policy commits.
TransactionValidator - Pre and post validation of transactions.
Libraries - Helper contracts for common functionality.
SafeHelper - Interacting with Gnosis Safe contracts.
TypeHashHelper - Building EIP-712 struct hashes.
Services - Key application logic.
SafeDeployer - Deploys new Console accounts and sub-accounts.
ExecutorPlugin - Allows execution via external modules.
Overall, the architecture is well-designed for extensibility and upgradability. The core address provider allows easy swapping of components. Common logic is extracted into libraries and validator contracts provide flexible validation hooks.
The code generally follows best practices and is of good quality:
Well commented with NatSpec documentation.
Modular with separation of concerns.
Use of libraries and interfaces for abstraction.
Immutability used wherever possible.
Input validation with custom errors.
Use of OpenZeppelin contracts where suitable.
Proper access controls and reentrancy guards.
Some areas of improvement:
Reduce contract size by splitting core contracts like AddressProviderService
.
Use events consistently for external consumption.
Additional test coverage for validators and libraries.
Formatting inconsistencies in some areas.
Overall the code is well-structured, documented, and demonstrates solid development practices.
The main centralization risk is the governance control over the AddressProvider
. An attacker gaining control of governance could change critical addresses like registries and validators.
The code mitigates this by emitting events and freezing registries after initial setup. Additional protections like timelocks could be added for governance changes.
There is risk of degraded performance on core validator contracts like PolicyValidator
as transaction volume increases. These could be optimized to reduce external calls.
Validators don't account for reorgs, which could cause post-validation to pass incorrectly. Checking block numbers could prevent this edge case.
The use of DELEGATECALL in some areas introduces risk of errors in the called contracts affecting operation. Using CALL instead would isolate logic better.
Input validation on methods reduces risk of errors or abuse. No obvious vulnerabilities were identified.
The use of typed EIP-712 structs prevents signature replay across transactions.
Additional test coverage would help identify edge cases not covered currently. Formal verification of core validation logic could be beneficial too.
Add timelock
governance and freeze critical registry addresses.
Reduce AddressProviderService
scope and split it into multiple contracts.
Emit events consistently from all state-changing operations.
Optimize validator contracts by caching policy lookups, checking block numbers, minimizing external calls etc.
Use CALL
instead of DELEGATECALL
where possible.
Increase test coverage of validators, libraries, and core logic.
Consider formal verification of validation logic.
Enforce consistent code formatting and linting.
Document codebase architecture and flows.
The Brahma Console codebase implements a well-designed architecture for custody and transaction validation. There is some risk of centralization and performance bottlenecks, but overall code quality is good. Some improvements could be made to governance, testing, and validation logic. The project provides a solid foundation for building secure DeFi services.
22 hours
#0 - c4-pre-sort
2023-10-22T21:16:22Z
raymondfam marked the issue as sufficient quality report
#1 - alex-ppg
2023-10-27T13:25:51Z
The report contains some correct points, however, most of the items specified are either generic that are not really applicable to the Brahma system or do not indicate sufficient insight of the system.
#2 - c4-judge
2023-10-27T13:25:58Z
alex-ppg marked the issue as grade-b