Fieldbooks / WebAssembly / Lesson 04
Lesson 04 of 08 · Course index 00 Start Here: What & WhyStack & control 01 Jump or trap?02 Stack types03 Branch targets04 Unreachable code→ Memory & calls 05 Page bounds06 Indirect callsVerification 07 Two verifier designs08 Transfer exam Lesson 04 / Stack & control
How far can an empty stack reach? Find the limit of the skipped-add rule. The stack holds 11 when a block begins. Inside, the program pushes 9 and jumps to the exit. The verifier keeps reading the skipped instructions. One of them puts a floating-point 1 on the stack before an integer add.
+ Figure 04
The block’s entry height is one
i
1 · The big idea In Chapter 1, an empty stack after br 0 let i32.add pass validation. Does that mean anything after br, return, or unreachable is blindly accepted?
No! Every container records its entry stack height (the number of values sitting below it when the container opened). Instructions inside that block can never pop below that saved floor, and any concrete value pushed above the floor still carries its real type!
Only when the stack sits right at the unreachable floor does a missing operand turn polymorphic (matching whatever type is asked). If the dead code pushes a real f32 and then runs i32.add, the concrete f32 on top still fails the i32 check!
→
2 · Worked step-by-step example Step-by-step worked trace for lesson 4 Entry Height Floor = 1 ([11 i32] Protected Below Line) Floor h=1 [11 i32] safe br 0 -> f32.const 1 Stack: [11 i32 | 1 f32] i32.add sees f32! Concrete mismatch -> REJECT Only missing items at the floor are polymorphic; real f32 above it fails. Worked Example: Protected i32 (11) Below the Block Floor
Push i32.const 11 → stack is [i32] (height = 1). Open block (floor saved at height 1). Inside block: push i64.const 9, then execute br 0. Verifier resets the block’s stack back to floor 1 and marks it unreachable. Next dead instruction pushes f32.const 1 → stack is [i32 | f32] (1 concrete item above the floor!). Dead i32.add pops top item: it finds concrete f32 instead of i32 → verifier rejects! Replacing f32.const 1 with i32.const 1 pops i32 + polymorphic placeholder and passes. Result: Unreachable polymorphism only invents missing inputs at the block’s floor—it never ignores known concrete types pushed after the jump.
Read the case On entry: [11 i32] | block starts here
Before jump: [11 i32] | [9 i64]
After jump in the checker: [11 i32] | []
Next push in skipped code: [11 i32] | [1 f32]
≡
3 · Bytecode stepper (explore before quizzing) br and return transfer control. The instruction named unreachable traps if executed. All three reset the verifier’s stack to the current region’s entry height and mark the remaining path unreachable. A later push still supplies a concrete type. At end, the enclosing region’s rules resume.
Bytecode is the list of machine instructions below. Step through Check types and Run values before answering the prediction below.
Check types Instruction step Step 0Ready 0 / 6
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
Step forward →
Step 1i32.const 1 / 6
Push the type i32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 2block 2 / 6
Open block at stack height 1.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 3i64.const 3 / 6
Push the type i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i64
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 4br 4 / 6
Check the block target. Reset to entry height 1. This path cannot reach the next instruction.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 5f32.const 5 / 6
Push the type f32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 f32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 6i32.add 6 / 6
Type mismatch: expected i32, found f32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack before rejection · top at right i32 f32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Types rejected
Run values Execution is blocked. Type mismatch: expected i32, found f32.
?
4 · Make a prediction Can the skipped i32.add accept the f32 that the verifier has just seen? ↗
5 · Repair the program Keep the value 11 for the function to return. Make the skipped add pass its type check. Push i32 1 in the skipped code Repair confirmed. The add takes the concrete i32, then a missing i32 at the line. The runner skips both. Return sends the preserved 11 back to the caller.
Types accepted Run finished Calls 0 Writes 0
Step through this edit Check types Instruction step Step 0Ready 0 / 11
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
Step forward →
Step 1i32.const 1 / 11
Push the type i32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 2block 2 / 11
Open block at stack height 1.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 3i64.const 3 / 11
Push the type i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i64
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 4br 4 / 11
Check the block target. Reset to entry height 1. This path cannot reach the next instruction.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 5i32.const 5 / 11
Push the type i32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 6i32.add 6 / 11
Check two i32 inputs. Push one i32 result. At the unreachable floor, 1 missing input(s) may have the requested type.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 7drop 7 / 11
Remove one value of any type.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 8end 8 / 11
Close this label. Restore its declared result types.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 9return 9 / 11
Check the function results. Reset to entry height 0. This path cannot reach the next instruction.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 10i32.add 10 / 11
Check two i32 inputs. Push one i32 result. At the unreachable floor, 2 missing input(s) may have the requested type.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 11drop 11 / 11
Remove one value of any type.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Types accepted
Run values Instruction step Step 0Ready 0 / 5
Start with an empty stack and one page of zero bytes.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
Step forward →
Step 1i32.const 1 / 5
Push the value 11.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 11
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
← Back Step forward →
Step 2block 2 / 5
Enter the block body.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 11
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
← Back Step forward →
Step 3i64.const 3 / 5
Push the value 9.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 11 i64 9
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
← Back Step forward →
Step 4br 4 / 5
Carry the result values to the exit of this block.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 11
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
← Back Step forward →
Step 5return 5 / 5
Carry the result values to the exit of this function.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 11
Control label stack innermost at right [ ] Exited
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.
← Back Run finished
Replace br with unreachable Inspect this edit. unreachable also resets the height. The next push still supplies f32 and the verifier still rejects the add.
Types rejected Run blocked Calls 0 Writes 0
Step through this edit Check types Instruction step Step 0Ready 0 / 6
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
Step forward →
Step 1i32.const 1 / 6
Push the type i32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 2block 2 / 6
Open block at stack height 1.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 3i64.const 3 / 6
Push the type i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i64
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 4unreachable 4 / 6
Reset to entry height 1. This path cannot reach the next instruction.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 5f32.const 5 / 6
Push the type f32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 f32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 6i32.add 6 / 6
Type mismatch: expected i32, found f32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 unreachable04 f32.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack before rejection · top at right i32 f32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Types rejected
Run values Execution is blocked. Type mismatch: expected i32, found f32.
Push i64 1 in the skipped code Inspect this edit. A whole number of a different width is still a known type. The add requests i32.
Types rejected Run blocked Calls 0 Writes 0
Step through this edit Check types Instruction step Step 0Ready 0 / 6
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right [ ] Empty
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
Step forward →
Step 1i32.const 1 / 6
Push the type i32.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 2block 2 / 6
Open block at stack height 1.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 3i64.const 3 / 6
Push the type i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i64
Control label stack innermost at right function h=0 block h=1
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 4br 4 / 6
Check the block target. Reset to entry height 1. This path cannot reach the next instruction.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 5i64.const 5 / 6
Push the type i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack top at right i32 i64
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Step forward →
Step 6i32.add 6 / 6
Type mismatch: expected i32, found i64.
Bytecode instruction address 00 i32.const 1101 block02 i64.const 903 br 004 i64.const 105 i32.add06 drop07 end08 return09 i32.add10 dropOperand stack before rejection · top at right i32 i64
Control label stack innermost at right function h=0 block h=1 · unreachable
Each label keeps its entry height (h = stack height when the block opened).
Linear memory Tail of page 0 – 65528
– 65529
– 65530
– 65531
– 65532
– 65533
– 65534
– 65535
× 65536+
Type checking does not read or write bytes.
← Back Types rejected
Run values Execution is blocked. Type mismatch: expected i32, found i64.
{ }
Code workshop Implement takeAtFloor in my-rules.mjs. Keep every value below the saved height. Only a missing input at an unreachable floor can match any type. The first command makes your own copy of the starter if needed. Edit the named function, then run the second command.
cp -n workshop/starter.mjs my-rules.mjs
node workshop/check.mjs 4 ./my-rules.mjsOptional worked example in a separate file Add the reset rule. Give it a stack containing the protected i32 and a temporary i64. Inspect both the shortened stack and the frame, the record for this block.
function markDead(stack, frame) {
stack.length = frame.height
frame.unreachable = true
}
const types = ["i32", "i64"]
const frame = { height: 1, unreachable: false }
markDead(types, frame)
console.log(types, frame)The i32 survives. When adapting take, return the requested type without popping only when the stack is exactly at the height and the frame is unreachable. Check every concrete value above the height.
Key Takeaway & Next Up Block entry heights act as a protective floor: unreachable code cannot pop below it, and any concrete types pushed above it are still strictly type-checked.
Next: Next, we inspect how WebAssembly enforces 64 KiB linear-memory walls without 32-bit wraparound exploits.
Edit the bytecode Change the numbered inputs or instructions and run the checker again. Each run starts with a fresh page. This editor accepts a JSON object containing the decoded instructions.
Program Check and run
Free to Learn: Build a WebAssembly Stack-Machine Verifier & Linear-Memory Sandbox Lab