wasmer-go icon indicating copy to clipboard operation
wasmer-go copied to clipboard

Gas Calculation per function

Open AchalaSB opened this issue 5 years ago • 5 comments

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

AchalaSB avatar Feb 11 '20 13:02 AchalaSB

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

AdamSLevy avatar Feb 13 '20 00:02 AdamSLevy

We can make it a higher priority. As @AdamSLevy said, we must first support middleware in the C API, then in Go.

Hywan avatar Feb 13 '20 14:02 Hywan

@Hywan Tell me, is there a plan to add this functionality?

Rathil avatar Sep 29 '21 07:09 Rathil

@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.

hnfgns avatar Jul 30 '22 00:07 hnfgns

Any update on this?

0xalank avatar Apr 04 '23 22:04 0xalank