design icon indicating copy to clipboard operation
design copied to clipboard

Determine Gas Price for opcodes

Open wanderer opened this issue 9 years ago • 7 comments

At some point we need to update the fee schedule with accurate gas prices. One way to do this would be to do is to see how many cycle each equivalent opcode takes on physical hardware.

wanderer avatar Aug 08 '16 17:08 wanderer

Appendix C of Architecture Optimization Manual (http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-optimization-manual.html) where cycles are called latency.

axic avatar Aug 08 '16 19:08 axic

Per pp. C-2:

Latency — The number of clock cycles that are required for the execution core to complete the execution of all of the μops that form an instruction.

Throughput — The number of clock cycles required to wait before the issue ports are free to accept the same instruction again. For many instructions, the throughput of an instruction can be significantly less than its latency.

axic avatar Aug 14 '16 17:08 axic

There is a draft available here: https://gist.github.com/axic/5bf506728005864461454dd4d37a7f37

axic avatar Aug 24 '16 22:08 axic

For what it's worth, as wasm is designed as a portable language, some virtual wasm instructions might be available as a single instruction on some archs and as a sequence of instructions on different archs. The biggest example I can think about right now is: all the int64 instructions. On 64-bits platforms (like intel x64, aarch64), they almost all map to a single assembly instruction, although on 32-bits platforms (like x86/ARM) they map to sequence of equivalent instructions.

I don't know what are the targeted archs for the ewasm VM, but worth noting in case you'd have wanted to support x86 and all. Possible alternatives I can think of, instead of a static arch-independent pricing:

  • arch-dependent pricing, but it sounds like metering should be hardware independent in general.
  • determine arch-dependent pricing for each platform, and then take an average of them (really, using any average function) to determine an arch-independent pricing. This seems a bit unfair to platforms that are not benchmarked first, but this should at least give a rought idea of what the pricing should look like.

bnjbvr avatar Oct 08 '16 10:10 bnjbvr

Thank you @bnjbvr. I am afraid we cannot introduce architecture dependent pricing at all.

axic avatar Oct 08 '16 11:10 axic

Regarding state operations. Here is some is the Approximate timing for disk reads compared to instuctions. http://norvig.com/21-days.html#answers

wanderer avatar Oct 09 '16 07:10 wanderer

See https://github.com/ewasm/design/blob/master/determining_wasm_gas_costs.md.

cdetrio avatar Mar 24 '19 12:03 cdetrio