@@ -5,15 +5,19 @@ including CPU time and storage cost. It's unit is 1, i.e. you can think of it as
5
5
countable points. Gas consumption is deterministic, so executing the same thing
6
6
costs the same amount of gas across all hardware and operating systems.
7
7
8
+ ## CosmWasm gas vs. Cosmos SDK gas
9
+
8
10
CosmWasm charges gas for Wasm operations, calls to host functions and calls to
9
- the Cosmos SDK. CosmWasm gas is different from Cosmos SDK gas as the numbers
11
+ the Cosmos SDK. _ CosmWasm gas _ is different from _ Cosmos SDK gas _ as the numbers
10
12
here are much larger. Since we charge gas for arbitrary user defined operations,
11
13
we need to charge each Wasm operation individually and cannot group larger tasks
12
14
together. As a result, the gas values become much larger than in Cosmos SDK even
13
15
for very fast executions. There is a [ multiplier] [ defaultgasmultiplier ] to
14
16
translate between CosmWasm gas and Cosmos SDK. It was measured and set to 100 a
15
17
while ago and can be adjusted when necessary.
16
18
19
+ ## CosmWasm gas pricing
20
+
17
21
For CosmWasm gas, the target gas consumption is 1 Teragas (10^12 gas) per
18
22
millisecond. This idea is [ inspired by NEAR] [ neargas ] and we encourage you to
19
23
read their excellent docs on that topic.
@@ -38,3 +42,26 @@ multiple ways:
38
42
https://github.com/CosmWasm/wasmd/blob/v0.19.0/x/wasm/keeper/gas_register.go#L18
39
43
[ neargas ] : https://docs.near.org/docs/concepts/gas
40
44
[ #1120 ] : https://github.com/CosmWasm/cosmwasm/pull/1120
45
+
46
+ ## Gas overflow potential
47
+
48
+ CosmWasm gas aims for 1 Teragas/millisecond, i.e. the uint64 range exceeds after
49
+ 18 million seconds (5 hours)<sup >1</sup >. Assuming a max supported block
50
+ execution time of 30 seconds, the gas price has to be over-priced by a factor of
51
+ 614 (614 Teragas/millisecond) in order to exceed the uint64 range<sup >2</sup >.
52
+ Since serious over or underpricing is considered a bug, using uint64 for gas
53
+ measurements is considered safe.
54
+
55
+ Cosmos SDK gas uses values that are smaller by a factor of 150_000, so those
56
+ don't overflow as well. Since no Cosmos SDK gas values are processed inside of
57
+ this repository, this is not our main concern. However, it's good to know that
58
+ we can safely pass them in uint64 fields, as long as the full range is
59
+ supported. This is the case for the C API as well as
60
+ [ JSON numbers] ( https://www.json.org/ ) as long as both sides support integers in
61
+ their JSON implementation. Go and Rust do that while many other implementations
62
+ don't support integers, and convert them to IEEE-754 doubles, which has a safe
63
+ integer range up to about 53 bit (e.g. JavaScript and jq).
64
+
65
+ <sup >1</sup > Python3: ` (2**64-1)/1000 / 10**12 `
66
+
67
+ <sup >2</sup > Python3: ` ((2**64-1)/1000/30) / 10**122 `
0 commit comments