transferNotionalFrom doesn’t check from != to
The transferNotionalFrom function in VaultTracker.sol uses temporary variables to store balances, and if the from and to addresses are the same, the balance of from is overwritten by the balance of to, increasing both balances without decreasing any, effectively creating money. An attacker could call this function via transferVaultNotional to inflate their balance.
Submitted by gpersoon, also found by cmichel.
Impact
The function transferNotionalFrom of VaultTracker.sol uses temporary variables to store the balances. If the “from” and “to” address are the same then the balance of “from” is overwritten by the balance of “to”. This means the balance of “from” and “to” are increased and no balances are decreased, effectively printing money.
Note: transferNotionalFrom can be called via transferVaultNotional by everyone.
Proof of Concept
https://github.com/Swivel-Finance/gost/blob/v2/test/vaulttracker/VaultTracker.sol#L144-L196
function transferNotionalFrom(address f, address t, uint256 a) external onlyAdmin(admin) returns (bool) {
Vault memory from = vaults\[f];
Vault memory to = vaults\[t];
...
vaults\[f] = from;
...
vaults\[t] = to; // if f==t then this will overwrite vaults\[f]
https://github.com/Swivel-Finance/gost/blob/v2/test/marketplace/MarketPlace.sol#L234-L238
function transferVaultNotional(address u, uint256 m, address t, uint256 a) public returns (bool) {
require(VaultTracker(markets\[u]\[m].vaultAddr).transferNotionalFrom(msg.sender, t, a), 'vault transfer failed');
Tools Used
Recommended Mitigation Steps
Add something like the following: require (f != t,"Same");
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 function does not validate that the from and to addresses are distinct, causing the assignment to the same storage slot to overwrite the decreased balance with the increased one.
Impact
An attacker could increase their balance without decreasing any other balance, effectively creating money, and this can be triggered by anyone through transferVaultNotional.
What the attacker needed
None
The fix
The function should be fixed by adding a check that the from and to addresses are not the same, for example with a require statement.
How it was found
- Call transferVaultNotional with the same address for the sender and receiver.
- The call invokes transferNotionalFrom with from and to equal.
- The function loads both balances into temporary variables, modifies them, and writes them back to the same storage slot, resulting in an increased balance without a corresponding decrease.
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 is a smart contract bug where a function that moves balances between two accounts fails to check that the sender and receiver are different. If they are the same, the code accidentally adds the balance to itself instead of subtracting from one and adding to the other, so the total money increases out of thin air. Anyone can trigger this through another public function, letting them create free balance.
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.