Skip to content

Commit 3883073

Browse files
updating fees related docs as per tx fee changes introduced by FLIP 351 (#1603)
* updating fees related docs as per tx fee changes introduced by FLIP 351 * updating the fees table for different type of transactions * update fee numbers --------- Co-authored-by: Janez Podhostnik <janez.podhostnik@gmail.com>
1 parent c3c6be8 commit 3883073

File tree

2 files changed

+148
-38
lines changed

2 files changed

+148
-38
lines changed

docs/build/cadence/basics/fees.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ The execution effort for a transaction is determined by the code path the transa
6262
- Writing data to storage, charged per byte written
6363
- Account creation
6464

65-
| Transaction Type | Estimated cost (FLOW) |
66-
| -------------------------------------------------- | --------------------- |
67-
| FT transfer | 0.00000185 |
68-
| Mint a small NFT (heavily depends on the NFT size) | 0.0000019 |
69-
| Empty Transaction | 0.000001 |
70-
| Add key to an account | 0.000001 |
71-
| Create 1 Account | 0.00000315 |
72-
| Create 10 accounts | 0.00002261 |
73-
| Deploying a contract that is ~50kb | 0.00002965 |
65+
| | Computation Units | Flow |
66+
|-----------------------------------|-------------------|-------------|
67+
| FT transfer | 19 | 8.60E-04 |
68+
| Mint a small NFT (size-dependent) | 25 | 1.10E-03 |
69+
| Empty Transaction | 0 | 1.00E-04 |
70+
| Create 1 Account | 45 | 1.90E-03 |
71+
| Create 10 Accounts | 363 | 1.46E-02 |
72+
| Deploy contract (~50kb) | 319 | 1.29E-02 |
73+
| Add key to an account | 9 | 4.60E-04 |
74+
7475

7576
**Inclusion Fee**
7677

@@ -80,7 +81,9 @@ The inclusion effort of a transaction represents the work needed for:
8081
- Transporting the transaction information from node to node
8182
- Verifying transaction signatures
8283

83-
Right now, the inclusion effort is always 1.0 and the inclusion effort cost is fixed to `0.000001`.
84+
Right now, the inclusion effort is always 1.0 and the inclusion effort cost is fixed to `0.0001`.
85+
86+
Fees were last revised as per [FLIP 351](https://github.com/onflow/flips/blob/main/governance/20251119-transaction-fee-update.md)
8487

8588
**Surge Factor**
8689

docs/build/evm/fees.md

Lines changed: 135 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,73 +22,180 @@ Transaction fee on EVM = surge x [inclusion fee + (execution effort * unit cost)
2222
```
2323

2424
- `Surge' factor` dynamically accounts for network pressure and market conditions.
25-
- `Inclusion fee` accounts for the resources required to process a transaction due to its core properties (byte size, signatures). This is currently constant at 1E-6 FLOW, but subject to change with community approval.
26-
- `Execution fee` The fee that accounts for the operational cost of running the transaction script, processing the results, sending results for verification, generating verification receipts, etc. and is calculated as a product of `execution effort units` and the `cost per unit`.
27-
- `Execution Effort (computation)` is based on transaction type and operations that are called during the execution of a transaction. The weights determine how costly (time consuming) each operation is.
28-
- `Execution Effort Unit Cost` = `2.49E-07 FLOW` (currently constant, but subject to change with community approval)
25+
- `Inclusion fee` accounts for the resources required to process a transaction due to its core properties (byte size, signatures). This is currently constant at 1E-4 FLOW, but subject to change with community approval.
26+
- `Execution fee` The fee that accounts for the operational cost of running the transaction script, processing the results, sending results for verification, generating verification receipts, etc. and is calculated as a product of `computation units` and the `cost per unit`.
27+
- `Execution Effort (measured in computation units)` is based on transaction type and operations that are called during the execution of a transaction. The weights determine how costly (time-consuming) each operation is.
28+
- `Execution Effort Unit Cost` = `4E-05 FLOW` (currently constant, but subject to change with community approval)
2929

3030
<h3>Calculation of Execution Effort</h3>
3131

3232
```
3333
Execution Effort (computation) =
34-
0.00478 * function_or_loop_call +
35-
0.00246 * GetValue +
36-
0.00234 * SetValue +
37-
8.65988 * CreateAccount +
38-
EVMGasUsageCost * EVMGasUsage
34+
3.271E+01 * create_account +
35+
2.348E+01 * blsverify_pop +
36+
7.408E+00 * get_account_balance +
37+
6.145E+00 * blsaggregate_public_keys +
38+
6.059E+00 * get_storage_capacity +
39+
5.726E+00 * get_account_available_balance +
40+
5.637E+00 * update_account_contract_code +
41+
4.964E+00 * blsaggregate_signatures +
42+
1.152E+00 * generate_account_local_id +
43+
5.000E-01 * get_account_contract_names +
44+
3.878E-01 * get_storage_used +
45+
3.770E-01 * account_keys_count +
46+
2.346E-01 * allocate_slab_index +
47+
1.348E-01 * atree_map_get +
48+
1.125E-01 * atree_map_remove +
49+
6.659E-02 * create_array_value +
50+
5.826E-02 * create_dictionary_value +
51+
5.579E-02 * atree_map_set +
52+
5.573E-02 * atree_array_insert +
53+
5.074E-02 * atree_map_read_iteration +
54+
4.442E-02 * encode_event +
55+
3.598E-02 * transfer_composite_value +
56+
2.910E-02 * atree_array_append +
57+
2.701E-02 * statement +
58+
2.650E-02 * atree_array_set +
59+
2.135E-02 * function_invocation +
60+
1.846E-02 * atree_map_pop_iteration +
61+
1.123E-02 * atree_array_pop_iteration +
62+
7.874E-03 * rlpdecoding +
63+
4.242E-03 * graphemes_iteration +
64+
3.922E-03 * ufix_parse +
65+
3.403E-03 * fix_parse +
66+
2.731E-03 * loop +
67+
2.701E-03 * atree_array_batch_construction +
68+
1.907E-03 * transfer_dictionary_value +
69+
1.053E-03 * big_int_parse +
70+
7.324E-04 * transfer_array_value +
71+
7.324E-04 * set_value +
72+
4.730E-04 * uint_parse +
73+
4.272E-04 * int_parse +
74+
3.510E-04 * get_value +
75+
7.629E-05 * string_to_lower +
76+
4.578E-05 * evmgas_usage
3977
```
4078

4179
where
4280

4381
```
44-
`EVMGasUsage` is reported by EVM as the cost in gas for executing the transaction within the EVM, for instance, 21K gas for a simple send transaction.
45-
```
46-
47-
```
48-
`EVMGasUsageCost` - The ratio that converts EVM gas into Flow compute units (execution effort) is currently set at `1/5000` but subject to revision by community approval
82+
`evmgas_usage` is reported by EVM as the cost in gas for executing the transaction within the EVM, for instance, 21K gas for a simple send transaction.
4983
```
5084

5185
</details>
5286

5387
<details>
5488
<summary><h2>Demonstration of Transaction Fees on EVM</h2></summary>
5589

56-
Assume a simple NFT transfer transaction that makes 31 cadence loop calls, reads 5668 bytes from the storage register, and saves 1668 bytes to the storage register.
57-
58-
- 'function_or_loop_call' = 31
59-
- 'GetValue' = 5688
60-
- 'SetValue' = 1668
61-
- 'CreateAccount' = 0
90+
Assume a simple Token transfer transaction:
6291

6392
**Scenario 1 - Cadence-only Transaction**
6493

65-
```
66-
Compute Units = 0.00478 * (31) + 0.00246 * (5668) + 0.00234 *(1668) + 8.65988 *(0) + EVMGasUsageCost * EVMGasUsage
94+
The token transfer transaction:
95+
96+
- makes 76 atree_map_get calls,
97+
- reads 9431 bytes (get_value),
98+
- sets 2448 bytes (set_value),
99+
- invokes 55 cadence statements,
100+
- makes 2 get_storage_used calls,
101+
- makes 28 cadence function_invocation calls,
102+
- makes 8 transfer_composite_value calls,
103+
- makes 5 atree_map_set calls,
104+
- makes 4 encode_event calls,
105+
- makes 2 create_array_value calls,
106+
- makes 2 atree_array_append calls,
107+
- makes 4 atree_array_batch_construction calls,
108+
- makes 2 loop calls,
109+
- makes 2 transfer_array_value calls
110+
111+
112+
```
113+
Compute Units =
114+
76 * 0.135 +
115+
9431 * 0.000 +
116+
2448 * 0.001 +
117+
55 * 0.027 +
118+
2 * 0.388 +
119+
28 * 0.021 +
120+
8 * 0.036 +
121+
5 * 0.056 +
122+
4 * 0.044 +
123+
2 * 0.067 +
124+
2 * 0.029 +
125+
4 * 0.003 +
126+
2 * 0.003 +
127+
2 * 0.001
67128
```
68129

69130
But since `EVMGasUsage` is 0 for a Cadence transaction,
70131

71132
```
72-
Compute Units = 18.04378
133+
Compute Units = 19.2
73134
```
74135

75136
Thus
76137

77138
```
78-
Transaction fee = [1E-6 FLOW + (18.04378 * 2.49E-07 FLOW)] x 1 = 5.5E-06 FLOW
139+
Transaction fee = [1E-4 FLOW + (19.2 * 4E-05 FLOW)] x 1 = 8.68E-04
79140
```
80141

81142
**Scenario 2 - EVM Transaction**
82-
If the EVMGasUsage can be assumed to be 21,000 gas (typical for a simple transfer),
143+
If the EVMGasUsage can be assumed to be 21,000 gas (typical for a simple transfer):
144+
145+
- uses 377806 evm gas (evmgas_usage),
146+
- reads 22840 bytes (get_value),
147+
- makes 1676 atree_array_batch_construction calls,
148+
- makes 30 atree_map_get calls,
149+
- makes 325 atree_array_pop_iteration calls,
150+
- sets 3182 bytes (set_value),
151+
- makes 273 rlpdecoding calls,
152+
- makes 20 atree_map_read_iteration calls,
153+
- makes 1329 transfer_array_value calls,
154+
- invokes 25 cadence statements,
155+
- makes 12 atree_map_set calls,
156+
- makes 17 transfer_composite_value calls,
157+
- makes 8 create_array_value calls,
158+
- makes 19 function_invocation calls,
159+
- makes 1 get_storage_used calls,
160+
- makes 87 graphemes_iteration calls,
161+
- makes 2 encode_event calls,
162+
- makes 2 atree_array_append calls,
163+
- makes 1 atree_map_pop_iteration calls,
164+
- makes 2 loop calls,
165+
- makes 40 string_to_lower calls
166+
167+
168+
```
169+
Compute Units =
170+
377806 * 0.00005 +
171+
22840 * 0.00035 +
172+
1676 * 0.00270 +
173+
30 * 0.13484 +
174+
325 * 0.01123 +
175+
3182 * 0.00073 +
176+
273 * 0.00787 +
177+
20 * 0.05074 +
178+
1329 * 0.00073 +
179+
25 * 0.02701 +
180+
12 * 0.05579 +
181+
17 * 0.03598 +
182+
8 * 0.06659 +
183+
19 * 0.02135 +
184+
1 * 0.38782 +
185+
87 * 0.00424 +
186+
2 * 0.04442 +
187+
2 * 0.02910 +
188+
1 * 0.01846 +
189+
2 * 0.00273 +
190+
40 * 0.00008
191+
= 47.8
83192
84-
```
85-
Compute Units = 0.00478 * (31) + 0.00246 * (5668) + 0.00234 *(1668) + 8.65988 *(0) + 1/5000 * 21000 = 22.24378
86193
```
87194

88195
Thus
89196

90197
```
91-
Transaction fee = [1E-6 FLOW + (110.97 * 2.49E-07 FLOW)] x 1 = 6.55E-06 FLOW
198+
Transaction fee = [1E-4 FLOW + (47.8 * 4E-05 FLOW)] x 1 = 2.012E-03 FLOW
92199
```
93200

94201
**Note**: Please be aware that this example serves solely for illustrative purposes to elucidate the calculations. Actual transaction fees may differ due to various factors, including the byte size of the transaction.

0 commit comments

Comments
 (0)