Tally VM startup costs not charged early enough
The gas cost for starting the WASM VM during the tally phase is charged too late, after expensive setup operations. An attacker can submit data requests with a gas limit that covers earlier phases but leaves insufficient gas for tallying, causing the VM to start and then immediately halt, leading to a denial-of-service and chain slowdown.
Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/157
Found by
zxriptor
Summary
The gas for activating the WASM VM is not charged early enough to prevent DoS attacks.
Root Cause
In seda-wasm-vm/runtime/core/src/runtime.rs#L85-L93, the gas is charged for starting up VM based on the formula (GAS_PER_BYTE * args_bytes_total as u64) + GAS_STARTUP where GAS_PER_BYTE = 10_000 and GAS_STARTUP = 5_000_000_000_000.
let args_bytes_total = call_data.args.iter().fold(0, |acc, v| acc + v.len());
// Gas startup costs (for spinning up the VM)
let gas_cost = (GAS_PER_BYTE * args_bytes_total as u64) + GAS_STARTUP;
if gas_cost < gas_limit {
set_remaining_points(&mut context.wasm_store, &wasmer_instance, gas_limit - gas_cost);
} else {
set_remaining_points(&mut context.wasm_store, &wasmer_instance, 0);
}
However, this occurs quite late in the process, right before the tally function call, after several computationally expensive operations - such as creating the runtime, instantiating the environment and module, and allocating memory - have already been executed.
Internal Pre-conditions
None
External Pre-conditions
None
Attack Path
An attacker can post data requests with a gas limit sufficient for the data request and filtering phases but leaving zero or nearly zero gas for the tallying phase. This triggers the internal_run_vm() function to spin up the VM completely, only to stop execution immediately when the first metered operation is executed due to gas exhaustion. This makes such attacks cheaper than expected.
Impact
DoS attack, chain slowdown.
PoC
No response
Mitigation
Do not start tally phase execution if the remaining gas is not enough for the VM spin-up.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-wasm-vm/pull/68
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
Likely, the gas for VM startup is deducted after the VM is created and initialised, rather than before, allowing an attacker to trigger the expensive startup with insufficient gas for the tally phase.
Impact
A denial-of-service attack could occur, causing chain slowdown, as the attack is cheaper than expected.
What the attacker needed
Ability to post data requests
The fix
The protocol team fixed this issue by not starting tally phase execution if the remaining gas is insufficient for VM spin-up.
How it was found
- Post a data request with a gas limit sufficient for the data request and filtering phases but leaving zero or nearly zero gas for the tallying phase.
- The system calls internal_run_vm() and spins up the VM completely.
- Execution stops immediately when the first metered operation runs due to gas exhaustion.
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.
In blockchain systems, users pay gas to run code. This report says the system charges for starting a virtual machine (VM) only after it has already done a lot of work. An attacker can set the gas just high enough to pass earlier steps but too low for the final step, so the VM starts and then stops, wasting resources and slowing the chain.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.