ZetaSupplyChecker calculation error
The ZetaSupplyChecker summed the amounts of all aborted cross-chain transactions without checking whether each transaction's coin type was ZETA, so non-ZETA amounts were included. This made the reported aborted amount larger than the real ZETA amount and caused the supply verification result to be wrong.
p0wd3r Follow with berndartmueller
Originally disclosed on Code4rena
Submitted by p0wd3r, also found by berndartmueller
Due to the incorrect calculation of AbortedTxAmount, the result of ZetaSupplyChecker is erroneous.
Proof of Concept
In ZetaSupplyChecker, to verify if the supply is correct, the following formula is used:
eth locked + aborted amount == zeta supply on node + zeta in transit + external supply + genesis amount
The calculation for the aborted amount is as follows:
func (zs *ZetaSupplyChecker) AbortedTxAmount() (sdkmath.Int, error) {
cctxList, err := zs.zetaClient.GetCctxByStatus(types.CctxStatus_Aborted)
if err != nil {
return sdkmath.ZeroInt(), err
}
amount := sdkmath.ZeroUint()
for _, cctx := range cctxList {
amount = amount.Add(cctx.GetCurrentOutTxParam().Amount)
}
amountInt, ok := sdkmath.NewIntFromString(amount.String())
if !ok {
return sdkmath.ZeroInt(), errors.New("error parsing amount")
}
return amountInt, nil
}
The problem arises here by directly taking cctx.GetCurrentOutTxParam().Amount, without determining whether the coinType of this cctx is ZETA.
When a revert cctx is created, outParam.coinType is set to cctx.InboundTxParams.CoinType, which can be gas or ERC20, and not necessarily ZETA.
// create new OutboundTxParams for the revert
revertTxParams := &types.OutboundTxParams{
Receiver: cctx.InboundTxParams.Sender,
ReceiverChainId: cctx.InboundTxParams.SenderChainId,
Amount: cctx.InboundTxParams.Amount,
CoinType: cctx.InboundTxParams.CoinType,
OutboundTxGasLimit: gasLimit,
}
cctx.OutboundTxParams = append(cctx.OutboundTxParams, revertTxParams)
If the revert cctx fails and turns into aborted, for example, in the following code snippet, then this non-ZETA amount will be recorded in AbortedTxAmount.
if cctx.InboundTxParams.CoinType == common.CoinType_ERC20 {
if err := k.RefundAmountOnZetaChain(ctx, cctx, cctx.InboundTxParams.Amount); err != nil {
// log the error
k.Logger(ctx).Error("failed to refund amount of aborted cctx on ZetaChain",
"error", err,
"sender", cctx.InboundTxParams.Sender,
"amount", cctx.InboundTxParams.Amount.String(),
)
}
}
cctx.CctxStatus.ChangeStatus(types.CctxStatus_Aborted, err.Error())
Therefore, the quantity returned by AbortedTxAmount is greater than the actual amount of ZETA.
Tools Used
VScode
Recommended Mitigation Steps
Ensure coinType is ZETA before recording the amount.
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
The aborted transaction amount was summed without filtering on coin type, so amounts in gas or ERC20 tokens were counted as ZETA.
Impact
The supply checker reports an incorrect aborted amount, so its supply verification result is erroneous; the text does not claim any direct loss of funds.
What the attacker needed
None
The fix
The amount should only be recorded when the coin type is ZETA.
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 supply checker is a program that adds up tokens in different places to confirm the total matches what should exist. Here it also added up failed transactions, but it forgot to check that those transactions were in the right token, so the total came out too high. The result is a wrong accounting figure, not a way to steal funds.
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.