Nested Finance contest - hyh's results

The one-stop Defi app to build, manage and monetize your portfolio.

General Information

Platform: Code4rena

Start Date: 11/11/2021

Pot Size: $50,000 USDC

Total HM: 9

Participants: 27

Period: 7 days

Judge: alcueca

Total Solo HM: 5

Id: 53

League: ETH

Nested Finance

Findings Distribution

Researcher Performance

Rank: 7/27

Findings: 3

Award: $2,227.17

🌟 Selected for report: 4

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: hyh

Also found by: jayjonah8

Labels

bug
2 (Med Risk)
disagree with severity

Awards

1169.9215 USDC - $1,169.92

External Links

Handle

hyh

Vulnerability details

Impact

Contract holdings can be emptied as malicious user will do deposit/withdraw to extract value. This is possible because after _transferInputTokens system uses contract balance for user's operations, assuming that equivalent value was transferred.

Proof of Concept

msg.value persist over calls, so passing 'Order[] calldata _orders' holding multiple ETH deposits will use the same msg.value in each of them, resulting in multiple deposits, that sums up to much bigger accounted value than actually deposited value, up to contract's ETH holdings.

create / addTokens -> _submitInOrders -> _transferInputTokens https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L103 https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L119

sellTokensToWallet -> _submitOutOrders -> _transferInputTokens https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L172

sellTokensToNft -> _submitOutOrders -> _transferInputTokens https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L152

_transferInputTokens uses msg.value: https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L462

Controlling ETH to be only once in orders will not help, as NestedFactory inherits from Multicall, which multicall(bytes[] calldata data) function allows same reusage of msg.value, which will persist over calls.

So, it is recommended to treat ETH exclusively, not allowing ETH operations to be batched at all.

#0 - adrien-supizet

2021-11-18T11:37:09Z

Multicall is not currently used, and the funds exposed would be the NestedFactory's which should hold no funds.

To avoid future bugs, we're going to remove the multicall library, but we don't think this is a high severity issue.

#1 - alcueca

2021-12-03T09:49:22Z

Downgrading severity to 2 because the NestedFactory is not expected to hold funds, and therefore there is no risk of a loss. You can't deposit the same Ether twice in the WETH contract.

Also keeping this as the main over #13.

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