# Block gas utilization is slightly lower than the actual gas utilization due to the gas snapshot being taken too early, resulting in an inaccurate base fee calculation

MANTRA's xfeemarket PostHandler snapshots gas before fee checks, undercounting block utilization ~21% and underestimating base fee.

- Payout: Audit contest
- Severity: medium
- Program: MANTRA
- Found by: berndartmueller
- Disclosed: 2025-03-31
- Write-up quality: 6/10
- Original: https://code4rena.com/reports/2024-11-mantra-chain#m-02
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-mantra-chain%3AM-02
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:go technique:source-review vuln:accounting-error vuln:fee-bypass

**Target:** Cosmos SDK PostHandler in x/xfeemarket/post/fee.go
**Root cause:** Gas snapshot taken at line 81 before GetMinGasPrice and CheckTxFee consume gas, so state.Update receives a lower gas value than actually consumed.
**Steps:**
1. Read x/xfeemarket/post/fee.go: gas := ctx.GasMeter().GasConsumed() at L81
2. Note state.Update(gas, params) at L129 uses that stale snapshot
3. Insert snapshot before L99 and print ctx.GasMeter().GasConsumed()-snapshot after L142
4. Run TestPostHandle_Audit with gasLimit=100000; observe gasDiff 31368
5. Compare to ~151,517 gas for a simple bank send (~21% undercount)
**How found:** Code review of the custom PostHandler flow, noticing the gas snapshot precedes fee-related calls that consume gas before state.Update.
**Insight:** In Cosmos PostHandlers, any gas-meter reads before fee deduction/ante checks undercount utilization; snapshot immediately before state mutation and diff-test with a print of GasConsumed deltas.

