When transferring Temple gold cross-chain some amount is lost due to precision not being set.
The Temple Gold token is non-transferable by design, but users are able to move it to different chains to their own wallets on the other chain. Layer Zero's OFT (Omnichain Fungible Token) is used to accomplish this. It is done by burning the tokens on the current chain and minting them on the target chain. The TempleGold::send
function is used to do this
The _debit()
function burns the tokens on the current chain and _lzSend()
send a message to the Lz router to mint tokens on the destination chain.
As can be seen in the above code snippet the _debit()
function returns the amount to be send and the amount that would be received in amountSentLD
and amountReceivedLD
. The reason for this is that depending on how OFT
is configured by the contract integrating it these two amount may differ due to cutting of some amount to send which is lost.
Looking in the _debit()
function it calls _debitView
_debitView
in it self calls _removeDust
_removeDust
cuts some decimals of the amount to send.
This results in loss of funds, due to less tokens being minted on the destination chain. The decimalConversionRate
by default 6 - a more detailed example can be seen in the LZ docs here: https://docs.layerzero.network/v2/developers/evm/oft/quickstart#example
This can be fixed by overriding OFT's sharedDecimals
option and setting it to the number of decimals the token has which is 18: https://docs.layerzero.network/v2/developers/evm/oft/quickstart#optional-overriding-shareddecimals
This way the decimalConversionRate
would become 1 and no precision would be lost during transfer.
decimalConversionRate = 10^(localDecimals − sharedDecimals) = 10^(18−18) = 10^0 = 1
and in _removeDust (_amountLD / decimalConversionRate) * decimalConversionRate
would be amountLD
or in other words amount send.
Loss of some amount of TGLD
Manual Review, LZ Docs
In TempleGold
override the following function
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.