Fieldbooks / WebAssembly / Lesson 08
Lesson 08 of 08 · Course index 00 Start Here: What & WhyStack & control 01 Jump or trap?02 Stack types03 Branch targets04 Unreachable codeMemory & calls 05 Page bounds06 Indirect callsVerification 07 Two verifier designs08 Transfer exam→ 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
The change under review
i
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 8 Audit Plugin: Fix Table Slot (0 = echo32) AND Store Offset (2) Original: slot 1, off 3 echo64 traps (0 calls) Partial: slot 0, off 3 1 call, traps @ 65536 Patch: slot 0, off 2 1 call, 1 write @ 65532 Writes 2a 00 00 00 (42) into bytes 65532..65535 and finishes cleanly. Worked Example: Tracing Both Defects in the Plugin Under Review
Stack before call: [65530 (addr), 42 (arg), 1 (slot)]. Table: 0 → echo32, 1 → echo64. Defect 1 (Call): Slot 1 points to echo64, which rejects requested (i32) → (i32) → traps with 0 calls and 0 writes!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)!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.
Check types Instruction step Step 0Ready 0 / 5
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 2i32.const 2 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 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 3i32.const 3 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 i32 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 4call_indirect 4 / 5
Check the table index and argument types. The selected slot is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 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 5i32.store 5 / 5
Check the address and value types. The actual address is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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.
← Back Types accepted
Run values Instruction step Step 0Ready 0 / 4
Start with an empty stack and one page of zero bytes.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 / 4
Push the value 65530.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 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 2i32.const 2 / 4
Push the value 42.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 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 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 3i32.const 3 / 4
Push the value 1.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 42 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 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 4call_indirect 4 / 4
Indirect call signature mismatch at slot 1 (echo64).
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 42 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 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 trapped
?
4 · Make a prediction Which check stops the original program first? ↗
5 · Repair the program Choose a patch. Verify the call, the exact byte range, and the value left in the last four bytes. Select slot 0 and keep offset 3 Inspect this edit. echo32 returns 42. The store then requests bytes 65533 through 65536. One call completed and zero writes completed.
Types accepted Run trapped Calls 1 Writes 0
Step through this edit Check types Instruction step Step 0Ready 0 / 5
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 2i32.const 2 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 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 3i32.const 3 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 i32 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 4call_indirect 4 / 5
Check the table index and argument types. The selected slot is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 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 5i32.store 5 / 5
Check the address and value types. The actual address is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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.
← 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 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 65530.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand 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 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 2i32.const 2 / 5
Push the value 42.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 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 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 3i32.const 3 / 5
Push the value 0.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 42 i32 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 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 4call_indirect 4 / 5
Slot 0 matches. echo32 returns its argument.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 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 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 5i32.store 5 / 5
Memory access out of bounds: [65533, 65537) exceeds 65536 bytes.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=3 align=1Operand stack top at right i32 65530 i32 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 00 65528
00 65529
00 65530
00 65531
00 65532
00 65533
00 65534
00 65535
× 65536+
Base 65530 + offset 3 = 65533. Four bytes need [65533, 65537). The end exceeds 65536. No bytes move.
← Back Run trapped
Select slot 0 and set offset 2 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 accepted Run finished Calls 1 Writes 1
Step through this edit Check types Instruction step Step 0Ready 0 / 5
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 2i32.const 2 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 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 3i32.const 3 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 i32 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 4call_indirect 4 / 5
Check the table index and argument types. The selected slot is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 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 5i32.store 5 / 5
Check the address and value types. The actual address is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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.
← 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 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 65530.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 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 2i32.const 2 / 5
Push the value 42.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 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 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 3i32.const 3 / 5
Push the value 0.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 42 i32 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 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 4call_indirect 4 / 5
Slot 0 matches. echo32 returns its argument.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 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 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 5i32.store 5 / 5
The entire range fits. Store four bytes, least significant byte first.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 003 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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
2A 65532
00 65533
00 65534
00 65535
× 65536+
Base 65530 + offset 2 = 65532. Four bytes need [65532, 65536). The whole range fits.
← Back Run finished
Keep slot 1 and set offset 2 Inspect this edit. The proposed range fits. Execution still stops at the incompatible echo64 function, before the corrected store can run.
Types accepted Run trapped Calls 0 Writes 0
Step through this edit Check types Instruction step Step 0Ready 0 / 5
Start with an empty stack. Read the instructions in order.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 2i32.const 2 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 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 3i32.const 3 / 5
Push the type i32.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 i32 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 4call_indirect 4 / 5
Check the table index and argument types. The selected slot is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 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 5i32.store 5 / 5
Check the address and value types. The actual address is checked during execution.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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.
← Back Types accepted
Run values Instruction step Step 0Ready 0 / 4
Start with an empty stack and one page of zero bytes.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 / 4
Push the value 65530.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand 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 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 2i32.const 2 / 4
Push the value 42.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 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 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 3i32.const 3 / 4
Push the value 1.
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 42 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 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 4call_indirect 4 / 4
Indirect call signature mismatch at slot 1 (echo64).
Bytecode instruction address 00 i32.const 6553001 i32.const 4202 i32.const 103 call_indirect (i32) → i3204 i32.store offset=2 align=1Operand stack top at right i32 65530 i32 42 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 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 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.mjsOptional 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!
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