Reentrancy Check in lock_staking::reentry_check Causes Concurrent INIT Deposit Failures (DOS)
The deposit function for INIT tokens fails when two users deposit in the same block because a reentrancy check prevents multiple delegations per block. An attacker could cause a denial of service by submitting a deposit just before other users, making their transactions fail and lose gas fees.
Submitted by rare_one
Finding description and impact
The liquid staking protocol’s deposit_init_for_xinit function, which allows users to deposit INIT tokens to receive xINIT, is vulnerable to transaction failures when multiple users deposit concurrently in the same block. The function withdraws INIT tokens and delegates them to a validator via pool_router::add_stake, which triggers lock_staking::delegate. This, in turn, invokes reentry_check to prevent multiple delegations in the same block.
If a second user attempts to deposit in the same block as another, their transaction fails with error code 196618 (EREENTER), as reentry_check detects that the StakingAccount was already modified in the current block. This vulnerability disrupts users’ ability to participate in the protocol, particularly during periods of high transaction activity.
Root Cause:
The reentry_check function in lock_staking.move enforces a strict one-delegation-per-block rule for a given StakingAccount:
fun reentry_check(
staking_account: &mut StakingAccount,
with_update: bool
) {
let (height, _) = block::get_block_info();
assert!(staking_account.last_height != height, error::invalid_state(EREENTER));
if (with_update) {
staking_account.last_height = height;
};
}
This function checks if staking_account.last_height equals the current block height and aborts with EREENTER if true. If with_update is true, it updates last_height to the current height, marking the block as processed.
In cabal.move, the deposit_init_for_xinit function processes user deposits independently:
public entry fun deposit_init_for_xinit(account: &signer, deposit_amount: u64) acquires ModuleStore {
emergency::assert_no_paused();
assert!(deposit_amount > 0, error::invalid_argument(EINVALID_COIN_AMOUNT));
let m_store = borrow_global<ModuleStore>(@staking_addr);
let coin_metadata = coin::metadata(@initia_std, string::utf8(b"uinit"));
// calculate mint xinit
let init_amount = pool_router::get_real_total_stakes(coin_metadata);
let x_init_amount = option::extract(&mut fungible_asset::supply(m_store.x_init_metadata));
let mint_x_init_amount = if (x_init_amount == 0) {
deposit_amount
} else {
let ratio = bigdecimal::from_ratio_u64(deposit_amount, init_amount);
// Round up because of truncation
(bigdecimal::mul_by_u128_ceil(ratio, x_init_amount) as u64)
};
assert!(mint_x_init_amount > 0, error::invalid_argument(EINVALID_STAKE_AMOUNT));
// withdraw init to stake
let fa = primary_fungible_store::withdraw(
account,
coin_metadata,
deposit_amount
);
pool_router::add_stake(fa); // Triggers lock_staking::delegate
// mint xINIT to user
coin::mint_to(&m_store.x_init_caps.mint_cap, signer::address_of(account), mint_x_init_amount);
}
When multiple users call deposit_init_for_xinit in the same block:
- The first user’s deposit passes
reentry_check, updatesstaking_account.last_heightto the current block height (assumingwith_update = trueinlock_staking::delegate), and completes, minting xINIT. - The second user’s deposit triggers
reentry_checkviapool_router::add_stakeandlock_staking::delegate. Sincestaking_account.last_heightequals the current height, the transaction aborts with EREENTER, preventing the deposit and xINIT minting.
The function’s lack of coordination for concurrent deposits results in multiple lock_staking::delegate calls, triggering the reentrancy failure. This vulnerability is evident in production scenarios where users deposit INIT during high network activity, such as during market events or protocol launches.
IMPACTS:
Denial-of-Service (DoS) for Users: Users attempting to deposit INIT in a block with multiple deposits will face transaction failures, losing gas fees and being unable to receive xINIT. This disrupts their ability to participate in liquid staking, particularly during peak usage periods.
Financial Loss: Failed transactions result in gas fee losses for users, which can accumulate significantly in high-traffic scenarios, deterring participation.
Recommended mitigation steps
Implement a batching mechanism to aggregate all user INIT deposits within a block and process them as a single delegation, ensuring only one call to lock_staking::delegate per block and bypassing the reentry_check restriction.
Proof of Concept
Initialize the protocol using initialize to set up the xINIT pool.
Simulate two users depositing INIT in the same block using mockdepositinitforxinit.
Observe the EREENTER error (code 196618) from reentry_check for the second deposit.
// User 1 transaction (submitted in block 100) public entry fun user1deposit(account: &signer) { depositinitforxinit(account, 500000000); }
// User 2 transaction (submitted in block 100) public entry fun user2deposit(account: &signer) { depositinitforxinit(account, 200000000); }
Setup:
Deploy the protocol and initialize it.
Fund User 1 (@0x1) with 500,000,000 INIT and User 2 (@0x2) with 200,000,000 INIT.
Set block height to 100.
User 1 submits user1*deposit in block 100, calling deposit*init*for*xinit, withdrawing 500,000,000 INIT, delegating viapool*router::add*stake(triggeringlock_staking::delegate), and minting approximately 500,000,000 xINIT (adjusted for pool size).
User 2 submits user2*deposit in block 100, calling deposit*init*for*xinit, butpool*router::add*staketriggerslock*staking::delegateandreentry*check. Sincestaking*account.last*height equals 100 (from User 1’s deposit), the transaction aborts with EREENTER (code 196618).
Result:
User 1: Receives ~500,000,000 xINIT.
User 2: Transaction fails, loses gas fees, receives no xINIT.
This test demonstrates the issue
fun test_concurrent_deposits(c: &signer, user_a: &signer, user_b: &signer) {
test_setup(c, string::utf8(b"initvaloper1test"));
let init_metadata = coin::metadata(@initia_std, string::utf8(b"uinit"));
let x_init_metadata = cabal::get_xinit_metadata();
// Transfer INIT to users
let deposit_a = 500_000_000;
let deposit_b = 200_000_000;
primary_fungible_store::transfer(c, init_metadata, signer::address_of(user_a), deposit_a);
primary_fungible_store::transfer(c, init_metadata, signer::address_of(user_b), deposit_b);
// Simulate concurrent deposits (no block increase between them)
cabal::mock_deposit_init_for_xinit(user_a, deposit_a);
cabal::mock_deposit_init_for_xinit(user_b, deposit_b);
utils::increase_block(1, 1);
// Verify xINIT balances
let user_a_xinit = primary_fungible_store::balance(signer::address_of(user_a), x_init_metadata);
let user_b_xinit = primary_fungible_store::balance(signer::address_of(user_b), x_init_metadata);
assert!(user_a_xinit == deposit_a || user_a_xinit == deposit_a - 1, 1007);
assert!(user_b_xinit == deposit_b || user_b_xinit == deposit_b - 1, 1008);
// Verify global state
let final_xinit_supply = cabal::get_xinit_total_supply();
let final_total_staked_init = cabal::get_pool_router_total_init();
assert!(final_xinit_supply == (MINIMUM_LIQUIDITY as u128) + (deposit_a as u128) + (deposit_b as u128), 1009);
assert!(final_total_staked_init == MINIMUM_LIQUIDITY + deposit_a + deposit_b, 1010);
}
and the result
Failures in 0xe472ba1c00b2ee2b007b4c5788839d6fb7371c6::core_staking_test:
┌── test_concurrent_deposits ──────
│ error[E11001]: test failure
│ ┌─ ././vip-contract/sources/lock_staking.move:1226:9
│ │
│ 1222 │ fun reentry_check(
│ │ ------------- In this function in 0xe55cc823efb411bed5eed25aca5277229a54c62ab3769005f86cc44bc0c0e5ab::lock_staking
│ ·
│ 1226 │ assert!(staking_account.last_height != height, error::invalid_state(EREENTER));
│ │ ^^^^^^ Test was not expected to error, but it aborted with code 196618 originating in the module e55cc823efb411bed5eed25aca5277229a54c62ab3769005f86cc44bc0c0e5ab::lock_staking rooted here
│
│
│ stack trace
│ lock_staking::delegate_internal(././vip-contract/sources/lock_staking.move:715)
│ lock_staking::delegate(././vip-contract/sources/lock_staking.move:256)
│ pool_router::mock_process_delegate_init(./sources/pool_router.move:608-614)
│ pool_router::mock_add_stake(./sources/pool_router.move:630)
│ cabal::mock_deposit_init_for_xinit(./sources/cabal.move:1196)
│ core_staking_test::test_concurrent_deposits(./tests/core_staking_test.move:780)
│
└──────────────────
Test result: FAILED. Total tests: 1; passed: 0; failed: 1
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 reentry_check function enforces a strict one-delegation-per-block rule by comparing the current block height to a stored last_height, and aborts if they match, without coordinating multiple deposits.
Impact
Users attempting to deposit in a block with multiple deposits will face transaction failures, losing gas fees and being unable to receive xINIT, which disrupts participation during peak usage.
What the attacker needed
Two users deposit in same block; protocol not paused
The fix
Implement a batching mechanism to aggregate all user INIT deposits within a block and process them as a single delegation, ensuring only one call to lock_staking::delegate per block.
How it was found
- Deploy the protocol and initialize it.
- Fund two users with INIT tokens.
- Set block height to 100.
- User 1 submits a deposit transaction in block 100, which succeeds and mints xINIT.
- User 2 submits a deposit transaction in the same block 100, which triggers reentry_check and aborts with EREENTER.
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.
This is a bug in a smart contract for a liquid staking token. When two people try to deposit tokens at the same time (in the same block), the second person's deposit is rejected because the contract only allows one deposit per block. This means users can lose their transaction fees and cannot deposit when the network is busy.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.