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

Malicious user can drain PeUSDMainnetStableVision via executeFlashloan() #280

Closed
code423n4 opened this issue Jun 29, 2023 · 4 comments
Closed
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-769 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")

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jun 29, 2023

Lines of code

https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/token/PeUSDMainnetStableVision.sol#L129
https://github.com/code-423n4/2023-06-lybra/blob/main/contracts/lybra/token/PeUSDMainnetStableVision.sol#L132

Vulnerability details

Impact

Maliciuos user can use executeFlashloan() and steal all available EUSD tokens.

Proof of Concept

Here is a vulnerable function:

    function executeFlashloan(FlashBorrower receiver, uint256 eusdAmount, bytes calldata data) public payable {
        uint256 shareAmount = EUSD.getSharesByMintedEUSD(eusdAmount);
        EUSD.transferShares(address(receiver), shareAmount);
        receiver.onFlashLoan(shareAmount, data);
        bool success = EUSD.transferFrom(address(receiver), address(this), 
        EUSD.getMintedEUSDByShares(shareAmount));
        require(success, "TF");

        uint256 burnShare = getFee(shareAmount);
        EUSD.burnShares(address(receiver), burnShare);
        emit Flashloaned(receiver, eusdAmount, burnShare);
    }

It allows to pass an arbitrary bytes calldata data as one of the arguments. Later it calls receiver, that can be PeUSDMainnetStableVision contract itself, with a malicious data.

...
receiver.onFlashLoan(shareAmount, data);
...

So malicious user can pass next arguments:

executeFlashloan( PeUSDMainnetStableVision , 1, abi.encodeWithSignature("approve(address,uint256)", attacker, amount));

Step by step:

  1. Hacker pass malicious arguments;
  2. PeUSDMainnetStableVision calculates the share amount and transfer it to itself;
  3. Call an approve function in malicious data;
  4. Transfer loaned token back to itself again, calculate fee and burn it;

Right after that hacker will be approved and be able to transfer all EUSD tokens from the contract.

Sorry for no tests included. I was little bit confused with setting up all params.

P.S. The same issue was in Damn Vulnerably DeFi Challenges (Truster).

Tools Used

Manual review.

Recommended Mitigation Steps

You can provide an additional checks to prohibit calls for approve functions or receiver should not be the same as PeUSDMainnetStableVision contract.

Assessed type

Other

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jun 29, 2023
code423n4 added a commit that referenced this issue Jun 29, 2023
@c4-pre-sort
Copy link

JeffCX marked the issue as primary issue

@c4-sponsor
Copy link

LybraFinance marked the issue as 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 Jul 14, 2023
@c4-judge
Copy link
Contributor

0xean marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jul 26, 2023
@c4-judge c4-judge added duplicate-769 and removed primary issue Highest quality submission among a set of duplicates labels Jul 28, 2023
@c4-judge
Copy link
Contributor

0xean marked issue #769 as primary and marked this issue as a duplicate of 769

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-769 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")
Projects
None yet
Development

No branches or pull requests

4 participants