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: 47/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
ConsoleAccount
and SubAccount
. This analysis dives deep into the intricacies of the Brahma ecosystem, focusing on possible security loopholes, briefly detailing possible gas improvements, and in depth function-level interactions.SafeModeratorOverridable
guard and policy layers.ConsoleAccount
or external operators. It also has an optional SafeModerator
guard and policy layers.TransactionValidator
and PolicyValidator
.policyHash
and Trusted Validator Signature
.ExecutorRegistry
.TypeHashHelper.sol
SafeHelper.sol
generateCalldata
function should be optimized for gas efficiency. Ensure that storage slots are obtained in a gas-efficient manner.TransactionValidator.sol
validatePreTransaction
and validatePostTransaction
functions should be carefully audited to ensure they enforce all policy/state compliance checks.SafeModeratorOverridable.sol
SafeEnabler.sol
DELEGATECALL
is executed securely, bypassing the selfAuthorized
check only when absolutely necessary.SafeModerator.sol
validateTransaction
function should be optimized for gas efficiency and should include all necessary policy checks.Constants.sol
immutable
to save on gas costs.ConsoleFallbackHandler.sol
AddressProvider.sol
PolicyValidator.sol
PolicyRegistry.sol
setPolicy
function should include a time-lock mechanism for added security.ExecutorRegistry.sol
WalletRegistry.sol
registerWallet
and registerSubAccount
functions should be secured with the onlyOwner
modifier.AddressProviderService.sol
SafeDeployer.sol
deploySafe
function should be optimized for gas efficiency.ExecutorPlugin.sol
executeTransaction
function should include rate-limiting mechanisms to prevent abuse.policyHash
: A keccak256 hash that represents the transaction policy. It's crucial for ensuring that the transaction adheres to predefined rules.Trusted Validator Signature
: A digital signature from a trusted validator, usually an EOA, that is verified in PolicyValidator
before transaction execution.Guard
: The address of the guard contract, which can be either SafeModerator
or SafeModeratorOverridable
, depending on the account type.ConsoleAccount.sol
: Main contract for user-initiated transactions.SubAccount.sol
: Allows transactions to be initiated by a ConsoleAccount
or an external operator.SafeModerator.sol
: Validates transactions for SubAccount
.SafeModeratorOverridable.sol
: An extended version of SafeModerator
with additional features, used in ConsoleAccount
.TransactionValidator.sol
: Validates the integrity and rules of transactions.PolicyValidator.sol
: Validates policy commitments.ExecutorPlugin.sol
: Enables third-party transaction execution.SafeModerator
and SafeModeratorOverridable
interact with TransactionValidator
and PolicyValidator
through internal function calls.ExecutorPlugin
interfaces with TransactionValidator
through a series of function calls to validate third-party transactions.policyHash
: Ensure that the hash is generated using keccak256 and is stored efficiently to minimize gas costs.Trusted Validator Signature
: Use EIP-712 for generating structured and secure signatures. Store only the hash of the signature to optimize storage costs.Guard
: Use a contract interface to enforce a standard set of functions for any guard contract.onlyOwner
: This should be used in functions like setGuard
to ensure that only the contract owner can change the guard.nonReentrant
: Apply this modifier to execTransaction()
to prevent re-entrancy attacks.SafeMath
library specifically in the execTransaction()
function to prevent integer overflow and underflow.Ownable
contract for robust and secure ownership management, especially in ConsoleAccount
and SubAccount
.setGuard
function to allow for community vetting.SafeModerator
and SafeModeratorOverridable
to allow for future security enhancements.ExecutorPlugin
to prevent abuse by external executors.SafeModerator
contract has the power to validate or invalidate transactions, creating a central point of failure.TransactionValidator
uses isPolicySignatureValid()
to validate the policyHash
and Trusted Validator Signature
, making it the cornerstone of transaction validation.PolicyValidator
uses a registry to validate policy commitments, making it crucial for ensuring that transactions adhere to predefined rules.Guard
mechanism in ConsoleAccount
and SubAccount
can be optionally set, providing flexibility but also adding complexity in understanding the security model.nonReentrant
is not properly implemented in execTransaction()
.TransactionValidator
due to the lack of transaction ordering enforcement.ConsoleAccount
:
setGuard(address(0))
.SubAccount
:
policyHash
manipulation by unauthorized external executors.onlyOwner
modifier for policy updates and validate policyHash
against a registry.SafeModerator
:
TransactionValidator
:
ConsoleAccount
and SubAccount
can lead to inconsistent security postures.ExecutorPlugin
allows external transaction execution but lacks robust rate-limiting mechanisms.PolicyValidator
relies on a centralized registry, creating a single point of failure.PolicyValidator
.I made function interaction graphs for the key contracts to better visualize interactions, as seen below:
Link to Graph for TypeHashHelper.sol.
Link to Graph for SafeHelper.sol.
Link to Graph for TransactionValidator.sol.
Link to Graph for SafeModeratorOverridable.sol.
Link to Graph for SafeModerator.sol.
Link to Graph for ConsoleFallbackHandler.sol.
Link to Graph for AddressProvider.sol.
Link to Graph for PolicyValidator.sol.
Link to Graph for AddressProviderService.sol.
16 hours
#0 - c4-pre-sort
2023-10-22T21:13:51Z
raymondfam marked the issue as sufficient quality report
#1 - alex-ppg
2023-10-27T13:35:41Z
While the report does analyze each module in detail, it does not have a solid grasp of the Brahma system. Upgrade-ability and ownership-related recommendations are incorrect as a result (i.e. the setGuard
operation of address(0)
is a multi-signature process by definition as being the result of a Gnosis Safe vote).
#2 - c4-judge
2023-10-27T13:35:46Z
alex-ppg marked the issue as grade-b