Skip to content

Conversation

@jinoosss
Copy link
Member

Descriptions

This PR adds caller verification to the SwapCallback function in the router v1 contract to enhance security and prevent unauthorized callback invocations.

Problem

The SwapCallback function, which handles token transfers during pool swaps, did not verify that it was being called from the authorized router v1 contract. This could potentially allow malicious actors to invoke the callback directly and manipulate the swap flow.

Solution

Added caller verification to ensure that only the router v1 contract can invoke the swap callback:

  1. New Assertion Function: Added assertIsRouterV1() in assert.gno to verify the caller's address matches the router v1 contract address
  2. Router V1 Address Constant: Added routerV1Addr constant in consts.gno to store the router v1 package address
  3. Caller Verification in SwapCallback:
    • Added halt state check using halt.AssertIsNotHaltedRouter()
    • Retrieve the previous realm's address using runtime.PreviousRealm().Address()
    • Verify the caller is router v1 before proceeding with the callback logic

Copy link
Member

@notJoon notJoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although I left a comment, but the changes seems good.

Copy link
Member

@dongwon8247 dongwon8247 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also confirm PreviousRealm(Address) == routerV1Addr?

@sonarqubecloud
Copy link

@jinoosss jinoosss merged commit 11097d6 into main Dec 1, 2025
161 of 166 checks passed
@jinoosss jinoosss deleted the fix-router-adds-caller-verification-when-the-swap-callback branch December 1, 2025 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants