Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyone can bypass fees in swapAndExecute using receiveFromBridge. #15

Closed
c4-bot-7 opened this issue Jan 20, 2024 · 6 comments
Closed

Anyone can bypass fees in swapAndExecute using receiveFromBridge. #15

c4-bot-7 opened this issue Jan 20, 2024 · 6 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-590 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality

Comments

@c4-bot-7
Copy link
Contributor

c4-bot-7 commented Jan 20, 2024

Lines of code

https://github.com/code-423n4/2024-01-decent/blob/main/src/UTB.sol#L311

Vulnerability details

Impact

Whenever a user wants to call swapAndExecute (which performs a swap and executes a transaction for a user in the same chain), they have to pay a fee via retrieveAndCollectFees modifier.

UTB.sol#L311C1-L319C6

    function swapAndExecute(
        SwapAndExecuteInstructions calldata instructions,
        FeeStructure calldata fees,
        bytes calldata signature
    )
        public
        payable
        retrieveAndCollectFees(fees, abi.encode(instructions, fees), signature)
    {
        _swapAndExecute(
            instructions.swapInstructions,
            instructions.target,
            instructions.paymentOperator,
            instructions.payload,
            instructions.refund
        );
    }

However there is another function that does essentially the same thing without the retrieveAndCollectFees modifier.

UTB.sol#L311C1-L319C6

    function receiveFromBridge(
        SwapInstructions memory postBridge,
        address target,
        address paymentOperator,
        bytes memory payload,
        address payable refund
    ) public {
        _swapAndExecute(postBridge, target, paymentOperator, payload, refund);
    }

Essentially, this means a user can bypass fees in swapAndExecute by using the function receiveFromBridge.

Note that though this function is not payable, _swapAndExecute also accepts ERC-20 tokens, meaning that one can abuse receiveFromBridge to swap ERC-20 tokens and execute transactions without a fee.

Tools Used

Manual Review

Recommended Mitigation Steps

The receiveFromBridge function needs to check if the msg.sender is actually a bridge adapter by using a new storage mapping that stores a boolean whether a given address is a valid bridge adapter.

Assessed type

Access Control

@c4-bot-7 c4-bot-7 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 20, 2024
c4-bot-10 added a commit that referenced this issue Jan 20, 2024
@c4-bot-10 c4-bot-10 removed the 3 (High Risk) Assets can be stolen/lost/compromised directly label Jan 20, 2024
@code4rena-admin code4rena-admin added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value edited-by-warden labels Jan 20, 2024
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Jan 23, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as sufficient quality report

@c4-pre-sort
Copy link

raymondfam marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Jan 23, 2024
@raymondfam
Copy link

raymondfam commented Jan 23, 2024

Dodging fee payment via this postBridge call is indeed a loophole.

This was referenced Jan 23, 2024
This was referenced Jan 24, 2024
@raymondfam raymondfam mentioned this issue Jan 26, 2024
@c4-sponsor
Copy link

wkantaros (sponsor) confirmed

@c4-sponsor c4-sponsor added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 30, 2024
@c4-judge c4-judge closed this as completed Feb 3, 2024
@c4-judge c4-judge added duplicate-590 and removed primary issue Highest quality submission among a set of duplicates labels Feb 3, 2024
@c4-judge
Copy link

c4-judge commented Feb 3, 2024

alex-ppg marked issue #590 as primary and marked this issue as a duplicate of 590

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 3, 2024
@c4-judge
Copy link

c4-judge commented Feb 3, 2024

alex-ppg marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-590 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

7 participants