You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lack of checks on the OnComplete field of the application calls might allow an attacker to execute the clear state program instead of the approval program, breaking core validations.
4
+
5
+
## Description
6
+
7
+
Algorand applications make use of group transactions to realize operations that may not be possible using a single transaction model. Some operations require that other transactions in the group call certain methods and applications. These requirements are asserted by validating that the transactions are ApplicationCall transactions. However, the OnComplete field of these transactions is not always validated, allowing an attacker to submit ClearState ApplicationCall transactions. The ClearState transaction invokes the clear state program instead of the intended approval program of the application.
8
+
9
+
## Exploit Scenario
10
+
11
+
A protocol offers flash loans from a liquidity pool. The flash loan operation is implemented using two methods: `take_flash_loan` and `pay_flash_loan`. `take_flash_loan` method transfers the assets to the user and `pay_flash_loan` verifies that the user has returned the borrowed assets. `take_flash_loan` verifies that a later transaction in the group calls the `pay_flash_loan` method. However, It does not validate the OnComplete field.
# Perform other validations, transfer assets to the user, update the global state
24
+
# [...]
25
+
])
26
+
27
+
@router.method(no_op=CallConfig.CALL)
28
+
defpay_flash_loan(offset: abi.Uint64) -> Expr:
29
+
return Seq([
30
+
# Validate the "take_flash_loan" transaction at `Txn.group_index() - offset.get()`
31
+
# Ensure the user has returned the funds to the pool along with the fee. Fail the transaction otherwise
32
+
# [...]
33
+
])
34
+
```
35
+
36
+
An attacker constructs a valid group transaction for flash loan but sets the OnComplete field of `pay_flash_loan` call to ClearState. The clear state program is executed for complete_flash_loan call, which does not validate that the attacker has returned the funds. The attacker steals all the assets in the pool.
37
+
38
+
## Recommendations
39
+
40
+
Validate the OnComplete field of the ApplicationCall transactions.
Inner transaction fees are by default set to an estimated amount which are deducted from the application account if it is the Sender. An attacker can perform operations executing inner transactions and drain system funds, making it under-collateralized.
4
+
5
+
## Description
6
+
7
+
Inner transactions are initialized with Sender set to the application account and Fee to the minimum allowable, taking into account MinTxnFee and credit from overpaying in earlier transactions. The inner transaction fee depends on the transaction fee paid by the user. As a result, the user controls, to some extent, the fee paid by the application.
8
+
9
+
If the application does not explicitly set the Fee to zero, an attacker can burn the application’s balance in the form of fees. This also becomes an issue if the application implements internal bookkeeping to track the application balance and does not account for fees.
10
+
11
+
## Exploit Scenarios
12
+
13
+
```py
14
+
@router.method(no_op=CallConfig.CALL)
15
+
defmint(pay: abi.PaymentTransaction) -> Expr:
16
+
return Seq([
17
+
# perform validations and other operations
18
+
# [...]
19
+
# mint wrapped-asset id
20
+
InnerTxnBuilder.Begin(),
21
+
InnerTxnBuilder.SetFields(
22
+
{
23
+
TxnField.type_enum: TxnType.AssetTransfer,
24
+
TxnField.asset_receiver: Txn.sender(),
25
+
TxnField.xfer_asset: wrapped_algo_asset_id,
26
+
TxnField.asset_amount: pay.get().amount(),
27
+
}
28
+
),
29
+
InnerTxnBuilder.Submit(),
30
+
# [...]
31
+
])
32
+
```
33
+
34
+
The application does not explicitly set the inner transaction fee to zero. When user mints wrapped-algo, some of the ALGO is burned in the form of fees. The amount of wrapped-algo in circulation will be greater than the application ALGO balance. The system will be under-collateralized.
35
+
36
+
## Recommendations
37
+
38
+
Explicitly set the inner transaction fees to zero and use the fee pooling feature of the Algorand.
0 commit comments