WASI imports can be exploited for unmetered execution or unbounded memory growth
The WASI imports in the SEDA WASM VM are not metered, so an attacker can call them in a loop to consume CPU or memory without paying gas. This can delay block building and potentially halt the chain.
Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/249
Found by
g
Summary
All the WASI imports do not call apply_gas_cost(), so they do not do any metering. For example, fd_write does not do any metering. Any attacker can exploit this unmetered execution because there is no cost to the attacker. This impacts validators by draining their resources, whether CPU or memory, and can lead to chain delays or Chain Halts, in the worst case.
Root Cause
WASI objects are imported as-is direct from the WASI environment.
pub fn create_wasm_imports(
store: &mut Store,
vm_context: &FunctionEnv<VmContext>,
wasi_env: &WasiFunctionEnv,
wasm_module: &Module,
call_data: &VmCallData,
) -> Result<Imports> {
// @audit the WASI environment's import objects
let wasi_import_obj = wasi_env.import_object(store, wasm_module)?;
// ... snip ...
for allowed_import in allowed_imports.iter() {
// "env" is all our custom host imports
if let Some(found_export) = custom_imports.get_export("seda_v1", allowed_import) {
allowed_host_exports.insert(allowed_import.to_string(), found_export);
} else if let Some(wasi_version) = wasi_version {
// When we couldn't find a match in our custom import we try WASI imports
// WASI has different versions of compatibility so it depends how the WASM was
// build, that's why we use wasi_verison to determine the correct export
// @audit the WASI import objects are imported as-is
if let Some(found_export) = wasi_import_obj.get_export(wasi_version.get_namespace_str(), allowed_import) {
allowed_wasi_exports.insert(allowed_import.to_string(), found_export);
}
}
}
Since the WASI import objects are imported as-is, they do not do any metering. These imported functions must be wrapped in a new that applies gas metering.
Below is a list of all the WASI imports.
"args_get",
"args_sizes_get",
"proc_exit",
"fd_write",
"environ_get",
"environ_sizes_get",
Internal Pre-conditions
None
External Pre-conditions
None
Attack Path
- The Attacker creates a WASM program that exploits the unmetered execution of any WASI imports.
The program will call a WASI import in a loop for as long as gas is available (they only need to pay for the gas for the loop).
2. The Attacker then compiles the WASM program and deploys the binary via StoreOracleProgram().
3. The Attacker posts a Data Request that will execute their earlier deployed Tally Program.
4. Once the Data Request is for tallying, it will be processed in the Tally module's EndBlock().
5. When executing the Attacker's Tally Program, the unmetered execution can delay block building significantly.
This unmetered execution can be compounded by performing the same attack with many data requests, which can cause greater delays in block building.
Impact
Delay block building, possibly to the point of chain halt.
PoC
None
Mitigation
Consider wrapping WASI imports in import objects that call apply_gas_cost().
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-wasm-vm/pull/58
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
WASI imports are used directly without wrapping them in gas metering.
Impact
This could delay block building and potentially cause a chain halt.
What the attacker needed
Ability to deploy a WASM program; Ability to post a Data Request
The fix
The issue was fixed by wrapping WASI imports in import objects that call apply_gas_cost().
How it was found
- Create a WASM program that calls a WASI import in a loop.
- Compile and deploy the WASM program via StoreOracleProgram().
- Post a Data Request that executes the deployed Tally Program.
- The Data Request is processed in the Tally module's EndBlock().
- The unmetered execution delays block building.
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' for computation to prevent abuse. Here, certain system functions (WASI imports) were not charging gas, so an attacker could use them heavily for free, slowing down the network.
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.