SwingTraderManager.swingTraders() shoudn’t contain duplicate traderContract s.
The addSwingTrader function does not check that each traderContract is unique, so the same contract can be registered under multiple trader IDs. This causes functions like buyMalt and sellMalt to distribute shares incorrectly because they rely on trader balances.
hansfriese Follow with minhquanym
Originally disclosed on Code4rena
Submitted by hansfriese, also found by minhquanym
If SwingTraderManager.swingTraders() contains duplicate traderContracts, several functions like buyMalt() and sellMalt() wouldn’t work as expected as they work according to traders’ balances.
Proof of Concept
During the swing trader addition, there is no validation that each trader should have a unique traderContract.
function addSwingTrader(
uint256 traderId,
address _swingTrader, //@audit should be unique
bool active,
string calldata name
) external onlyRoleMalt(ADMIN_ROLE, "Must have admin privs") {
SwingTraderData storage trader = swingTraders[traderId];
require(traderId > 2 && trader.id == 0, "TraderId already used");
require(_swingTrader != address(0), "addr(0)");
swingTraders[traderId] = SwingTraderData({
id: traderId,
index: activeTraders.length,
traderContract: _swingTrader,
name: name,
active: active
});
activeTraders.push(traderId);
emit AddSwingTrader(traderId, name, active, _swingTrader);
}
So the same traderContract might have 2 or more traderIds.
When we check buyMalt() as an example, it distributes the ratio according to the trader balance and it wouldn’t work properly if one trader contract is counted twice and receives more shares that it can’t manage.
Similarly, other functions wouldn’t work as expected and return the wrong result.
Recommended Mitigation Steps
Recommend adding a new mapping like activeTraderContracts to check if the contract is added already or not.
Then we can check the trader contract is added only once.
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 addSwingTrader function lacks a check to ensure each traderContract address is unique before storing it.
Impact
Functions like buyMalt and sellMalt could distribute shares incorrectly, giving a duplicate trader more than it can manage, and other functions may return wrong results.
What the attacker needed
Admin role required to add traders
The fix
Add a mapping to track active trader contracts and check that a contract is added only once.
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.
A smart contract lets an admin add traders, but it doesn't check if the same trader address is added twice. If the same address is added under two different IDs, the system counts it twice when sharing out rewards or handling trades, which gives that trader more than it should get.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.