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

Arbitrary zeroExTradeData calldata to the exchange router may result in loss of fund for the borrower #384

Closed
code423n4 opened this issue Nov 10, 2022 · 4 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 downgraded by judge Judge downgraded the risk level of this issue duplicate-110 edited-by-warden partial-50

Comments

@code423n4
Copy link
Contributor

code423n4 commented Nov 10, 2022

Lines of code

https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/utils/SpigotedLineLib.sol#L135

Vulnerability details

Impact

During trading claimToken with targetToken, the calldata provided for the 0x router is an arbitrary data that can be provided by the borrower or lender.
https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/utils/SpigotedLineLib.sol#L135

If lender provides the calldata so that that more claimToken is consumed than expected, the borrower is impacted (loses some fund).

Proof of Concept

If a lender (malicious) would like to claim and repay, the flow is as follows:
claimAndRepay(address claimToken, bytes calldata zeroExTradeData) => function _claimAndTrade(address claimToken, address targetToken, bytes calldata zeroExTradeData) => function claimAndTrade(address claimToken, address targetToken, address payable swapTarget, address spigot, uint256 unused, bytes calldata zeroExTradeData) => function trade(uint256 amount, address sellToken, address payable swapTarget, bytes calldata zeroExTradeData)

https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/modules/credit/SpigotedLine.sol#L93
https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/modules/credit/SpigotedLine.sol#L187
https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/utils/SpigotedLineLib.sol#L53
https://github.com/debtdao/Line-of-Credit/blob/f32cb3eeb08663f2456bf6e2fba21e964da3e8ae/contracts/utils/SpigotedLineLib.sol#L120

Assuming the targetToken is DAI, and claimToken is USDC, if the calldata zeroExTradeData is something that calls the function buy 100 DAI for any amount of USDC instead of buy 100 DAI for maximum amount of 105 USDC, it is highly possible that more than 105 USDC will be consumed to trade for 100 DAI. In this case, the borrower loses more claimToken than expected.

In summary, since the calldata is arbitrary, the lender can put these data buy X targetToken for any amount of claim token or sell X claimToken for any amount of targetToken, in both cases the borrower may lose fund. While the correct call data is: buy X targetToken for max Y claimToken or sell X claimToken for min Y targetToken.

Tools Used

Recommended Mitigation Steps

The calldata zeroExTradeData should be set in advance that which function of the router is going to be called. For example in case of uniswap router, it should be abi.encodeWithSignature("swapExactTokensForTokens(uint256,uint256,address[],address,uint256)", amountIn, amountOutMin, path, to, dedline). In which the amountIn and amountOutMin should be a factor of each other so the borrower will not lose revenue token a lot.

@code423n4 code423n4 added 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 labels Nov 10, 2022
code423n4 added a commit that referenced this issue Nov 10, 2022
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly edited-by-warden and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Nov 10, 2022
@c4-judge
Copy link
Contributor

dmvt marked the issue as duplicate of #88

@c4-judge c4-judge added duplicate-88 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Nov 17, 2022
@c4-judge
Copy link
Contributor

dmvt changed the severity to 2 (Med Risk)

@c4-judge
Copy link
Contributor

c4-judge commented Dec 8, 2022

dmvt marked the issue as partial-50

@C4-Staff
Copy link
Contributor

captainmangoC4 marked the issue as duplicate of #110

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 downgraded by judge Judge downgraded the risk level of this issue duplicate-110 edited-by-warden partial-50
Projects
None yet
Development

No branches or pull requests

3 participants