Platform: Code4rena
Start Date: 24/02/2022
Pot Size: $170,000 UST
Total HM: 15
Participants: 16
Period: 14 days
Judge: Albert Chon
Total Solo HM: 11
Id: 82
League: COSMOS
Rank: 6/16
Findings: 4
Award: $7,905.18
π Selected for report: 1
π Solo Findings: 1
π Selected for report: WatchPug
Also found by: BondiPestControl, broccoli, defsec
During the code review, It has been observed that the whitelisted token check is commented out. That will cause to user fund lost on the bridge. The related function only should allow white-listed tokens.
function handleStableToken( address token, uint256 amount, uint8 opCode ) internal { // Check that `token` is a whitelisted stablecoin token. // require(whitelistedStableTokens[token]); handleToken(token, amount, opCode); }
Code review
Ensure that the whitelist check has been enabled on the related code section. Even if the user is going to lose funds, the bridge smart contract should be ensure that the token is white-listed.
#0 - GalloDaSballo
2022-08-04T23:36:05Z
Dup of #44
π Selected for report: defsec
During the code review, It has been observed that reward calculation has been done with execute_epoch_operations function. However, the config are stored in the storage. When the anc_purchase_factor is updated by the owner, the execute_epoch_operations is not called.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/overseer/src/contract.rs#L192
if let Some(threshold_deposit_rate) = threshold_deposit_rate { config.threshold_deposit_rate = threshold_deposit_rate; } if let Some(buffer_distribution_factor) = buffer_distribution_factor { config.buffer_distribution_factor = buffer_distribution_factor; } if let Some(anc_purchase_factor) = anc_purchase_factor { config.anc_purchase_factor = anc_purchase_factor; } if let Some(target_deposit_rate) = target_deposit_rate { config.target_deposit_rate = target_deposit_rate; } if let Some(epoch_period) = epoch_period { config.epoch_period = epoch_period; } if let Some(price_timeframe) = price_timeframe { config.price_timeframe = price_timeframe; }
Code Review
Consider calling execute_epoch_operations function after config update.
#0 - GalloDaSballo
2022-08-07T14:25:11Z
Confirmed Lack of validation
#1 - albertchon
2022-09-19T23:18:00Z
Good catch
On several locations in the code precautions are taken not to divide by 0, because this will revert the code. However on some locations this isnβt done.
Oracle price is not checked. That will cause to revert on the several functions.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/oracle/src/contract.rs#L172
None
Recommend making sure division by 0 wonβt occur by checking the variables beforehand and handling this edge case.
Transmitted coins are filtered by the configured stable denomination in multiple places across the codebase, however any other coins sent are not returned to the sender. That leaves those other coins frozen to the contract.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-bAsset-contracts/contracts/anchor_basset_hub/src/contract.rs#L43 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-bAsset-contracts/contracts/anchor_basset_hub/src/bond.rs#L41
None
Consider returning unused coins or reverting the transaction if unexpected coins are sent.
The Overseer contract is responsible for storing key protocol parameters and the whitelisting of new bAsset collaterals. The Overseer keeps track of locked collateral amounts and calculates the borrow limits for each user. The initialize function does not have any sanity check in the smart contract variables.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/overseer/src/contract.rs#L46
None
The protocol considers to the variable is between 0 and 1. However, the sanity checks are not implemented. That will cause to arithmetic errors.
Missing checks for zero-addresses may lead to broken functionality in the protocol, if the variable addresses are updated incorrectly.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/cross-chain-contracts/ethereum/CrossAnchorBridge.sol#L152
Code Review
Consider adding zero-address checks in the discussed constructors: require(newAddr != address(0));.
The Oracle contract acts as the price source for the Anchor Money Market. Price sources are gaven as a resource with the feeders. With the register_feeder function, the existing feeder will be overwritten. Therefore, the code does not check existing feeder.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/oracle/src/contract.rs#L76
Code Review
Consider checking the existing feeder.
The Overseer contract is responsible for storing key protocol parameters and the whitelisting of new bAsset collaterals. The Overseer keeps track of locked collateral amounts and calculates the borrow limits for each user.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/overseer/src/contract.rs#L245
Code Review
Consider to trim and validate all String parameters before the state.
The owner is the authorized user in the cosmwasm contracts. Usually, an owner can be updated with update_config function. However, the process is only completed with single transaction. If the address is updated incorrectly, an owner functionality will be lost forever.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/oracle/src/contract.rs#L58 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/money-market-contracts/contracts/distribution_model/src/contract.rs#L79
Code Review
Lack of two-step procedure for critical operations leaves them error-prone. Consider adding two step procedure on the critical functions.
#0 - GalloDaSballo
2022-08-04T23:37:34Z
Whitelist, same as #44
Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks are available for free.
The advantages of versions 0.8.* over <0.8.0 are:
All Contracts
None
Consider to upgrade pragma to at least 0.8.4.
++i is more gas efficient than i++ in loops forwarding.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/cross-chain-contracts/ethereum/CrossAnchorBridge.sol#L149
Code Review
It is recommend to use unchecked{++i} and change i declaration to uint256.
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/cross-chain-contracts/ethereum/CrossAnchorBridge.sol#L149
None
Consider to cache array length.
The several code sections are redundant. The variable/structs should be deleted for the gas optimization if It is not used.
https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/cross-chain-contracts/ethereum/CrossAnchorBridge.sol#L19 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/cross-chain-contracts/ethereum/CrossAnchorBridge.sol#L26
None
Consider removing the unused function/structs which is not used.
#0 - GalloDaSballo
2022-08-04T23:46:04Z
Seems like it would save less than 100 gas Also doesn't cover any rust contract