Skip to content
Smart contracts Audit finding Beginner

Incorrect nonce value emitted in TimeBasedCollateralPool::_resetPool event

The contract emits a PoolReset event with an incorrect nonce value because it adds 1 to an already incremented nonce. This could mislead off-chain consumers that rely on the event's nonce to track reset counts.

mrMorningstar Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#36306 [SC-Insight] Incorrect nonce value emitted in `TimeBasedCollateralPool::_resetPool` event

Submitted on Oct 28th 2024 at 18:44:16 UTC by @MrMorningstar for Audit Comp | Anvil

Description

Brief/Intro

Incorrect nonce value emitted in `TimeBasedCollateralPool::_resetPool` event

Vulnerability Details

If pool is in process to reset in `_resetPool`(https://github.com/AcronymFoundation/anvil-contracts/blame/1bbe04bb6f1aa1beea0ebf55e1bad67da3aa0f87/contracts/TimeBasedCollateralPool.sol#L1022) the nonce is updated in this line here:

```js // NB: must be resetNonce++, NOT ++resetNonce uint256 resetNonce = contractStateStorage.resetNonce++; ``` After the reset is done the the following event is emitted:

```js emit PoolReset(IERC20(_tokenAddress), resetNonce + 1, tokensToReset, unitsToReset); ``` The issue here that the event uses already updated value of `resetNonce`.

Impact Details

This does not impact functionality of the protocol, but it could impact place that rely on the value of the `PoolReset` event (maybe on front end if someone wants to know if reset happened or how many times reset is happened) because wrong data will be passed.

Recommendation

Change the event emitted like this to pass the correct information

```diff

  • emit PoolReset(IERC20(_tokenAddress), resetNonce + 1, tokensToReset, unitsToReset);
  • emit PoolReset(IERC20(_tokenAddress), resetNonce, tokensToReset, unitsToReset); ```

Proof of Concept

Proof of Concept

POC:

Lets assume there are no resets before and this is the first reset of the pool so the resetNonce will have following value: `contractStateStorage.resetNonce = 0`

If reset process is eligible and will proceed the `resetNonce` would be updated to the new value of 1 as we can see in this line

```js // NB: must be resetNonce++, NOT ++resetNonce uint256 resetNonce = contractStateStorage.resetNonce++; ``` So `resetNonce = 1` now.

After reset is processed the `PoolReset` event will be emitted with `newResetNonce` value of 2 instead of correct value of 1 because of this `resetNonce + 1`. This is incorrect because the actual value of `resetNonce` is 1 not 2.

The original report as published on Immunefi, by MrMorningstar. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

Impact

This does not impact protocol functionality, but could mislead off-chain consumers that rely on the PoolReset event's nonce value.

What the attacker needed

None

The fix

The event should emit the nonce without adding 1, so it reflects the actual stored value.

How it was found

  1. Assume the pool has never been reset, so the stored nonce is 0.
  2. Trigger a reset; the nonce is incremented to 1.
  3. The contract emits PoolReset with nonce 2 instead of 1.

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 sometimes announces what it did by emitting an event, like a public log. Here, the log said the reset count was one higher than it really was, so anyone reading the log would get the wrong number.

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 mrMorningstar

View all

6 more disclosed reports, best first.

More from Anvil

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.