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

Lesson 08 / Verification

Sign off on a new plug-in

A new plug-in must get 42 back from a host function and save it in the last four bytes of a page. Audit the instructions before approving the change. Predict the first failure. Then choose a patch that completes exactly one call and puts 42 at the promised address.

+ Figure 08
Select a slot, call its host function, then write its result.
The change under review

1 · The big idea

In a real plugin audit, a broken module often has more than one bug—and the first runtime trap hides the second defect right behind it!

To sign off safely, trace two gates independently: first check the indirect call (does the table slot hold a function matching the requested (i32) → (i32) signature?); second check the linear-memory store (does base + offset plus 4 bytes fit strictly inside 0..65535?).

Remember how i32.store uses stack items: it expects [address, value] underneath, so leaving 65530 on the stack while call_indirect transforms 42 through echo32 sets up the exact inputs needed by the final store.

2 · Worked step-by-step example

Step-by-step worked trace for lesson 8Audit Plugin: Fix Table Slot (0 = echo32) AND Store Offset (2)Original: slot 1, off 3echo64 traps (0 calls)Partial: slot 0, off 31 call, traps @ 65536Patch: slot 0, off 21 call, 1 write @ 65532Writes 2a 00 00 00 (42) into bytes 65532..65535 and finishes cleanly.
Worked Example: Tracing Both Defects in the Plugin Under Review
  1. Stack before call: [65530 (addr), 42 (arg), 1 (slot)]. Table: 0 → echo32, 1 → echo64.
  2. Defect 1 (Call): Slot 1 points to echo64, which rejects requested (i32) → (i32) → traps with 0 calls and 0 writes!
  3. Partial fix (Slot 0, keep offset 3): echo32 returns 42 (1 call), then 65530 + 3 = 65533 tries writing 65533..65536 → traps on byte 65536 (0 writes)!
  4. Complete fix (Slot 0, offset 2): echo32 runs (1 call) and store writes 42 into 65532..65535 (1 write, status done).
Result: Fixing both the table slot (0) and store offset (2) achieves 1 call, 1 write, and clean completion.

Read the case

Stack before call: [65530 address, 42 argument, 1 slot]

Table: 0 → echo32, 1 → echo64

Requested signature: i32 in, i32 out

Store: base 65530, offset 3, width 4, page size 65536

3 · Bytecode stepper (explore before quizzing)

An earlier stop can hide a second defect. Trace the call count and the memory range separately. The accepted patch has to deliver the result to the caller’s promised address.

Bytecode is the list of machine instructions below. Step through Check types and Run values before answering the prediction below.

Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.const2 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.const3 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32i32i32

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.

call_indirect4 / 5

Check the table index and argument types. The selected slot is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.store5 / 5

Check the address and value types. The actual address is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.

Types accepted
Instruction step
Ready0 / 4

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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

Push the value 65530.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530

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

Push the value 42.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42

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

Push the value 1.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42i32 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.

call_indirect4 / 4

Indirect call signature mismatch at slot 1 (echo64).

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42i32 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.

Run trapped

4 · Make a prediction

Which check stops the original program first?

Prediction confirmed. The stack satisfies the requested signature. Slot 1 supplies echo64, so the runner stops at the call. Inspect whether the later write would fit before choosing a patch.

Compare your prediction. call_indirect takes the slot and argument from the top. The address can stay underneath for the store.

Compare your prediction. The store would cross the page edge, but execution reaches the table lookup first. Find which function occupies slot 1.

5 · Repair the program

Choose a patch. Verify the call, the exact byte range, and the value left in the last four bytes.
Inspect this edit. echo32 returns 42. The store then requests bytes 65533 through 65536. One call completed and zero writes completed.
Types acceptedRun trappedCalls 1Writes 0
Step through this edit
Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.const2 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.const3 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32i32i32

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.

call_indirect4 / 5

Check the table index and argument types. The selected slot is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.store5 / 5

Check the address and value types. The actual address is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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.

Types accepted
Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530

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.const2 / 5

Push the value 42.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42

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.const3 / 5

Push the value 0.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42i32 0

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.

call_indirect4 / 5

Slot 0 matches. echo32 returns its argument.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42

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.store5 / 5

Memory access out of bounds: [65533, 65537) exceeds 65536 bytes.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=3 align=1

Operand stack top at right

i32 65530i32 42

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+

Base 65530 + offset 3 = 65533. Four bytes need [65533, 65537). The end exceeds 65536. No bytes move.

Run trapped
Repair confirmed. echo32 runs once. The store writes 65532 through 65535. Read 2a 00 00 00 from low to high address, the four-byte encoding of 42.
Types acceptedRun finishedCalls 1Writes 1
Step through this edit
Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.const2 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.const3 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32i32i32

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.

call_indirect4 / 5

Check the table index and argument types. The selected slot is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.store5 / 5

Check the address and value types. The actual address is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.

Types accepted
Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530

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.const2 / 5

Push the value 42.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42

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.const3 / 5

Push the value 0.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42i32 0

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.

call_indirect4 / 5

Slot 0 matches. echo32 returns its argument.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42

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.store5 / 5

The entire range fits. Store four bytes, least significant byte first.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 0
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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
2A65532
0065533
0065534
0065535
×65536+

Base 65530 + offset 2 = 65532. Four bytes need [65532, 65536). The whole range fits.

Run finished
Inspect this edit. The proposed range fits. Execution still stops at the incompatible echo64 function, before the corrected store can run.
Types acceptedRun trappedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 5

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.const2 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.const3 / 5

Push the type i32.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32i32i32

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.

call_indirect4 / 5

Check the table index and argument types. The selected slot is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.store5 / 5

Check the address and value types. The actual address is checked during execution.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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.

Types accepted
Instruction step
Ready0 / 4

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

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

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

Push the value 65530.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530

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

Push the value 42.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42

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

Push the value 1.

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42i32 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.

call_indirect4 / 4

Indirect call signature mismatch at slot 1 (echo64).

Bytecode instruction address

  1. 00i32.const 65530
  2. 01i32.const 42
  3. 02i32.const 1
  4. 03call_indirect (i32) → i32
  5. 04i32.store offset=2 align=1

Operand stack top at right

i32 65530i32 42i32 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.

Run trapped

Code workshop

Implement audit in my-rules.mjs. Use your requireSlot and fits32 functions in execution order. Return the status and the number of completed calls and writes. 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 8 ./my-rules.mjs
Optional worked example in a separate file

Test your sign-off against the supplied engine. Save this as audit.mjs next to lessons.js and wasm-verifier.js. Run node audit.mjs.

import { analyze } from "./wasm-verifier.js"
import { lessons } from "./lessons.js"
const exam = lessons[7]
for (const patch of exam.repairs) {
  const { validation, runtime } = analyze(patch.program)
  console.log(validation.ok, runtime.status, runtime.calls, runtime.writes)
}

Find the only row with a completed run, one call and one write. Inside the loop, when runtime.status equals "done", make a copy with const changed = structuredClone(patch.program). Increase changed.code[0].value by one. Pass changed to analyze. Predict which count changes and whether the run finishes, then run your test again.

Key Takeaway & Next Up

Auditing sandboxed Wasm code requires verifying static stack shapes, indirect call signatures, and widened memory bounds end to end.

Next: Experiment with your own decoded instruction streams in the Edit Bytecode console below!