Skip to content
Business logic Audit finding Intermediate

Low market bonds/swaps not working after loan is taken from treasury

The treasury contract allowed a trusted debtor to take a loan, but the operator's capacity calculation still counted the loaned tokens as available, causing transfers to fail. An attacker with a trusted contract could take a large loan and then legitimate bond or swap operations would fail due to insufficient balance.

immeas Follow

Originally disclosed on Code4rena

Submitted by immeas

https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L60

I am bordering between this being medium and low, but since this is, granted under very unlikely circumstances, hindering intended transfers to work I am submitting it as medium. That said, I don’t think this scenario is very likely since it requires a trusted contract not part of initial release(? no contract in repo used a loan) to take a large loan from TRSRY.

Proof of Concept

This will cause test to fail on TRANSFER_FAILED due to TRSRY not having the tokens to transfer but getReserveBalance says it has, since capacity is determined based on non-existing tokens.

diff --git a/src/test/policies/Operator.t.sol b/src/test/policies/Operator.t.sol
index e09aec1..5c1e95f 100644
--- a/src/test/policies/Operator.t.sol
+++ b/src/test/policies/Operator.t.sol
@@ -26,6 +26,8 @@ import {OlympusMinter, OHM} from "modules/MINTR.sol";
 import {Operator} from "policies/Operator.sol";
 import {BondCallback} from "policies/BondCallback.sol";

+import {ModuleTestFixtureGenerator} from "test/lib/ModuleTestFixtureGenerator.sol";
+
 contract MockOhm is ERC20 {
     constructor(
         string memory _name,
@@ -45,6 +47,7 @@ contract MockOhm is ERC20 {
 // solhint-disable-next-line max-states-count
 contract OperatorTest is Test {
     using FullMath for uint256;
+    using ModuleTestFixtureGenerator for OlympusTreasury;

     UserFactory public userCreator;
     address internal alice;
@@ -53,6 +56,9 @@ contract OperatorTest is Test {
     address internal policy;
     address internal heart;

+    address public debtor;
+    address public godmode;
+
     RolesAuthority internal auth;
     BondAggregator internal aggregator;
     BondFixedTermTeller internal teller;
@@ -187,6 +193,18 @@ contract OperatorTest is Test {

         reserve.mint(address(treasury), testReserve * 100);

+        debtor = treasury.generateFunctionFixture(treasury.getLoan.selector);
+        godmode = treasury.generateGodmodeFixture(type(OlympusTreasury).name);
+
+        kernel.executeAction(Actions.ActivatePolicy, godmode);
+        kernel.executeAction(Actions.ActivatePolicy, debtor);
+
+        vm.prank(godmode);
+        treasury.setApprovalFor(debtor, reserve, testReserve * 100);
+
+        vm.prank(debtor);
+        treasury.getLoan(reserve,testReserve*100);
+
         // Approve the operator and bond teller for the tokens to swap
         vm.prank(alice);
         ohm.approve(address(operator), testOhm * 20);

Same is applicable for low market bonds since they are created based on the same capacity.

Tools Used

vs code + tests

Recommended Mitigation Steps

Determine capacity from actual tokens held by treasury.

ind-igo (Olympus) confirmed and commented:

Acknowledged. Will add a reserve requirement check inside the TRSRY’s debt functions, which we can expand with a policy to rebalance if out of balance on a heartbeat.


The original report as published on Code4rena, by immeas. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the capacity calculation uses the treasury's recorded reserve balance without accounting for outstanding loans, so it overstates available tokens.

Impact

Under unlikely circumstances, intended transfers for bonds or swaps could fail, disrupting operations.

What the attacker needed

A trusted contract with loan permission; large loan taken from treasury

The fix

The fix should determine capacity from the actual tokens held by the treasury, and the team acknowledged they will add a reserve requirement check in the treasury's debt functions.

How it was found

  1. Activate a godmode policy and a debtor policy that can call getLoan.
  2. Set approval for the debtor to withdraw reserve tokens from the treasury.
  3. Have the debtor call getLoan to borrow a large amount of reserve tokens.
  4. Attempt a bond or swap operation that relies on the treasury's capacity; the transfer fails because the treasury lacks the tokens.

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 treasury contract lets other contracts borrow tokens. The system that handles bonds and swaps checks how many tokens the treasury has, but it mistakenly includes tokens that have been lent out. So when someone tries to use those tokens, the transfer fails because they are not actually there.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by immeas

View all

24 more disclosed reports, best first.

More from Olympus DAO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.