Skip to content

core: Add Cranelift WasmTarget variants for Stylus overflow fallback#645

Merged
eljobe merged 9 commits intomasterfrom
nm004-config-stylus-stack-size
Apr 10, 2026
Merged

core: Add Cranelift WasmTarget variants for Stylus overflow fallback#645
eljobe merged 9 commits intomasterfrom
nm004-config-stylus-stack-size

Conversation

@bragaigor
Copy link
Copy Markdown
Contributor

@bragaigor bragaigor commented Mar 31, 2026

When a Stylus program overflows the native (Singlepass) coroutine stack, Nitro recompiles it with Cranelift as a fallback. The Cranelift ASM needs to be stored separately from the Singlepass ASM in the wasm store so both remain available — normal execution uses Singlepass, and only the overflow retry path uses Cranelift.

  • Add three new WasmTarget constants: TargetArm64Cranelift, TargetAmd64Cranelift, TargetHostCranelift
  • Add corresponding wasm store key prefixes ({0x00, 'c', 'r/x/h'}) separate from the existing Singlepass prefixes ({0x00, 'w', 'r/x/h'}), included in WasmPrefixesExceptWavm()
  • Add helper functions: CraneliftTarget(), BaseTarget(), IsCraneliftTarget(), SplitAsmMap(), DeduplicateAsmMap(), DeleteActivatedAsm()
  • ActivateWasm: deduplicate cranelift entries into base targets for the consistency check via DeduplicateAsmMap, then eagerly persist cranelift entries to the wasm store under their own keys
  • Journal revert (wasmActivation) deletes eagerly-written cranelift entries from the wasm store on RevertToSnapshot
  • ActivatedAsmMap: fall back to cranelift ASM when singlepass is missing for a requested target
  • Add unit tests for all new rawdb helpers and for the activation/revert path in StateDB

pulled in by OffchainLabs/nitro#4538

- Add three new WasmTarget constants for Cranelift-compiled ASM
- Add CraneliftTarget() helper to map a platform target to its Cranelift

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Comment thread core/state/statedb_arbitrum.go Outdated
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
as far as ActivateWasm goes we activate every wasm
program regardless of architecture

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
}
}

func TestActivateWasmRevert(t *testing.T) {
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.

lightweight test that now validates the new behavior (cranelift entries stored alongside singlepass). I think it's nice to have a test to make sure activation and revert happens for both.

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@eljobe eljobe merged commit 975117a into master Apr 10, 2026
16 checks passed
@eljobe eljobe deleted the nm004-config-stylus-stack-size branch April 10, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants