code-423n4 / 2023-01-numoen-findings

0 stars 0 forks source link

Lendgine contract can be drained through mint() function due to lack of Access Control #202

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Lendgine.sol#L71-L102

Vulnerability details

Impact

Anybody can call the mint function on lendgine.sol and enter any amount of collateral. This allows them to mint any number of tokens to their address for free.

Proof of Concept

The mint() function in lendgine.sol is external with no additional modifiers or checks for access control.

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Lendgine.sol#L71-L80

Additionally, the caller of the function can input any value for "collateral" and "address to", with no requirement that this needs to match their real collateral. Thus an attacker can call the function setting the "collateral" the amount they wish to mint in Lendgine contract, and set address "to" to their own address. Note that they do not have to send any tokens to the contract to do this.

Both the shares and liquidity are derived from the collateral which was entered by the attacker:

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Lendgine.sol#L83-L84

And this is used to calculate the amount minted to (address to). Since the collateral was the input by the caller of the mint() function, rather than their actually collateral, they can mint tokens while not having any real collateral.

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Lendgine.sol#L93

Tools Used

Manual Review, Hardhat

Recommended Mitigation Steps

Make the mint function internal or add an access control modifier to the function.

berndartmueller commented 1 year ago

Invalid.

It will revert due to https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Lendgine.sol#L99

The caller is required to provide the necessary collateral by transferring the amount from within the mintCallback callback function.

c4-judge commented 1 year ago

berndartmueller marked the issue as unsatisfactory: Invalid