Prepared by:
HALBORN
Last Updated 04/26/2024
Date of Engagement by: March 28th, 2022 - April 1st, 2022
100% of all REPORTED Findings have been addressed
All findings
3
Critical
0
High
0
Medium
1
Low
0
Informational
2
Brokkr
engaged Halborn to conduct a security assessment on CosmWasm smart contracts beginning on March 28th, 2022 and ending on April 1st, 2022.
The security engineers involved on the audit are blockchain and smart-contract security experts with advanced penetration testing, smart-contract hacking, and deep knowledge of multiple blockchain protocols.
The purpose of this audit is to achieve the following:
Ensure that smart contract functions work as intended.
Identify potential security issues with the smart contracts.
In summary, Halborn identified some improvements to reduce the likelihood and impacts of the risks, which were addressed by the Brokkr team
. The main ones are the following:
Split owner address transfer functionality to allow transfer to be completed by recipient.
Ensure proper verification when checking for spend limits.
Apply validation mechanisms when updating the configurations.
External threats, such as financial related attacks, oracle attacks, and inter-contract functions and calls should be validated for expected logic and state.
Halborn performed a combination of manual review of the code and automated security testing to balance efficiency, timeliness, practicality, and accuracy in regard to the scope of the smart contract audit. While manual testing is recommended to uncover flaws in logic, process, and implementation; automated testing techniques help enhance coverage of smart contracts and can quickly identify items that do not follow security best practices. The following phases and associated tools were used throughout the term of the audit:
Research into architecture, purpose, and use of the platform.
Manual code read and walkthrough.
Manual assessment of use and safety for the critical Rust variables and functions in scope to identify any contracts logic related vulnerability.
Fuzz testing (Halborn custom fuzzing tool
)
Checking the test coverage (cargo tarpaulin
)
Scanning of Rust files for vulnerabilities (cargo audit
) \newline
\begin{enumerate} \item CosmWasm Smart Contracts \begin{enumerate} \item Repository: \href{https://github.com/block42-blockchain-company/brotocol-token-contracts/tree/main}{brotocol-token-contracts} \item Commit ID: \href{https://github.com/block42-blockchain-company/brotocol-token-contracts/tree/6e5b287382d1c3c29d568851ce3038ffff7407a3}{6e5b287382d1c3c29d568851ce3038ffff7407a3} \item Contracts in scope: \begin{enumerate} \item epoch manager \item mvp-tresury \item rewards \item token-pool \end{enumerate} \end{enumerate} \end{enumerate}
Out-of-scope:
External libraries and financial related attacks
Critical
0
High
0
Medium
1
Low
0
Informational
2
Impact x Likelihood
HAL-01
HAL-02
HAL-03
Security analysis | Risk level | Remediation Date |
---|---|---|
PRIVILEGED ADDRESS CAN BE TRANSFERRED WITHOUT CONFIRMATION | Medium | Solved - 03/21/2022 |
REWARDS SPEND LIMIT CAN BE IGNORED | Informational | Solved - 04/08/2022 |
LACK OF VALIDATION WHEN UPDATING EPOCH STATE | Informational | Solved - 04/08/2022 |
// Medium
Incorrect use of the update_config
function in contracts can set the owner to have an invalid address and inadvertently lose control of the contracts, which cannot be undone in any way. Currently, the contract owner can change the owner address using the aforementioned function in a single transaction
and without confirmation
from the new address.
The affected smart contracts are the following:
In the epoch manager contract:
if let Some(owner) = owner {
config.owner = deps.api.addr_canonicalize(&owner)?;
}
In the rewards contract:
if let Some(owner) = owner {
config.owner = deps.api.addr_canonicalize(&owner)?;
}
In the token-pool contract:
if let Some(owner) = owner {
config.owner = deps.api.addr_canonicalize(&owner)?;
}
SOLVED: The issue was fixed in commit 79549c38936e99a89a1fa7aa7e38456032f47389.
// Informational
The rewards contract has a spend_limit
attribute that caps the maximum amount a distributor can spend in a transaction. However, the amount of each distribution message is verified separately instead of checking that the global amount spent is less than the spending limit. That allows a distributor to bypass the restriction in a transaction.
Users who interact with the distribute
function must be whitelisted first. Therefore, the likelihood of such a scenario is low.
let mut msgs: Vec<CosmosMsg> = vec![];
for distribution in distributions {
if config.spend_limit < distribution.amount {
return Err(ContractError::SpendLimitReached {});
}
msgs.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: bro_token.clone(),
funds: vec![],
msg: to_binary(&Cw20ExecuteMsg::Send {
contract: distribution.contract,
amount: distribution.amount,
msg: distribution.msg,
})?,
SOLVED: The issue was fixed in commit a9856345f269ca5275236297feae192d1ee4cec4.
// Informational
When updating the epoch manager status, the owner can set the following attributes:
epochs
(number of blocks in an epoch)blocks_per_year
bbro_emission_rate
The absence of validation allows the variables to be set to 0, inducing malfunction in the contracts by querying the epoch-manager: staking-v1 and distributor-v1. For example, epochs
with a value of 0 will cause a 0-unverified division in the distributor-v1 contract, and a 0-verified division in the staking-v1 contract, causing transactions to go into panic.
However, only an administrator can update these values. Therefore, the likelihood is limited.
Absence of validation when updating the state value in epoch-manager
:
let mut state = load_state(deps.storage)?;
if let Some(epoch) = epoch {
state.epoch = epoch;
}
if let Some(blocks_per_year) = blocks_per_year {
state.blocks_per_year = blocks_per_year;
}
if let Some(bbro_emission_rate) = bbro_emission_rate {
state.bbro_emission_rate = bbro_emission_rate;
}
store_state(deps.storage, &state)?;
\color{black}\color{white}In staking-v1, when calling compute_normal_bbro_reward
:
let epoch_info = query_epoch_info(querier, epoch_manager_contract)?;
let epochs_staked = Uint128::from(state.last_distribution_block - self.last_balance_update)
.checked_div(Uint128::from(epoch_info.epoch))?;
\color{black}\color{white}In distributor, when calling distribute
:
// query epoch from epoch_manager contract
let epoch_blocks = query_epoch_info(
&deps.querier,
deps.api.addr_humanize(&config.epoch_manager_contract)?,
)?
.epoch;
// distribute rewards only for passed epochs
let blocks_since_last_distribution = env.block.height - state.last_distribution_block;
let passed_epochs = blocks_since_last_distribution / epoch_blocks;
if passed_epochs == 0 {
return Err(ContractError::NoRewards {});
}
SOLVED: The issue was fixed in commit 1c7ab7d56ae6ad16c88d8fdfeddb4e3e8e571f85.
Halborn used automated security scanners to assist with detection of well-known security issues and vulnerabilities. Among the tools used was cargo audit
, a security scanner for vulnerabilities reported to the RustSec Advisory Database. All vulnerabilities published in https://crates.io
are stored in a repository named The RustSec Advisory Database. cargo audit
is a human-readable version of the advisory database which performs a scanning on Cargo.lock. Security Detections are only in scope. All vulnerabilities shown here were already disclosed in the above report. However, to better assist the developers maintaining this code, the auditors are including the output with the dependencies tree, and this is included in the cargo audit output to better know the dependencies affected by unmaintained and vulnerable crates.
\begin{center} \begin{tabular}{|l|p{3.5cm}|p{6.5cm}|} \hline \textbf{ID} & \textbf{package} & \textbf{Short Description} \ \hline \href{https://rustsec.org/advisories/RUSTSEC-2020-0025}{RUSTSEC-2020-0025} & bigint & bigint is unmaintained, use uint instead \ \hline \end{tabular} \end{center}
Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.
// Download the full report
* Use Google Chrome for best results
** Check "Background Graphics" in the print settings if needed