sherlock-audit / 2022-10-union-finance-judging

4 stars 1 forks source link

Picodes - `voucherIndexes` is incorrectly updated #160

Closed sherlock-admin closed 2 years ago

sherlock-admin commented 2 years ago

Picodes

high

voucherIndexes is incorrectly updated

Summary

In cancelVouch, voucherIndexes is incorrectly update, messing up the whole accountability and ultimately leading to loss of funds for stakers

Vulnerability Detail

Here, vouchers[borrower][vouchers[borrower].length - 1] is moved but voucherIndexes is not updated. So the user that created vouchers[borrower][vouchers[borrower].length - 1] cannot modify this voucher anymore has voucherIndexes is incorrect.

Impact

Affected users will not be able to close or update their trust amounts anymore, hence will lose funds.

Tool used

Manual Review

Recommendation

Add the following line:

voucherIndexes[borrower][vouchers[borrower][vouchers[borrower].length - 1].staker].idx = voucherIndex.idx

Duplicate of #157