Skip to content
Business logic Audit finding Intermediate

Native gas tokens can become stuck in ASDRouter contract

The ASDRouter contract does not refund excess native gas tokens (CANTO) sent with a transaction when an asD redemption succeeds, leaving the surplus stuck in the contract. An attacker could deliberately send extra value to cause funds to be permanently locked, violating the protocol's invariant that the router's native balance should always be zero.

0xTheC0der Follow with SpicyMeatball and oakcobalt

Originally disclosed on Code4rena

Submitted by 0xTheC0der, also found by SpicyMeatball and oakcobalt

In case of a successful asD redemption flow, native gas tokens (CANTO) can become stuck in the ASDRouter contract.

A successful execution of lzCompose(…) ends with a call to _sendASD(…):

function _sendASD(bytes32 _guid, OftComposeMessage memory _payload, uint _amount) internal {
    /* transfer the ASD tokens to the destination receiver */
    if (_payload._dstLzEid == cantoLzEID) {
        // just transfer the ASD tokens to the destination receiver
        ...
        ASDOFT(_payload._cantoAsdAddress).transfer(_payload._dstReceiver, _amount);   // @audit 0 of msg.value used
    } else {
        // use Layer Zero oapp to send ASD tokens to the destination receiver on the destination chain

        // make sure msg.value is enough to cover the fee or this transaction will revert
        if (msg.value < _payload._feeForSend) {   // @audit msg.value >= _payload._feeForSend seems intended, otherwise != should be used
            // refund ASD tokens on canto
            _refundToken(_guid, _payload._cantoAsdAddress, _payload._cantoRefundAddress, _amount, msg.value, "insufficient msg.value for send fee");
            return;
        }

        // create send params for the Layer Zero oapp
        ...

        // send tokens
        (bool successfulSend, bytes memory data) = payable(_payload._cantoAsdAddress).call{value: _payload._feeForSend}(abi.encodeWithSelector(IOFT.send.selector, sendParams, fee, _payload._cantoRefundAddress));   // @audit only _payload._feeForSend of msg.value used

        // check if the send was successful
        if (!successfulSend) {
            // refund ASD tokens on canto
            _refundToken(_guid, _payload._cantoAsdAddress, _payload._cantoRefundAddress, _amount, msg.value, string(data));
            return;
        }
        ...
    }
    // @audit rest of msg.value is not refunded
}

Thereby, one can distinguish 3 scenarios:

  1. On error: msg.value is fully refunded to specified refund address.
  2. On successful transfer (within Canto chain): 0 of msg.value is used and any remaining value will be stuck.

One cannot assume and the contract doesn’t require that msg.value == 0 always holds in this case.

  1. On successful transfer (to other chain): _payload._feeForSend of msg.value is used for sending asD, the remaining value will be stuck.

One cannot assume and the contract doesn’t require that msg.value == _payload._feeForSend always holds in this case.

Furthermore, the present behaviour violates a protocol invariant, according to the README:

  1. ASDRouter native balance should always be zero.

Proof of Concept

The diff below modifies the existing test case lzCompose: successful deposit and send on canto to demonstrate that excess msg.value is not refunded in case of a successful asD redemption flow.

