Skip to content
Business logic Audit finding Beginner

Incorrect event parameter in inboundtransferratelimited emits recipient instead of caller

The NttRateLimiter contract emits an InboundTransferRateLimited event whose sender field is filled with the recipient address rather than the caller. Monitoring and analytics tools that rely on the event schema would misattribute who triggered the rate-limited inbound transfer.

yashar Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

57013 sc insight incorrect event parameter in inboundtransferratelimited emits recipient instead of caller

Description

Brief / Intro

The NttRateLimiter contract emits an InboundTransferRateLimited event when an inbound transfer is enqueued due to insufficient capacity. However, the event field labeled sender is incorrectly populated with the recipient’s address, not the caller or actual sender.

Vulnerability Details

In _enqueue_or_consume_inbound_transfer, the event is emitted as:

{% code title="NttRateLimiter.py (snippet)" %}

Python
            emit(InboundTransferRateLimited(
                recipient,
                message_digest,
                current_capacity,
                ARC4UInt64(untrimmed_amount))
            )
            return Bool(True)

{% endcode %}

while the struct defines:

{% code title="NttRateLimiter.py (struct)" %}

Python
class InboundTransferRateLimited(Struct):
    sender: Address
    message_digest: MessageDigest
    current_capacity: ARC4UInt256
    amount: ARC4UInt64

{% endcode %}

This results in a semantic mismatch: the event’s sender field actually contains the recipient address. Indexers, monitoring tools, and analytics relying on event schemas will misinterpret who triggered the action.

Impact Details

Potential confusion or incorrect accounting in monitoring and analytics pipelines.

Proof of Concept

<details> <summary>Test case to reproduce the mismatch</summary>

Add the following test case to NttRateLimiter.test.ts inside the enqueue or consume outbound transfer describe:

{% code title="NttRateLimiter.test.ts (add)" %}

