Precision Loss During Division #151
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
duplicate
This issue or pull request already exists
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L757
https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L541
Vulnerability details
Proof-of-Concept
Assume that
toSwap = 10 DAI
andpathLen = 3
in this example.Therefore, the bridge will pull 10 DAI from the
RouterFacet
contract. However, within theBridgeFacet._handleExecuteLiquidity
function, due to precision loss when solidity handles division of integer, the following code will result inrouterAmount
to be evaluted to3
:The code will then proceed to deduct the liquidity from all the 3 routers equally:
Router A =
-3 DAI
Router B =
-3 DAI
Router C =
-3 DAI
A total of
-9 DAI
is deducted from the 3 routers. However, this value does not match with the amount of DAI that was being pulled from theRouterFacet
contract.10 DAI
was pulled fromRouterFacet
contract, but9 DAI
was deducted from the 3 routers. Thus, there is some discrepancy over here.https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L757
The following code within
BridgeFacet._reconcile
function exhibits the same problem and also demostrate that only9 DAI
will be reimbuse back to the 3 routers.https://github.com/code-423n4/2022-06-connext/blob/4dd6149748b635f95460d4c3924c7e3fb6716967/contracts/contracts/core/connext/facets/BridgeFacet.sol#L541
Impact
It might cause some internal accounting issue within the protocol due to the discrepancy.
Recommended Mitigation Steps
It is recommended to update the code so that the amount pulled from
RouterFacet
contract is equal to the amount deducted from the routers. Considering having the last router "sweep" all the remaining balance as shown below:The above code will deduct the liquidity from the routers as follows, which will add up to the
10 DAI
.Router A =
-3 DAI
Router B =
-3 DAI
Router C =
-4 DAI
The text was updated successfully, but these errors were encountered: