dusk-network / piecrust

General purpose virtual machine for running WASM smart contracts
Mozilla Public License 2.0
22 stars 13 forks source link

Make storage instructions cost #361

Closed ureeves closed 4 months ago

ureeves commented 4 months ago

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: https://github.com/dusk-network/piecrust/issues/359

herr-seppia commented 4 months ago

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 commented 4 months ago

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.