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

Lesson 07 / Verification

Two paths, one result

Check both paths through an if. The test value is 1, so a run would choose the first path. The if promises one i32 where the paths meet. A control-flow graph, or CFG, is a drawing of where execution can go. Each arrow carries the types a path leaves on the stack. Trace both paths to decide whether the program can run.

+ Figure 07
Two arms diverge at a condition and meet at the result check.
Two arrows into the same join

1 · The big idea

Why is WebAssembly verification fast enough to run on every browser page load? Because WebAssembly’s structured control flow (block, loop, if/else/end) lets a browser verify an entire module in a single linear pass—reading each byte once and throwing it away!

Traditional compilers (and Java’s JVM verifier) often use a two-pass control-flow graph (CFG): Pass 1 maps every branch arrow between basic blocks; Pass 2 propagates type stacks along every arrow and checks that paths meeting at a join point agree on the exact same types.

Crucially, both designs check every possible path—even an else arm that a constant condition 1 would skip at runtime!

2 · Worked step-by-step example

Step-by-step worked trace for lesson 7Both Arms of if/else Must Match Promised [i32] Join ShapeThen arm: 7 (i32)Matches [i32]Else arm: 8 (f64)[f64] != [i32] -> REJECTJoin expects [i32]Then + 1 -> i32.addChange else value to i32.const 8 so both incoming paths agree.
Worked Example: Condition = 1, Then = i32, Else = f64
  1. Condition i32.const 1 enters if (results: i32).
  2. Then arm: pushes 7 (i32) → matches promised [i32].
  3. Else arm: pushes 8 (f64) → verifier checks [f64] against promised [i32] → rejected!
  4. Even though runtime condition 1 would never enter else, static verification checks all paths before running.
Result: Both single-pass and two-pass CFG verifiers reject the mismatched else arm before execution begins.

Read the case

Condition 1 → then: push 7 i32 → join

Condition 0 → else: push 8 f64 → join

Join requires [i32] → push 1 → i32.add

3 · Bytecode stepper (explore before quizzing)

A single-pass validator reads each instruction once. It checks the first arm at else and the second at end, using the saved label. A two-pass CFG design first builds the arrows. It then carries type lists along them and checks that incoming lists agree at each join. Both designs find the bad else path in this example.

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 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

if2 / 6

Open if at stack height 0.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0if 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.const3 / 6

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32

Control label stack innermost at right

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

else4 / 6

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

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

f64.const5 / 6

Push the type f64.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

f64

Control label stack innermost at right

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

end6 / 6

Type mismatch: expected i32, found f64.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack before rejection · top at right

f64

Control label stack innermost at right

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

Types rejected

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

Compare the two-pass graph check

Pass 1 builds the arrows. From the condition, one arrow reaches instruction 02 and the other reaches 04. Both paths then join before instruction 06.

Pass 2 compares what each arrow carries with the promised i32. The test value 1 selects a path only when the program runs.

Incoming pathStack at joinMatch
Then[i32]yes
Else[f64]no

4 · Make a prediction

A run would take the then path. Can this program pass the verifier?

Compare your prediction. The checker reads both arms. The else path carries f64 to an exit that promises i32.

Prediction confirmed. At end, the else arm must leave one i32. Its f64 fails even though the constant condition selects the other arm.

Compare your prediction. Only one arm runs on a given path. The checker compares each arm’s result shape with the same promise.

5 · Repair the program

Make both arms keep their numeric values and satisfy the join. The final add must produce an i32.
Inspect this edit. Changing the chosen arrow leaves the else path’s type unchanged. Both paths still face the same check.
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 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

if2 / 6

Open if at stack height 0.

Bytecode instruction address

  1. 00i32.const 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0if 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.const3 / 6

Push the type i32.

Bytecode instruction address

  1. 00i32.const 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32

Control label stack innermost at right

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

else4 / 6

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00i32.const 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

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

f64.const5 / 6

Push the type f64.

Bytecode instruction address

  1. 00i32.const 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

f64

Control label stack innermost at right

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

