Perps - GTL post-only orders skew totalAssets accounting, minting excessive shares and rendering the GTL vault insolvent
When the GTL vault places a post-only limit order on a new subaccount, the subaccount is not added to the vault's internal accounting until the order fills, so totalAssets omits the posted collateral. Deposits made during that window mint inflated shares, diluting existing depositors and potentially making the vault insolvent.
Submitted by lodelux
perps/types/ClearingHouse.sol #L108-L144
When the GTL vault places the first post-only limit order for a subaccount, ClearingHouse::placeOrder returns early without setting the new subaccount in the internal accounting of GTL. This causes GTL::totalAssets to NOT account for the posted collateral on the orderBook for that specific subaccount meaning that mintedShares = depositedAssets / totalAssets are inflated, making the vault insolvent.
Finding description
The GTL vault acts as a ERC4626 compliant liquidity pool where users can deposit USDC in exchange for shares of the pool. The protocol then uses funds to place orders on the perp book and user’s shares represent their portion of the NAV controlled by the vault.
Specifically, when a user calls GTL::deposit with assets, he receives shares = assets / (totalAssets() + 1 ) * (totalSupply() + 1) where totalAssets is:
function totalAssets() public view override returns (uint256) {
return usdc.balanceOf(address(this)) + orderbookCollateral() + freeCollateralBalance() + totalAccountValue();
}
function orderbookCollateral() public view returns (uint256 collateral) {
uint256[] memory subaccounts = _subaccounts.values();
@> for (uint256 i; i < subaccounts.length; ++i) {
collateral += IViewPort(perpManager).getOrderbookCollateral(address(this), subaccounts[i]);
}
}
Notice that the posted orderBook collateral is accounted only for the locally stored subaccounts.
These subaccounts are added via GTL:addSubaccount which is an onlyPerpManager function, and it’s called inside ClearingHouse:setAssets:
function setAssets(
ClearingHouse storage self,
address account,
uint256 subaccount,
uint256 newLength,
bytes32 asset
) internal {
uint256 oldLength = self.assets[account][subaccount].length();
if (oldLength == newLength) return;
if (oldLength < newLength) self.assets[account][subaccount].add(asset);
else self.assets[account][subaccount].remove(asset);
if (account == Constants.GTL) {
@> if (oldLength == 0) IGTL(Constants.GTL).addSubaccount(subaccount);
else if (newLength == 0) IGTL(Constants.GTL).removeSubaccount(subaccount);
}
}
More specifically, they are added whenever an order is filled on a new subaccount (as before assets for that subaccount in perpManager was empty) as this function is called by ClearingHouse::updateAccount which is itself called only in either _processTakerFill or _processMakerFill. When the GTL admin places a post-only order, this fn handles it:
function placeOrder(ClearingHouse storage self, address account, PlaceOrderArgs calldata args, BookType bookType)
internal
returns (PlaceOrderResult memory orderResult)
{
Market storage market = self.market[args.asset];
orderResult = market.placeOrder(account, args, bookType);
uint256 collateralPosted;
if (orderResult.basePosted > 0 && !args.reduceOnly) {
collateralPosted = _getCollateral(
orderResult.basePosted, args.limitPrice, market.getPositionLeverage(account, args.subaccount)
);
}
@> if (orderResult.baseTraded == 0) {
StorageLib.loadCollateralManager().handleCollateralDelta({
account: account,
collateralDelta: collateralPosted.toInt256()
});
return orderResult;
}
_processTakerFill(
self,
__FillParams__({
asset: args.asset,
account: account,
subaccount: args.subaccount,
side: args.side,
quoteAmount: orderResult.quoteTraded,
baseAmount: orderResult.baseTraded,
collateralPosted: collateralPosted
})
);
}
As you can see if baseTraded == 0, meaning that the order is a post-only, _processTakerFill is never executed.
What this means is whenever the GTL admin places an order on a new subaccount which doesn’t immediately fill, this subaccount is not added to the GTL _subaccounts set even though collateral was indeed posted from GTL to the book, causing now the totalAssets call to not return this collateral in the calculations. This subaccount is lastly added once the order is filled and processMakerOrder is called.
Impact
This means that, for deposits that happen while this subaccount is not added but the collateral is moved from GTL to the book, the shares minted are inflated, giving much more USDC to these depositors than they should be entitled to. Effectively wrongly transferring USDC from some depositors to others.
View detailed Proof of Concept
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 vault only adds a subaccount to its internal list when an order fills, so collateral posted for an unfilled post-only order is excluded from totalAssets until the fill occurs.
Impact
Depositors during the window receive inflated shares, wrongly transferring USDC from other depositors and potentially rendering the vault insolvent.
What the attacker needed
GTL admin places a post-only order on a new subaccount; order does not immediately fill; a user deposits while the subaccount is unaccounted
The fix
The vault should add the subaccount to its internal accounting as soon as collateral is posted, not only when an order fills.
How it was found
- The GTL admin places a post-only limit order on a new subaccount that does not immediately fill.
- The order posts collateral from the GTL vault to the order book, but the subaccount is not added to the vault's internal subaccount list.
- A user deposits into the GTL vault while the subaccount is missing from the list.
- The vault calculates totalAssets without the posted collateral, so the deposit mints more shares than it should.
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 vault lets people deposit money and gives them shares representing their portion of the vault's total value. The vault also places orders on a trading platform, which locks up some of its money as collateral. The bug is that the vault temporarily forgets to count that locked money when calculating its total value, so new depositors get too many shares for their deposit, taking value from existing depositors.
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.