diff --git a/test/ASDRouter.js b/test/ASDRouter.js
index 2a36337..eccedc0 100644
--- a/test/ASDRouter.js
+++ b/test/ASDRouter.js
@@ -276,6 +276,7 @@ describe("ASDRouter", function () {
     it("lzCompose: successful deposit and send on canto", async () => {
         // update whitelist
         await ASDUSDC.updateWhitelist(USDCOFT.target, true);
+        const gas = ethers.parseEther("1");
         // call lzCompose with valid payload
         await expect(
             ASDRouter.lzCompose(
@@ -287,12 +288,18 @@ describe("ASDRouter", function () {
                     generatedRouterPayload(cantoLzEndpoint.id, refundAddress, TESTASD.target, TESTASD.target, "0", refundAddress, "0")
                 ),
                 executorAddress,
-                "0x"
+                "0x",
+                { value: gas }
             )
         )
             .to.emit(ASDRouter, "ASDSent")
             .withArgs(guid, refundAddress, TESTASD.target, amountUSDCSent, cantoLzEndpoint.id, false);
         // expect ASD to be sent to canto
         expect(await TESTASD.balanceOf(refundAddress)).to.equal(amountUSDCSent);
+
+        // expect gas to be refunded and not held in ASDRouter
+        expect(await ethers.provider.getBalance(ASDRouter.target)).to.equal(0);
+        expect(await ethers.provider.getBalance(refundAddress)).to.equal(gas);
+
     });
 });

Recommended Mitigation Steps

Apply the following changes to the _sendASD(…) method in order to refund the remaining value (i.e. the native contract balance).

diff --git a/contracts/asd/asdRouter.sol b/contracts/asd/asdRouter.sol
index 7cb4ecc..37786e1 100644
--- a/contracts/asd/asdRouter.sol
+++ b/contracts/asd/asdRouter.sol
@@ -164,6 +164,10 @@ contract ASDRouter is IOAppComposer, Ownable {
             }
             emit ASDSent(_guid, _payload._dstReceiver, _payload._cantoAsdAddress, _amount, _payload._dstLzEid, true);
         }
+
+        if (address(this).balance > 0) {
+            payable(_payload._cantoRefundAddress).transfer(address(this).balance);
+        }
     }

     /**

Note: Using transfer might not be an ideal choice, but this proposed solution in meant to be in analogy with the _refundToken(...) method.

Assessed type

ETH-Transfer

3docSec (judge) commented:

Looks valid. The difference between msg.value and _payload._feeForSend is indeed not refunded to _payload._cantoRefundAddress as one would expect.

dsudit01 (Canto) confirmed

3docSec (judge) increased severity to High and commented:

Upgrading to High as if I am not mistaken, there is no viable way to safely recover the native tokens stuck in the contract.

SpicyMeatball (warden) commented:

@3docSec - it is true that there is no way to recover ETH from the router once the transaction succeeds, but I think it should be viewed as a user’s mistake and QA is more appropriate. The report describes two cases in which ETH can stuck:

  1. On successful transfer (within Canto chain) - there is no need for the user to send a non-zero msg.value in this case.
  2. On successful transfer (to other chain) - since _feeForSend is known beforehand, sending msg.value > _feeForSend can be considered a mistake on user’s side.

3docSec (judge) commented:

On successful transfer (within Canto chain).

Agree, Low impact there.

sending msg.value > _feeForSend can be considered a mistake on user’s side.

The logic is protected against excess tokens and has a refundAddress for this purpose. The fact that refunds cover only full refunds and not partial ones is not one a user could reasonably expect.


The original report as published on Code4rena, by 0xTheC0der. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 contract fails to refund any excess native tokens (msg.value) beyond the required fee after a successful redemption, leaving them trapped in the contract.

Impact

Excess native tokens become permanently stuck in the contract, and there is no viable way to recover them, potentially leading to loss of funds for users or attackers who send more than the required fee.

What the attacker needed

Attacker can call lzCompose with a valid payload; attacker sends extra native tokens (msg.value)

How it was found

  1. Call lzCompose with a valid payload and send extra native tokens (msg.value) along with the transaction.
  2. The contract processes the redemption and sends asD tokens to the receiver.
  3. The excess native tokens remain in the ASDRouter contract instead of being refunded.

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.

When you send cryptocurrency to a smart contract, you can include extra gas money (native tokens) to pay for processing. This contract only uses part of that money and doesn't return the rest, so it gets stuck forever. An attacker could exploit this by intentionally sending too much, causing the contract to hold funds that can never be recovered.

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.

More by 0xTheC0der

View all

11 more disclosed reports, best first.

More from Canto

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.