Trader Joe v2 contest - hansfriese's results

One-stop-shop decentralized trading on Avalanche.

General Information

Platform: Code4rena

Start Date: 14/10/2022

Pot Size: $100,000 USDC

Total HM: 12

Participants: 75

Period: 9 days

Judge: GalloDaSballo

Total Solo HM: 1

Id: 171

League: ETH

Trader Joe

Findings Distribution

Researcher Performance

Rank: 11/75

Findings: 4

Award: $2,157.04

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Awards

0.3268 USDC - $0.33

Labels

bug
3 (High Risk)
satisfactory
duplicate-299

External Links

Lines of code

https://github.com/code-423n4/2022-10-traderjoe/blob/79f25d48b907f9d0379dd803fc2abc9c5f57db93/src/LBToken.sol#L190-L191

Vulnerability details

Impact

LBToken._transfer() won't work properly when _from == _to.

Users can double their balances as they want by transferring the tokens to their accounts again.

As a result, the token will be useless.

Proof of Concept

Inside the _transfer(), it uses _fromBalance and _toBalance to update the balances after the transfer.

    unchecked {
        _balances[_id][_from] = _fromBalance - _amount;
        _balances[_id][_to] = _toBalance + _amount;
    }

But it won't work properly when _from == to so users can increase their balance as they like.

I've created a test for the proof and you can copy the below code here and check the result.

    vm.prank(BOB);
    pair.setApprovalForAll(DEV, true);
    pair.safeTransferFrom(BOB, BOB, _ids[0], amounts[0]);
    assertEq(pair.balanceOf(BOB, _ids[0]), 2 * amounts[0]);

We can see the balance is doubled when BOB transfers the entire tokens to BOB again.

Tools Used

Manual Review, Foundry

We can modify this part like below.

_balances[_id][_from] -= _amount; _balances[_id][_to] += _amount;

#0 - trust1995

2022-10-23T20:43:01Z

Great find!

#1 - GalloDaSballo

2022-10-26T16:35:40Z

#2 - c4-judge

2022-11-23T18:28:28Z

GalloDaSballo marked the issue as not a duplicate

#3 - c4-judge

2022-11-23T18:28:58Z

GalloDaSballo marked the issue as duplicate of #299

#4 - Simon-Busch

2022-12-05T06:38:30Z

Marked this issue as Satisfactory as requested by @GalloDaSballo

Findings Information

🌟 Selected for report: KIntern_NA

Also found by: Jeiwan, cccz, hansfriese

Labels

bug
3 (High Risk)
satisfactory
duplicate-400

Awards

1876.8857 USDC - $1,876.89

External Links

Lines of code

https://github.com/code-423n4/2022-10-traderjoe/blob/79f25d48b907f9d0379dd803fc2abc9c5f57db93/src/LBRouter.sol#L725

Vulnerability details

Impact

It calculates the amountsIn wrongly here and the function returns the wrong result.

Proof of Concept

Currently, _getAmountsIn() calculates the amountsIn like below.

amountsIn[i - 1] = (_reserveIn * amountOut_ * 1_000) / (_reserveOut - amountOut_ * 997) + 1;

As we can see here, we should fix (_reserveOut - amountOut_ * 997) to ((_reserveOut - amountOut_) * 997).

Tools Used

Manual Review, Foundry

This line should be fixed like below.

amountsIn[i - 1] = (_reserveIn * amountOut_ * 1_000) / ((_reserveOut - amountOut_) * 997) + 1;

#0 - Shungy

2022-10-25T05:12:32Z

I believe this finding to be valid.

The math error do indeed exist. But this finding has skipped the impact of this issue. Will it simply cause revert? Will it result in loss of funds?

This duplicate goes more into detail: https://github.com/code-423n4/2022-10-traderjoe-findings/issues/400

#1 - GalloDaSballo

2022-10-26T16:40:06Z

#2 - c4-judge

2022-11-09T16:16:28Z

GalloDaSballo marked the issue as satisfactory

#3 - c4-judge

2022-11-16T22:00:10Z

GalloDaSballo marked the issue as not a duplicate

#4 - c4-judge

2022-11-16T22:00:16Z

GalloDaSballo marked the issue as duplicate of #400

Awards

0.006 USDC - $0.01

Labels

2 (Med Risk)
satisfactory
duplicate-139

External Links

Judge has assessed an item in Issue #446 as M risk. The relevant finding follows:

[L-01] There should be an upper limit for LBFactory.flashLoanFee https://github.com/code-423n4/2022-10-traderjoe/blob/79f25d48b907f9d0379dd803fc2abc9c5f57db93/src/LBFactory.sol#L66 https://github.com/code-423n4/2022-10-traderjoe/blob/79f25d48b907f9d0379dd803fc2abc9c5f57db93/src/LBFactory.sol#L474 If the admin sets the flashLoanFee too high, the flash loan functionality might be useless as users won't use it.

#0 - c4-judge

2022-11-14T23:24:03Z

GalloDaSballo marked the issue as duplicate of #139

#1 - Simon-Busch

2022-12-05T06:31:10Z

Marked this issue as Satisfactory as requested by @GalloDaSballo

Findings Information

🌟 Selected for report: zzykxx

Also found by: 0x1f8b, 0xSmartContract, IllIllI, KingNFT, Rolezn, adriro, brgltd, hansfriese, pashov, rbserver

Labels

bug
QA (Quality Assurance)
grade-b
Q-09

Awards

279.8109 USDC - $279.81

External Links

#0 - GalloDaSballo

2022-11-09T19:20:33Z

[L-01] There should be an upper limit for LBFactory.flashLoanFee

M-03

[L-02] Missing events for admin functions that change critical parameters

NC

[L-03] Immutable addresses should be 0-checked

L

#1 - GalloDaSballo

2022-11-14T23:23:45Z

1L 1NC

#2 - c4-judge

2022-11-16T21:08:52Z

GalloDaSballo marked the issue as grade-b

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter