IOP _ ThunderNFT 34975 - [Smart Contract - Low] Read out of index

Submitted on Mon Sep 02 2024 03:56:37 GMT-0400 (Atlantic Standard Time) by @jasonxiale for IOP | ThunderNFT

Report ID: #34975

Report type: Smart Contract

Report severity: Low

Target: https://github.com/ThunderFuel/smart-contracts/tree/main/contracts-v1/asset_manager

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

In asset_manager.get_supported_asset and execution_manager.get_whitelisted_strategy, there is a out-of-index read issue.

Vulnerability Details

In asset_manager.get_supported_asset, the function checks index <= storage.assets.len, which is incorrect, because the index starts from 0.

 74     #[storage(read)]
 75     fn get_supported_asset(index: u64) -> Option<AssetId> {
 76         let len = storage.assets.len();
 77         require(len != 0, AssetManagerErrors::ZeroLengthVec);
 78         require(index <= len, AssetManagerErrors::IndexOutOfBound); <<<--- Here is not correct
 79 
 80         storage.assets.get(index).unwrap().try_read()
 81     }

Same issue happens in execution_manager.get_whitelisted_strategy:

Impact Details

function read out-of-index, and tx will revert with unexpected message

References

Add any relevant links to documentation or code

Proof of concept

Proof of Concept

Please generate a Rust test template under thunder_exchange folder, and puts the following code in thunder_exchange/tests/harness.rs and run cargo test -- --nocapture

As the code shows above, the tx is reverted

Last updated

Was this helpful?