TempleGold

TempleDAO
Foundry
25,000 USDC
View results
Submission Details
Severity: low
Valid

`quote()` view function in `TempleTeleporter` contract return wrong value

Summary

quote() view function in TempleTeleporter contract return wrong value

Vulnerability Details

In TempleTeleporter contract, quote() function returns amount of native token and lz token required to send crosschain message. It serves the purpose as an API to get the required native token amount to later call to teleport() function

https://github.com/Cyfrin/2024-07-templegold/blob/57a3e597e9199f9e9e0c26aab2123332eb19cc28/protocol/contracts/templegold/TempleTeleporter.sol#L87-L94

function quote(
uint32 _dstEid,
address _to,
uint256 _amount,
bytes memory _options
) external view returns (MessagingFee memory fee) {
return _quote(_dstEid, abi.encodePacked(_to, _amount), _options, false);
}

Notice here that the message to get quote is abi.encodePacked(_to, _amount), but in teleport(), the message sent is abi.encodePacked(to.addressToBytes32(), amount)
https://github.com/Cyfrin/2024-07-templegold/blob/57a3e597e9199f9e9e0c26aab2123332eb19cc28/protocol/contracts/templegold/TempleTeleporter.sol#L52

Impact

The message in quote() is shorter than the message in teleport(), which means the quote fetched will likely not enough to cover the fee for teleport(), which make function reverted

L0's docs: https://docs.layerzero.network/v2/developers/evm/oapp/overview#estimating-gas-fees

Make sure that the arguments passed into the quote() function identically match the parameters used in the lzSend() function. If parameters mismatch, you may run into errors as your msg.value will not match the actual gas quote.

Tools Used

Manual Review

Recommendations

function quote(
uint32 _dstEid,
address _to,
uint256 _amount,
bytes memory _options
) external view returns (MessagingFee memory fee) {
- return _quote(_dstEid, abi.encodePacked(_to, _amount), _options, false);
+ return _quote(_dstEid, abi.encodePacked(_to.addressToBytes32(), _amount), _options, false);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Incorrect payload bytes in `quote()` they use `abi.encodePacked(_to, _amount)` instead of `abi.encodePacked(_to.addressToBytes32(), _amount)`

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.