Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make storage instructions cost #361

Merged
merged 2 commits into from
May 16, 2024
Merged

Make storage instructions cost #361

merged 2 commits into from
May 16, 2024

Conversation

ureeves
Copy link
Member

@ureeves ureeves commented May 15, 2024

Each byte stored in the WebAssembly linear memory of a contract is made to cost 4 units of fuel - in the units that wasmtime uses. This makes storing a single byte as expensive as, for example, multiplying or subtracting two numbers.

The MemoryGrow instruction is purposefully left with the default price - just like any other instruction, due the fact that expanding the size of the linear memory doesn't actually cost a lot of resources, owing to the fact that a page that is never written to is never written to disk.

A single contract's compiled bytecode will contain a header, encoding within it information about the cost per WebAssembly instruction. If these don't match the costs configured for the current VM instantiation, the contract will be recompiled, just as what happens if the native instruction set doesn't match.

See-also: #359

Eduardo Leegwater Simões added 2 commits May 15, 2024 22:28
Each byte stored in the WebAssembly linear memory of a contract is made
to cost 4 units of fuel - in the units that wasmtime uses. This makes
storing a single byte as expensive as, for example, multiplying or
subtracting two numbers.

The `MemoryGrow` instruction is purposefully left with the default price
- just like any other instruction, due the fact that expanding the size
of the linear memory doesn't actually cost a lot of resources, owing to
the fact that a page that is never written to is never written to disk.

A single contract's compiled bytecode will contain a header, encoding
within it information about the cost per WebAssembly instruction. If
these don't match the costs configured for the current `VM`
instantiation, the contract will be recompiled, just as what happens if
the native instruction set doesn't match.

See-also: #359
Copy link
Member

@HDauven HDauven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM!

@herr-seppia
Copy link
Member

A single contract's compiled bytecode will contain a header, encoding within it information about the cost per WebAssembly instruction

Is this part of the PR? I haven't found any change for this

@ureeves
Copy link
Member Author

ureeves commented May 16, 2024

A single contract's compiled bytecode will contain a header, encoding within it information about the cost per WebAssembly instruction

Is this part of the PR? I haven't found any change for this

No, it was a part of this one, and the reason why we had an upgrade of the dusk-wasmtime version during this PR.

@ureeves ureeves merged commit d352bda into main May 16, 2024
6 checks passed
@ureeves ureeves deleted the storage-costs branch May 16, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants