# Incorrect Calculation Logic

***

## Issue from Incorrect priceMarkUp Range

When using `priceMarkup`, it's important to carefully consider who bears the cost of any discount. Be mindful of scenarios where other users or the paymaster may be unfairly burdened.

Example Case:

If the `priceMarkUp` is too low (discount), only certain users may benefit from the reduced gas fees, while other users may be unable to access the amount they have deposited.

<figure><img src="https://964345221-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei169WYgpcSKzLw6xzlv%2Fuploads%2FtO7PjPEYR9GKSNzzEXSA%2Fimage.png?alt=media&#x26;token=b95deec8-4aff-4918-ad81-9a89f152a9aa" alt=""><figcaption></figcaption></figure>

* Mitigation: The range of `priceMarkUp` should be restricted to ensure it does not negatively impact the protocol.

{% code overflow="wrap" %}

```solidity
require(_tokenPaymasterConfig.priceMarkup <= 2 * PRICE_DENOMINATOR, "TPM: price markup too high");
require(_tokenPaymasterConfig.priceMarkup >= PRICE_DENOMINATOR, "TPM: price markup too low");
```

{% endcode %}

***

## Overflow/Underflow Risk with Unchecked Operations

When using `unchecked` blocks to save gas, be cautious of overflow/underflow risks, especially when performing calculations with sensitive variables or user-supplied parameters.

Example Case:

If a user `withdraws` all their `deposit` while their `userOperation` is waiting in the mempool after the first validation, an underflow could occur in the gas payment process due to an `unchecked` code block.

Following this process, the user’s `deposit` approaches the maximum value, allowing them to potentially `withdraw` all of the Paymaster’s funds.

<figure><img src="https://964345221-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fei169WYgpcSKzLw6xzlv%2Fuploads%2FizJi9rrlpgUwxupqdYR2%2Fimage.png?alt=media&#x26;token=bdfdb8ab-499c-48a3-88b6-3772c394e11d" alt=""><figcaption></figcaption></figure>

* Mitigation: A conditional statement should be used to compare the two values before performing the actual calculation to ensure that such issues do not occur.

```solidity
if (requiredGasCost > deposits[user]){
    revert("deposit too low");
}
```
