TRSRY susceptible to loan / withdraw confusion
The treasury contract uses the same approval mapping for both withdrawals and loans, so a policy with loan permission can withdraw funds directly without recording a loan. This could allow a policy to bypass loan bookkeeping and potentially cause loss of funds.
Submitted by Trust, also found by 0xSky, datapunk, and tonisives
https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L64-L102
Treasury allocates approvals in the withdrawApproval mapping which is set via setApprovalFor(). In both withdrawReserves() and in getLoan(), _checkApproval() is used to verify user has enough approval and subtracts the withdraw / loan amount. Therefore, there is no differentiation in validation between loan approval and withdraw approval. Policies which will use getLoan() (currently none) can simply withdraw the tokens without bookkeeping it as a loan.
Proof of Concept
- Policy P has getLoan permission
- setApprovalFor(policy, token, amount) was called to grant P permission to loan amount
- P calls withdrawReserves(address, token, amount) and directly withdraws the funds without registering as loan
Recommended Mitigation Steps
A separate mapping called loanApproval should be implemented, and setLoanApprovalFor() will set it, getLoan() will reduce loanApproval balance.
ind-igo (Olympus) confirmed, but disagreed with severity and commented:
Confirmed. Good suggestion. Would put as low risk though.
Currently thinking Medium is appropriate for this issue, but will circle back on it.
See #293 for a possible vector in which this could lead to loss of funds. Going to leave as Medium.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract uses a single approval mapping for both withdrawals and loans, so loan approvals can be spent as withdrawal approvals.
What the attacker needed
A policy with loan permission; Loan approval granted via setApprovalFor
The fix
A separate loan approval mapping should be implemented, with its own setter, and getLoan should reduce that balance instead of the withdrawal approval.
How it was found
- A policy is granted loan permission via setApprovalFor.
- The policy calls withdrawReserves instead of getLoan.
- The funds are withdrawn directly without being registered as a loan.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract lets certain trusted programs (policies) borrow or withdraw funds from a treasury. The same permission slip is used for both actions, so a program allowed to borrow can instead just take the money without it being tracked as a loan. This mix-up could let funds disappear without proper accounting.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.