# Gas costs are severely underpriced for certain WASM instructions which can lead to network DoS

Seda's WASM VM charges a flat 115 gas for all non-accounting ops, letting malicious oracle programs spam TableGrow/MemoryFill/math to exhaust node resources and DoS the network.

- Payout: Audit contest
- Severity: high
- Program: Seda Protocol
- Found by: tallo
- Disclosed: 2024-12-20
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/183
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-seda-protocol%3AH-4
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:high tech:evm tech:rust technique:source-review vuln:dos vuln:misconfiguration

**Target:** seda-wasm-vm runtime metering (metering.rs)
**Root cause:** get_wasm_operation_gas_cost applies a flat GAS_PER_OPERATION to every instruction except accounting ops and MemoryGrow, so computationally expensive instructions (TableGrow, MemoryFill, TableCopy, MemoryInit, sin/cos/exp/log/div/sqrt) are priced identically to cheap ones.
**Steps:**
1. Register an oracle program on the SEDA chain.
2. Craft the program to loop over underpriced ops: `TableGrow` with large size, repeated `MemoryFill`/`MemoryInit`/`TableInit`, or heavy math (`sin`/`cos`/`exp`/`log`/`div`/`sqrt`).
3. Submit a data request invoking the program.
4. Each instruction is charged only `GAS_PER_OPERATION` (115) despite disproportionate CPU/memory cost.
5. Repeat submissions to amplify resource exhaustion during EndBlock execution.
**How found:** Code review of metering.rs: noticed the match only special-cases MemoryGrow and accounting ops, leaving all other operators at a flat cost, then reasoned about which WASM instructions are disproportionately expensive.
**Exploitation:** Attacker submits many data requests whose oracle programs loop expensive WASM instructions; each pays 115 gas but forces large table/memory allocation or heavy math, exhausting node CPU/memory during EndBlock and crashing nodes.
**Escalation:** Multiple malicious requests submitted in parallel amplify resource exhaustion across the network.
**Insight:** When auditing gas metering, enumerate every WASM operator and compare its real CPU/memory cost against the flat default; TableGrow, MemoryFill, MemoryInit, TableCopy and transcendental math are classic underpriced ops that a single flat rate misses.

## Proof of concept (copied exactly from the original report)

**Flat gas cost function in metering.rs**

```
pub fn get_wasm_operation_gas_cost(operator: &Operator) -> u64 {
    if is_accounting(operator) {
        return GAS_PER_OPERATION * GAS_ACCOUNTING_MULTIPLIER;
    }

    match operator {
        Operator::MemoryGrow { mem, mem_byte: _ } => {
            GAS_MEMORY_GROW_BASE + ((WASM_PAGE_SIZE as u64 * *mem as u64) * GAS_PER_BYTE)
        }
        _ => GAS_PER_OPERATION,
    }
}
```

