In _handleDeposit() of Trading.sol, when _tigAsset != _marginAsset and _permitData.usePermit == true, _marginAsset, an allowed token, is deposited into deposit() of StableVault.sol in exchange for tigAsset tokens. A check is done to ensure an exact amount of _margin has been added to the tigAsset balance of Trading.sol. However, the burnFrom amount is tigAsset.balanceOf(address(this)) instead of _margin. This could drastically lead to an accounting error.
As can be seen from the code block above, tigAsset.balanceOf(address(this)) on line 655 is very much larger than _margin on line 657. The contract balance of tigAssert is practically burned each time the first three if blocks of the function logic return true consecutively.
Tools Used
Manual inspection
Recommended Mitigation Steps
Consider refactoring the affected code line as follows:
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L655
Vulnerability details
Impact
In _handleDeposit() of Trading.sol, when
_tigAsset != _marginAsset
and_permitData.usePermit == true
,_marginAsset
, an allowed token, is deposited into deposit() of StableVault.sol in exchange fortigAsset
tokens. A check is done to ensure an exact amount of_margin
has been added to thetigAsset balance
of Trading.sol. However, the burnFrom amount istigAsset.balanceOf(address(this))
instead of_margin
. This could drastically lead to an accounting error.Proof of Concept
File: Trading.sol#L643-L659
As can be seen from the code block above,
tigAsset.balanceOf(address(this))
on line 655 is very much larger than_margin
on line 657. The contract balance of tigAssert is practically burned each time the first three if blocks of the function logic return true consecutively.Tools Used
Manual inspection
Recommended Mitigation Steps
Consider refactoring the affected code line as follows: