wasmer-go
wasmer-go copied to clipboard
Gas Calculation per function
Can we calculate Cost for each function using go-wasmer?( something like ethereum is doing)
Ex: if we are executing simple rust code to add two numbers, need to know the cost for +
operator.
I see there are implementation in wasmer/pull/450 But didn't get how exactly cost is calculating. where is cost table here? Is there any doc to understand this?
Thanks
The docs on metering are very sparse. The implementation in Rust is here: https://github.com/wasmerio/wasmer/blob/master/lib/middleware-common/src/metering.rs
That is some middleware that injects metering code at module compilation. This functionality is not exposed in either the Go or C APIs in the main release of wasmer and this library, unfortunately. It's not impossible to get it working though. A number of branches that are a little stale now, but work, are out there that implement the necessary APIs in the Rust -> C bridge and C -> Go bridge.
Another thing to be aware of is that the metering as currently implemented is buggy and can miss some functions that exceed the set limit. See https://github.com/wasmerio/wasmer/issues/999
We can make it a higher priority. As @AdamSLevy said, we must first support middleware in the C API, then in Go.
@Hywan Tell me, is there a plan to add this functionality?
@Hywan adding this to C runtime is a great idea. one can look at this issue as an important enhancement to the security model currently offered. hosts can prevent some attack vectors through this feature imo.
Any update on this?