Redundant code in dexaggregatorwrapperwithpredicateproxy impairs readability and potentially increases gas costs
The report identifies redundant code in the depositOneInch function of DexAggregatorWrapperWithPredicateProxy, where the vault address is validated three times and shares are recalculated unnecessarily. This redundancy increases gas costs and reduces readability, potentially introducing errors.
- Disclosed after under an hour
50677 sc insight redundant code in dexaggregatorwrapperwithpredicateproxy impairs readability and potentially increases gas costs
Submitted on Jul 27th 2025 at 12:14:16 UTC by @KKam86 for Attackathon | Plume Network
- Report ID: #50677
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol
- Impacts: (see details below)
Description
Brief/Intro
One of the functions in DexAggregatorWrapperWithPredicateProxy - depositOneInch has redundant code which unnecessarily complicates function logic. Redundant code impairs readability, produces additional gas costs or even can introduce new errors in contract logic.
Vulnerability Details
{% stepper %} {% step %}
Redundant vault address validation (multiple checks)
Function depositOneInch validates vaultAddress three separate times:
- First time inside call to
_oneInchHelper:
uint256 supportedAssetAmount = _oneInchHelper(
supportedAsset,
address(teller),
executor,
desc,
data,
nativeValueToWrap
);
Inside _oneInchHelper before approving assets to vaultAddress:
address vaultAddress = address(
TellerWithMultiAssetSupport(payable(teller)).vault()
);
if (vaultAddress == address(0)) {
revert("DexAggregatorWrapper: Invalid vault address for approval");
}
supportedAsset.safeApprove(vaultAddress, supportedAssetAmount);
- Second check immediately in
depositOneInchafter calling_oneInchHelperand beforedeposit:
address vaultAddress = address(teller.vault());
if (vaultAddress == address(0)) {
// Handle error: Vault address cannot be zero if we need to transfer shares
revert("DexAggregatorWrapper: Invalid vault address");
}
- Third check at the end of
depositOneInchinside_calcSharesAndEmitEventcall path:
_calcSharesAndEmitEvent(
supportedAsset,
CrossChainTellerBase(address(teller)),
address(desc.srcToken),
desc.amount,
supportedAssetAmount
);
And inside _calcSharesAndEmitEvent it again obtains and checks the vault address:
// Get vault address
address vaultAddress = address(teller.vault());
if (vaultAddress == address(0)) {
revert("DexAggregatorWrapper: Invalid vault address");
}
These repeated checks for the same invariant are redundant and increase code complexity and gas usage. {% endstep %}
{% step %}
Unnecessary shares recalculation in _calcSharesAndEmitEvent
The call to _calcSharesAndEmitEvent in depositOneInch recomputes shares solely to emit a Deposit event, but teller.deposit already returns the shares calculated using the same logic.
Example in depositOneInch:
shares = teller.deposit(
supportedAsset,
supportedAssetAmount,
minimumMint
);
In TellerWithMultiAssetSupport.sol the deposit function returns shares via internal _erc20Deposit:
function deposit(
ERC20 depositAsset,
uint256 depositAmount,
uint256 minimumMint
) external requiresAuth nonReentrant returns (uint256 shares)
And _erc20Deposit calculates shares as:
shares = depositAmount.mulDivDown(
ONE_SHARE,
accountant.getRateInQuoteSafe(depositAsset)
);
Where ONE_SHARE and accountant are initialized in TellerWithMultiAssetSupport constructor.
Meanwhile, shares calculation inside _calcSharesAndEmitEvent duplicates the same computation:
uint256 shares = supportedAssetAmount.mulDivDown(
10 ** teller.vault().decimals(),
AccountantWithRateProviders(teller.accountant()).getRateInQuoteSafe(
supportedAsset
)
);
This redundant recalculation is unnecessary since the shares were already computed and returned by teller.deposit.
{% endstep %}
{% endstepper %}
Impact Details
- Increased gas costs — redundant operations consume additional gas which the user must pay for.
- Reduced readability — redundant and repeated checks make the code harder to reason about, maintain, and audit, increasing risk of errors.
References
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L100
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L275-L278
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L106-L110
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L114-L120
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L397-L400
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol?utm\\_source=immunefi#L103
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/base/Roles/TellerWithMultiAssetSupport.sol#L353
- https://github.com/immunefi-team/attackathon-plume-network-nucleus-boring-vault/blob/main/src/helper/DexAggregatorWrapperWithPredicateProxy.sol#L401-L404
Proof of Concept
(Empty)
Proof of Concept
(Empty)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code performs redundant validation and recalculation instead of reusing results from earlier calls.
Impact
The redundant operations could increase gas costs for users and reduce code readability, potentially leading to errors.
What the attacker needed
None
The fix
The code should be refactored to remove redundant checks and reuse the shares returned by teller.deposit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This report points out that a smart contract function repeats the same checks and calculations multiple times. While not a security vulnerability, this wastes gas (transaction fees) and makes the code harder to understand and maintain.