Skip to content

fuel: Defer fuel consumption for bulk operations - #14213

Open
adamrk wants to merge 4 commits into
bytecodealliance:mainfrom
adamrk:defer-bulk-op-fuel-consumption
Open

fuel: Defer fuel consumption for bulk operations#14213
adamrk wants to merge 4 commits into
bytecodealliance:mainfrom
adamrk:defer-bulk-op-fuel-consumption

Conversation

@adamrk

@adamrk adamrk commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

For bulk operations and memory/table grows, defer consuming fuel until the operation has succeed.

This fixes #14161.

For small statically known sizes, we immediately consume fuel, but for larger or dynamic sizes we insert a fuel/epoch check before the operation and then only consume the variable fuel amount after.

adamrk added 2 commits August 26, 2026 10:07
For bulk operations and table/memory grows, wait until the operation has
succeeded to consume fuel. This prevents large operations that fail from
consuming fuel for work that doesn't actually occur.
@adamrk
adamrk requested review from a team as code owners August 26, 2026 15:00
@adamrk
adamrk requested review from cfallin and removed request for a team August 26, 2026 15:00
Comment thread tests/all/fuel.rs
i32.const 0
i32.const 65536
memory.copy
(loop)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're now consuming the fuel after the fuel check, a bunch of these tests need an additional fuel check inserted at the end to pass. The empty loop block does that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the fuel check move to after the operation instead of before the operation to handle this? That way while the fuel running out would be retroactively discovered it'd basically be the same thing and wouldn't need extra updates

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we can do that. I think it'll require changing some other tests which assert that we don't do a bulk operation if fuel is at 0 just before the op, but that seems fine to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that seems ok to me, a lot of the fuel tests are about precise behavior and it's ok to tweak them if the behavior is slightly adjusted as well

Comment thread tests/all/fuel.rs

#[wasmtime_test(wasm_features(memory64), strategies(not(Winch)))]
#[cfg_attr(miri, ignore)]
fn memory64_variable_operator_cost_saturates(config: &mut Config) -> Result<()> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do with these saturating fuel tests. Now that we only consume the fuel on a successful operation we shouldn't be able to actually hit the saturation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wast_tests fuzzbug: OOB bulk operations consume fuel

2 participants