Incentives silently skip reward checkpointing by querying scaled_total_supply() with the wrong ABI type
The incentives contract queries the token's scaled_total_supply() expecting a u128, but the token returns i128, so the cross-contract call fails and the contract silently treats supply as zero. This causes claim_all_rewards() to skip the latest reward interval and set_emission_per_second() to skip checkpointing the old emission rate, leading to underpayment and retroactive mispricing of rewards.
Submitted by ht111111, also found by 0xrex, 4funnds, Ace2, hezze, JuggerNaut63, MikePeth, pepoc, qed, samuraii77, secssilia, v12, and zp6119126
Found with V12
contracts/incentives/src/contract.rs#L418-L427contracts/incentives/src/contract.rs#L623-L629contracts/a-token/src/contract.rs#L534-L536contracts/debt-token/src/contract.rs#L280-L281
K2’s incentives contract assumes that scaled_total_supply() returns a u128. The real token contracts do not:
a-token::scaled_total_supply()returnsi128debt-token::scaled_total_supply()returnsi128
That mismatch is not harmless. In both claim_all_rewards() and set_emission_per_second(), the incentives contract performs a cross-contract query like:
try_invoke_contract::<u128, IncentivesError>(..., "scaled_total_supply", ...)
and then treats every non-Ok(Ok(_)) result as:
total_supply = 0
The PoC confirms the runtime behavior on the real a-token WASM:
- querying
scaled_total_supply()asi128returns the expected nonzero supply; - querying the exact same function as
u128does not land inOk(Ok(_)); - the incentives call sites therefore fall through to the
_ => 0branch.
This breaks two live reward-accounting paths.
First, claim_all_rewards() does not checkpoint the latest pending interval. If the caller has a real positive token supply but the cross-contract u128 decode is swallowed into 0, the function skips the global index update entirely. The user only receives rewards that had already been materialized in storage before the claim. The pending interval remains invisible until some later handle_action() call checkpoints it through the token callback path.
Second, set_emission_per_second() does not checkpoint the old emission regime before switching to the new one. The intended behavior is:
- settle rewards earned under the old rate up to the mutation timestamp;
- then store the new emission rate.
Instead, the same ABI mismatch collapses total_supply to 0, so the old interval is never checkpointed. The next real handle_action() then accrues the entire skipped interval using the new emission rate, retroactively repricing rewards that should have been settled under the old one.
This is not a theoretical type neatness issue. It is a live accounting bug that changes user-facing reward outcomes:
claim_all_rewards()underpays by skipping the most recent interval;set_emission_per_second()can misprice a historical interval after an admin emission change.
Recommended mitigation steps
Make the incentives contract query scaled_total_supply() using the token contracts’ real ABI (i128), then convert to u128 only after a successful decode and sign check. More broadly, do not treat cross-contract decode failures as a silent 0 supply in reward checkpointing paths; bubble the error or fail the checkpoint explicitly.
Proof of Concept
Executable PoC file
tests/unit-tests/src/finding_007_poc.rs
Test names
test_claim_all_rewards_skips_latest_interval_on_real_atokentest_set_emission_per_second_skips_old_checkpoint_on_real_atoken
Run command
cargo test -p k2-unit-tests finding_007_poc -- --nocapture
What it proves
The PoC uses the real a-token WASM instead of a mock and demonstrates two concrete effects of the ABI mismatch:
- reading
scaled_total_supply()asi128succeeds and returns the expected nonzero value; - reading the same function as
u128does not land inOk(Ok(_)), which matches the incentives contract’s_ => 0fallback path.
From there it proves two user-visible failures:
claim_all_rewards()transfers0and leaves the reward index unchanged, even though a fresh reward interval has accrued;set_emission_per_second()does not checkpoint the old interval before changing the emission rate, so the nexthandle_action()reprices the skipped interval under the new rate.
That shows the finding is not a static ABI style concern. It changes reward accounting on live paths.
See original finding for full Proof of Concept
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 incentives contract decodes the return value of scaled_total_supply() as u128 while the token contracts return i128, and it silently maps any decode failure to a supply of zero.
Impact
claim_all_rewards() underpays by skipping the most recent interval, and set_emission_per_second() can misprice a historical interval after an admin emission change.
What the attacker needed
A deployed incentives contract; a token contract returning i128; a user with pending rewards
The fix
The incentives contract should query scaled_total_supply() using the token contracts' real ABI (i128), convert to u128 only after a successful decode and sign check, and not treat cross-contract decode failures as a silent zero supply.
How it was found
- Query scaled_total_supply() as i128 on the real a-token WASM and observe a nonzero supply.
- Query the same function as u128 and observe it does not return Ok(Ok(_)).
- Call claim_all_rewards() and see it transfers 0 and leaves the reward index unchanged.
- Call set_emission_per_second() and see it does not checkpoint the old interval before changing the rate.
- Observe the next handle_action() reprices the skipped interval under the new rate.
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 asked another contract for a number but expected the wrong type, so the answer was rejected. Instead of reporting an error, the contract assumed the number was zero. That zero made it skip important reward calculations, so users could get less than they earned or rewards could be recalculated at the wrong rate.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.