end6 / 6

Type mismatch: expected i32, found f64.

Bytecode instruction address

  1. 00i32.const 0
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack before rejection · top at right

f64

Control label stack innermost at right

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

Types rejected

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

Compare the two-pass graph check

Pass 1 builds the arrows. From the condition, one arrow reaches instruction 02 and the other reaches 04. Both paths then join before instruction 06.

Pass 2 compares what each arrow carries with the promised i32. The test value 0 selects a path only when the program runs.

Incoming pathStack at joinMatch
Then[i32]yes
Else[f64]no
Inspect this edit. Now the first arm fails at else: 7 has type i32. The instruction after the join also needs an integer.
Types rejectedRun blockedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 4

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

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → f64
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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 / 4

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → f64
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

if2 / 4

Open if at stack height 0.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → f64
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0if 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.const3 / 4

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → f64
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32

Control label stack innermost at right

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

else4 / 4

Type mismatch: expected f64, found i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → f64
  3. 02i32.const 7
  4. 03else
  5. 04f64.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack before rejection · top at right

i32

Control label stack innermost at right

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

Types rejected

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

Compare the two-pass graph check

Pass 1 builds the arrows. From the condition, one arrow reaches instruction 02 and the other reaches 04. Both paths then join before instruction 06.

Pass 2 compares what each arrow carries with the promised f64. The test value 1 selects a path only when the program runs.

Incoming pathStack at joinMatch
Then[i32]no
Else[f64]yes
Repair confirmed. Both arrows now carry a single i32. At runtime the condition chooses 7, then the add returns 8.
Types acceptedRun finishedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 8

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

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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 / 8

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

if2 / 8

Open if at stack height 0.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0if 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.const3 / 8

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32

Control label stack innermost at right

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

else4 / 8

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0else 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.const5 / 8

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32

Control label stack innermost at right

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

end6 / 8

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

i32.const7 / 8

Push the type i32.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32i32

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.add8 / 8

Check two i32 inputs. Push one i32 result.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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.

Types accepted
Instruction step
Ready0 / 7

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

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

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 / 7

Push the value 1.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 1

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.

if2 / 7

Enter the if body.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0if 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.const3 / 7

Push the value 7.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 7

Control label stack innermost at right

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

else4 / 7

The first arm finished. Skip the other arm.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 7

Control label stack innermost at right

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

end5 / 7

Leave the if with its result values.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 7

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.const6 / 7

Push the value 1.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 7i32 1

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.add7 / 7

Add 7 and 1.

Bytecode instruction address

  1. 00i32.const 1
  2. 01if → i32
  3. 02i32.const 7
  4. 03else
  5. 04i32.const 8
  6. 05end
  7. 06i32.const 1
  8. 07i32.add

Operand stack top at right

i32 8

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.

Run finished
Compare the two-pass graph check

Pass 1 builds the arrows. From the condition, one arrow reaches instruction 02 and the other reaches 04. Both paths then join before instruction 06.

Pass 2 compares what each arrow carries with the promised i32. The test value 1 selects a path only when the program runs.

Incoming pathStack at joinMatch
Then[i32]yes
Else[i32]yes

Code workshop

Implement agrees in my-rules.mjs. Compare every incoming type list with the list promised at the join. 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 7 ./my-rules.mjs
Optional worked example in a separate file

Model the second pass for this join. Run the check with both incoming lists. Change the else list to make it pass.

function agrees(incoming, expected) {
  return incoming.every(path =>
    path.length === expected.length &&
    path.every((type, i) => type === expected[i]))
}
console.log(agrees([["i32"], ["f64"]], ["i32"]))

The comparison returns false. In a streaming checker, use the same comparison on each arm as it closes. The surrounding label already holds the expected list, so this check can run without storing the arrows.

Key Takeaway & Next Up

WebAssembly’s structured labels enable fast single-pass verification that catches type mismatches on every reachable path—including untaken if/else arms.

Next: Finally, put everything together to audit and patch a brand-new plugin before sign-off!