Master

The host is a component

A module does not run alone. Something loads it, gives it memory, and decides what it may ask for, and that something is a component with its own limits.

What you will see

One line. Both limits exist before the run starts, which is the rule.

About 1 min of reading

Try It

Write the permission list

1

Write the imports allowed

printf 'clock\nrandom\n' > /tmp/i.txt; wc -l < /tmp/i.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. Two imports is the permission, and the permission is a file.
2

Check the module asks for more

printf 'clock\nrandom\nfs\n' > /tmp/i2.txt; comm -13 /tmp/i.txt /tmp/i2.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
fs. The module asks for something the host does not grant, which is a load failure.
3

Write the limit at load

printf 'max_memory_pages 512 fuel 1000000\n' > /tmp/l.txt; cat /tmp/l.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line. Both limits exist before the run starts, which is the rule.

Data Flow

A module to a bounded run
1 The contract file is written
↓
2 The host loads the module with limits
↓
3 The module runs against the imports
↓
4 A trap is caught and reported
Why this works
Why the host is written first

The host decides what the module may do. Writing the module first is writing a module for a host that does not exist.

The one artefact that must be shared

The contract file. Both sides are written against it, and it is the file that drifts.

Examples

Imports are the permission list

A module that imports a clock can ask for time. A module that imports nothing cannot, and the list is the whole permission.

The trap is the stop

A call that traps stops the module, not the host. The host must decide whether to reload or refuse.

Limits are set at load

Memory growth and fuel are set when the module is loaded. A limit set after is a limit that was already passed.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← When WASM is not worth it
Previous Lesson
When WASM is not worth it
Next Lesson
Debugging a module
Debugging a module →