Free to LearnSystems fieldbooksCode workshop
Fieldbooks/WebAssembly/Lesson 04
Lesson 04 of 08 · Course index

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
A stack with a saved value below the entry height and a temporary value above it.
The block’s entry height is one

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 4Entry Height Floor = 1 ([11 i32] Protected Below Line)Floor h=1[11 i32] safebr 0 -> f32.const 1Stack: [11 i32 | 1 f32]i32.add sees f32!Concrete mismatch -> REJECTOnly missing items at the floor are polymorphic; real f32 above it fails.
Worked Example: Protected i32 (11) Below the Block Floor
  1. Push i32.const 11 → stack is [i32] (height = 1). Open block (floor saved at height 1).
  2. Inside block: push i64.const 9, then execute br 0. Verifier resets the block’s stack back to floor 1 and marks it unreachable.
  3. Next dead instruction pushes f32.const 1 → stack is [i32 | f32] (1 concrete item above the floor!).
  4. 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.

Instruction step
Ready0 / 6

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

i32.const1 / 6

Push the type i32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

block2 / 6

Open block at stack height 1.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i64.const3 / 6

Push the type i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i64

Control label stack innermost at right

function h=0block 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.

br4 / 6

Check the block target. Reset to entry height 1. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

f32.const5 / 6

Push the type f32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32f32

Control label stack innermost at right

function h=0block 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.

i32.add6 / 6

Type mismatch: expected i32, found f32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack before rejection · top at right

i32f32

Control label stack innermost at right

function h=0block 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.

Types rejected

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?

Compare your prediction. The checker has a concrete top type. Pop f32 and compare its label with the requested i32.

Compare your prediction. The line is the height on entry. Pops in this block cannot cross it. The first pop sees the f32 above it.

Prediction confirmed. Only a missing input at the entry height can match any type. A real f32 above that height must match the requested type.

5 · Repair the program

Keep the value 11 for the function to return. Make the skipped add pass its type check.
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 acceptedRun finishedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 11

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

i32.const1 / 11

Push the type i32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

block2 / 11

Open block at stack height 1.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i64.const3 / 11

Push the type i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i64

Control label stack innermost at right

function h=0block 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.

br4 / 11

Check the block target. Reset to entry height 1. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i32.const5 / 11

Push the type i32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i32

Control label stack innermost at right

function h=0block 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.

i32.add6 / 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

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i32

Control label stack innermost at right

function h=0block 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.

drop7 / 11

Remove one value of any type.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

end8 / 11

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

return9 / 11

Check the function results. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

i32.add10 / 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

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

drop11 / 11

Remove one value of any type.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

Types accepted
Instruction step
Ready0 / 5

Start with an empty stack and one page of zero bytes.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const1 / 5

Push the value 11.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

block2 / 5

Enter the block body.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32 11

Control label stack innermost at right

function h=0block h=1

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i64.const3 / 5

Push the value 9.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32 11i64 9

Control label stack innermost at right

function h=0block h=1

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br4 / 5

Carry the result values to the exit of this block.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

return5 / 5

Carry the result values to the exit of this function.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

Run finished
Inspect this edit. unreachable also resets the height. The next push still supplies f32 and the verifier still rejects the add.
Types rejectedRun blockedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 6

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

i32.const1 / 6

Push the type i32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

block2 / 6

Open block at stack height 1.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i64.const3 / 6

Push the type i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i64

Control label stack innermost at right

function h=0block 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.

unreachable4 / 6

Reset to entry height 1. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

f32.const5 / 6

Push the type f32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32f32

Control label stack innermost at right

function h=0block 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.

i32.add6 / 6

Type mismatch: expected i32, found f32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03unreachable
  5. 04f32.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack before rejection · top at right

i32f32

Control label stack innermost at right

function h=0block 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.

Types rejected

Execution is blocked. Type mismatch: expected i32, found f32.

Inspect this edit. A whole number of a different width is still a known type. The add requests i32.
Types rejectedRun blockedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 6

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

i32.const1 / 6

Push the type i32.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand 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.

block2 / 6

Open block at stack height 1.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i64.const3 / 6

Push the type i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i64

Control label stack innermost at right

function h=0block 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.

br4 / 6

Check the block target. Reset to entry height 1. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32

Control label stack innermost at right

function h=0block 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.

i64.const5 / 6

Push the type i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack top at right

i32i64

Control label stack innermost at right

function h=0block 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.

i32.add6 / 6

Type mismatch: expected i32, found i64.

Bytecode instruction address

  1. 00i32.const 11
  2. 01block
  3. 02i64.const 9
  4. 03br 0
  5. 04i64.const 1
  6. 05i32.add
  7. 06drop
  8. 07end
  9. 08return
  10. 09i32.add
  11. 10drop

Operand stack before rejection · top at right

i32i64

Control label stack innermost at right

function h=0block 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.

Types rejected

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.mjs
Optional 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.