Closed c4-submissions closed 1 year ago
0xA5DF marked the issue as low quality report
In the _createDeposit function, the depositNonce is augmented by 1 prior to the storage of the deposit, whereas it should have been incremented post the storage of the deposit.
Why? Any evidence that it causes any issues to the protocol?
alcueca marked the issue as unsatisfactory: Insufficient quality
Lines of code
https://github.com/code-423n4/2023-09-maia/blob/f5ba4de628836b2a29f9b5fff59499690008c463/src/BranchBridgeAgent.sol#L821
Vulnerability details
Impact
In the smart contract code provided, there exists a notable logical flaw where the Nonce value in
payload
andgetDeposit
fails to align. This flaw can be taken advantage of by a malicious entity by making two sequential deposits (for instance, a larger sum followed by a smaller sum), and intentionally causing the deposit with the lesser amount to fail. Due to the discrepancy betweengetDeposit[depositNonce]
andgetDeposit[depositNonce + 1]
, the malicious entity could redeem the larger sum on the branch chain, despite having already acquired the corresponding tokens on the root chain. This act of exploitation could lead to the theft of funds and result in the insolvency of the smart contract.Proof of Concept
Outlined below are segments of the code and relevant functions that demonstrate the impact:
Function
callOutAndBridge
Function
_createDeposit
Function
redeemDeposit
In the
_createDeposit
function, thedepositNonce
is augmented by 1 prior to the storage of the deposit, whereas it should have been incremented post the storage of the deposit.Recommended Mitigation Steps
In order to address the identified issues, it is advised to relocate the statement
depositNonce = _depositNonce + 1;
to the conclusion of the_createDeposit
function. This adjustment ensures that thedepositNonce
is incremented accurately after the deposit has been stored, thereby resolving the Nonce mismatch issue betweenpayload
andgetDeposit
.Moreover, a similar issue was observed with the settlement nonce, and it's suggested to implement the same remedial measure to rectify the issue.
Assessed type
Rug-Pull