#37807 [SC-Insight] Truncation of mint_amount to zero leading to potential stake loss
Description
Brief/Intro
Vulnerability Details
@router.method(no_op=CallConfig.CALL)
def claim_delayed_mint(receiver: abi.Address, nonce: abi.StaticBytes[L[2]]) -> Expr:
box_name = Concat(DelayMintBox.NAME_PREFIX, receiver.get(), nonce.get())
box = BoxGet(box_name)
delay_mint_receiver = Extract(box.value(), DelayMintBox.RECEIVER, Int(32))
delay_mint_stake = ExtractUint64(box.value(), DelayMintBox.STAKE)
delay_mint_round = ExtractUint64(box.value(), DelayMintBox.ROUND)
algo_balance = ScratchVar(TealType.uint64)
mint_amount = ScratchVar(TealType.uint64)
return Seq(
# callable by anyone
rekey_and_close_to_check(),
# ensure initialised
Assert(App.globalGet(initialised_key)),
# check nonce is 2 bytes
Assert(Len(nonce.get()) == Int(2)),
# check box
box,
Assert(box.hasValue()),
Assert(receiver.get() == delay_mint_receiver),
Assert(Global.round() >= delay_mint_round),
# update total stake and total rewards
App.globalPut(total_pending_stake_key, App.globalGet(total_pending_stake_key) - delay_mint_stake),
App.globalPut(total_active_stake_key, App.globalGet(total_active_stake_key) + delay_mint_stake),
update_total_rewards_and_unclaimed_fees(),
# calculate mint amount
algo_balance.store(
App.globalGet(total_active_stake_key)
+ App.globalGet(total_rewards_key)
- delay_mint_stake
- App.globalGet(total_unclaimed_fees_key)
),
mint_amount.store(
If(
algo_balance.load(),
mul_scale(delay_mint_stake, get_x_algo_circulating_supply(), algo_balance.load()),
delay_mint_stake
)
),
# send xALGO to user
mint_x_algo(mint_amount.load(), receiver.get()),
# delete box so cannot claim multiple times
Assert(BoxDelete(box_name)),
# give box min balance to sender as incentive
InnerTxnBuilder.Begin(),
get_transfer_inner_txn(Global.current_application_address(), Txn.sender(), get_app_algo_balance(), Int(0)),
InnerTxnBuilder.Submit(),
# log so can retrieve info for claiming
Log(Concat(
MethodSignature("ClaimDelayedMint(byte[36],address,uint64,uint64)"),
box_name,
receiver.get(),
Itob(delay_mint_stake),
Itob(mint_amount.load()),
)),
)Impact details
Resolution
Proof of Concept
Proof of Concept
Previous#37791 [SC - Insight] consensus contract distributes algo for proposers that are offline that causeNext#37852 [SC-High] The accumulation of rewards is being decreased from the active stake which could le
Last updated
Was this helpful?