TypeScript
    test("event mismatch", async () => {
      if (!client) {
        const { appClient, result } = await factory.deploy({ createParams: { sender: creator } });
        appId = result.appId;
        client = appClient;
      }

      if (!(await client.state.global.isInitialised())) {
        const APP_MIN_BALANCE_INIT = (210_300).microAlgos();
        const fundingTxn = await localnet.algorand.createTransaction.payment({
          sender: creator,
          receiver: getApplicationAddress(appId),
          amount: APP_MIN_BALANCE_INIT,
        });

        const outboundBucketId = getOutboundBucketIdBytes();
        await client
          .newGroup()
          .addTransaction(fundingTxn)
          .initialise({
            args: [admin.toString()],
            boxReferences: [
              getRoleBoxKey(new Uint8Array(16)), // DEFAULT_ADMIN_ROLE
              getAddressRolesBoxKey(new Uint8Array(16), admin.publicKey),
              getRoleBoxKey(RATE_LIMITER_MANAGER_ROLE),
              getAddressRolesBoxKey(RATE_LIMITER_MANAGER_ROLE, admin.publicKey),
              getBucketBoxKey(outboundBucketId),
            ],
          })
          .send();
      }

      const inboundBucketId = getInboundBucketIdBytes(PEER_CHAIN_ID);
      try {
        await client.getCurrentInboundCapacity({ args: [PEER_CHAIN_ID] });
      } catch {
        const APP_MIN_BALANCE_INBOUND = (55_000).microAlgos();
        const fundingTxn = await localnet.algorand.createTransaction.payment({
          sender: creator,
          receiver: getApplicationAddress(appId),
          amount: APP_MIN_BALANCE_INBOUND,
        });
        await client
          .newGroup()
          .addTransaction(fundingTxn)
          .addOutboundChain({ args: [PEER_CHAIN_ID], boxReferences: [getBucketBoxKey(inboundBucketId)] })
          .send();
      }

      const INBOUND_LIMIT_FOR_TEST = 1_000n;
      const INBOUND_DURATION_FOR_TEST = 60n;

      await client.send.setInboundRateLimit({
        sender: admin,
        args: [PEER_CHAIN_ID, INBOUND_LIMIT_FOR_TEST],
        boxReferences: [
          getRoleBoxKey(RATE_LIMITER_MANAGER_ROLE),
          getAddressRolesBoxKey(RATE_LIMITER_MANAGER_ROLE, admin.publicKey),
          getBucketBoxKey(inboundBucketId),
        ],
      });

      await client.send.setInboundRateDuration({
        sender: admin,
        args: [PEER_CHAIN_ID, INBOUND_DURATION_FOR_TEST],
        boxReferences: [
          getRoleBoxKey(RATE_LIMITER_MANAGER_ROLE),
          getAddressRolesBoxKey(RATE_LIMITER_MANAGER_ROLE, admin.publicKey),
          getBucketBoxKey(inboundBucketId),
        ],
      });

      const currentCapacity = await client.getCurrentInboundCapacity({ args: [PEER_CHAIN_ID] });
      const untrimmedAmount = currentCapacity + 1n;
      expect(await client.hasCapacity({ args: [inboundBucketId, untrimmedAmount] })).toBeFalsy();

      // Caller ≠ recipient to prove the mismatch ---
      const recipientAcct = await localnet.context.generateAccount({ initialFunds: (1).algo() });
      const recipientAddr = recipientAcct.toString();

      const trimmedAmount: TrimmedAmount = { amount: untrimmedAmount, decimals: 6 };
      const MESSAGE_DIGEST = getRandomBytes(32);

      // Fund app for the inbound queue box write
      const APP_MIN_BALANCE_ENQUEUE = (46_000).microAlgos();
      const fundingTxn2 = await localnet.algorand.createTransaction.payment({
        sender: creator,
        receiver: getApplicationAddress(appId),
        amount: APP_MIN_BALANCE_ENQUEUE,
      });

      // Enqueue (insufficient capacity)
      const res = await client
        .newGroup()
        .addTransaction(fundingTxn2)
        .enqueueOrConsumeInboundTransfer({
          sender: user, // caller (NOT the recipient)
          args: [untrimmedAmount, PEER_CHAIN_ID, trimmedAmount, recipientAddr, MESSAGE_DIGEST],
          boxReferences: [inboundBucketId, getInboundQueuedTransfersBoxKey(MESSAGE_DIGEST)],
        })
        .send();

      // It should have enqueued
      expect(res.returns).toEqual([true]);

      // first field is actually the RECIPIENT, not the caller
      const expectedWithRecipient = getEventBytes(
        "InboundTransferRateLimited(address,byte[32],uint256,uint64)",
        [recipientAddr, MESSAGE_DIGEST, currentCapacity, untrimmedAmount],
      );
      const expectedWithCaller = getEventBytes(
        "InboundTransferRateLimited(address,byte[32],uint256,uint64)",
        [user.toString(), MESSAGE_DIGEST, currentCapacity, untrimmedAmount],
      );

      // Logs are on the 2nd txn in the group (index 1) after funding
      expect(res.confirmations[1].logs![0]).toEqual(expectedWithRecipient);
      expect(res.confirmations[1].logs![0]).not.toEqual(expectedWithCaller);
    });

{% endcode %}

Run the test:

{% code title="Run test" %}

Bash
$ npm test -- -t "event mismatch" --testTimeout=50000

{% endcode %}

Expected/observed result when running the test:

</details>

References

(none provided)

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

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 emit call passes the recipient variable into the struct's first positional field, which is declared as sender, so the wrong value is logged.

Impact

The mismatch could cause confusion or incorrect accounting in monitoring and analytics pipelines; it does not by itself let an attacker steal funds or bypass the rate limit.

What the attacker needed

Access to the contract source; local test network

How it was found

  1. Deploy and initialise the rate limiter contract on a local network.
  2. Add the peer chain and set an inbound rate limit and duration.
  3. Choose a caller account that differs from the recipient account.
  4. Call enqueueOrConsumeInboundTransfer with an amount above current capacity so it is queued.
  5. Compare the emitted event bytes against the expected recipient-based and caller-based encodings.

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 smart contract can record events, which are like public log entries that other software reads. Here the log entry has a slot meant to say who sent the transfer, but the code puts the receiver's address in that slot instead. Nothing is stolen; the problem is that anyone reading the logs gets the wrong picture of who did what.

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 yashar

View all

1 more disclosed report, best first.

More from Folks Finance: Wormhole NTT on Algorand

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.