Skip to content
Smart contracts Audit finding Intermediate

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.

ht111111 Follow with 0xrex, 4funnds and 10 others

Originally disclosed on Code4rena

Submitted by ht111111, also found by 0xrex, 4funnds, Ace2, hezze, JuggerNaut63, MikePeth, pepoc, qed, samuraii77, secssilia, v12, and zp6119126

Found with V12

K2’s incentives contract assumes that scaled_total_supply() returns a u128. The real token contracts do not:

  • a-token::scaled_total_supply() returns i128
  • debt-token::scaled_total_supply() returns i128

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:

  1. querying scaled_total_supply() as i128 returns the expected nonzero supply;
  2. querying the exact same function as u128 does not land in Ok(Ok(_));
  3. the incentives call sites therefore fall through to the _ => 0 branch.

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_atoken
  • test_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:

  1. reading scaled_total_supply() as i128 succeeds and returns the expected nonzero value;
  2. reading the same function as u128 does not land in Ok(Ok(_)), which matches the incentives contract’s _ => 0 fallback path.

From there it proves two user-visible failures:

  1. claim_all_rewards() transfers 0 and leaves the reward index unchanged, even though a fresh reward interval has accrued;
  2. set_emission_per_second() does not checkpoint the old interval before changing the emission rate, so the next handle_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


The original report as published on Code4rena, by ht111111. 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

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

  1. Query scaled_total_supply() as i128 on the real a-token WASM and observe a nonzero supply.
  2. Query the same function as u128 and observe it does not return Ok(Ok(_)).
  3. Call claim_all_rewards() and see it transfers 0 and leaves the reward index unchanged.
  4. Call set_emission_per_second() and see it does not checkpoint the old interval before changing the rate.
  5. 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.

More by ht111111

View all

3 more disclosed reports, best first.

More from K2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.