diff --git a/docs/build/cadence/basics/fees.md b/docs/build/cadence/basics/fees.md index 35780c3380..e7e37fe5b5 100644 --- a/docs/build/cadence/basics/fees.md +++ b/docs/build/cadence/basics/fees.md @@ -62,15 +62,16 @@ The execution effort for a transaction is determined by the code path the transa - Writing data to storage, charged per byte written - Account creation -| Transaction Type | Estimated cost (FLOW) | -| -------------------------------------------------- | --------------------- | -| FT transfer | 0.00000185 | -| Mint a small NFT (heavily depends on the NFT size) | 0.0000019 | -| Empty Transaction | 0.000001 | -| Add key to an account | 0.000001 | -| Create 1 Account | 0.00000315 | -| Create 10 accounts | 0.00002261 | -| Deploying a contract that is ~50kb | 0.00002965 | +| | Computation Units | Flow | +|-----------------------------------|-------------------|-------------| +| FT transfer | 19 | 8.60E-04 | +| Mint a small NFT (size-dependent) | 25 | 1.10E-03 | +| Empty Transaction | 0 | 1.00E-04 | +| Create 1 Account | 45 | 1.90E-03 | +| Create 10 Accounts | 363 | 1.46E-02 | +| Deploy contract (~50kb) | 319 | 1.29E-02 | +| Add key to an account | 9 | 4.60E-04 | + **Inclusion Fee** @@ -80,7 +81,9 @@ The inclusion effort of a transaction represents the work needed for: - Transporting the transaction information from node to node - Verifying transaction signatures -Right now, the inclusion effort is always 1.0 and the inclusion effort cost is fixed to `0.000001`. +Right now, the inclusion effort is always 1.0 and the inclusion effort cost is fixed to `0.0001`. + +Fees were last revised as per [FLIP 351](https://github.com/onflow/flips/blob/main/governance/20251119-transaction-fee-update.md) **Surge Factor** diff --git a/docs/build/evm/fees.md b/docs/build/evm/fees.md index 52b5ec3a85..b68c8bef6f 100644 --- a/docs/build/evm/fees.md +++ b/docs/build/evm/fees.md @@ -22,30 +22,64 @@ Transaction fee on EVM = surge x [inclusion fee + (execution effort * unit cost) ``` - `Surge' factor` dynamically accounts for network pressure and market conditions. -- `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. -- `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`. - - `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. - - `Execution Effort Unit Cost` = `2.49E-07 FLOW` (currently constant, but subject to change with community approval) +- `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. +- `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`. + - `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. + - `Execution Effort Unit Cost` = `4E-05 FLOW` (currently constant, but subject to change with community approval)

Calculation of Execution Effort

``` Execution Effort (computation) = - 0.00478 * function_or_loop_call + - 0.00246 * GetValue + - 0.00234 * SetValue + - 8.65988 * CreateAccount + - EVMGasUsageCost * EVMGasUsage + 3.271E+01 * create_account + + 2.348E+01 * blsverify_pop + + 7.408E+00 * get_account_balance + + 6.145E+00 * blsaggregate_public_keys + + 6.059E+00 * get_storage_capacity + + 5.726E+00 * get_account_available_balance + + 5.637E+00 * update_account_contract_code + + 4.964E+00 * blsaggregate_signatures + + 1.152E+00 * generate_account_local_id + + 5.000E-01 * get_account_contract_names + + 3.878E-01 * get_storage_used + + 3.770E-01 * account_keys_count + + 2.346E-01 * allocate_slab_index + + 1.348E-01 * atree_map_get + + 1.125E-01 * atree_map_remove + + 6.659E-02 * create_array_value + + 5.826E-02 * create_dictionary_value + + 5.579E-02 * atree_map_set + + 5.573E-02 * atree_array_insert + + 5.074E-02 * atree_map_read_iteration + + 4.442E-02 * encode_event + + 3.598E-02 * transfer_composite_value + + 2.910E-02 * atree_array_append + + 2.701E-02 * statement + + 2.650E-02 * atree_array_set + + 2.135E-02 * function_invocation + + 1.846E-02 * atree_map_pop_iteration + + 1.123E-02 * atree_array_pop_iteration + + 7.874E-03 * rlpdecoding + + 4.242E-03 * graphemes_iteration + + 3.922E-03 * ufix_parse + + 3.403E-03 * fix_parse + + 2.731E-03 * loop + + 2.701E-03 * atree_array_batch_construction + + 1.907E-03 * transfer_dictionary_value + + 1.053E-03 * big_int_parse + + 7.324E-04 * transfer_array_value + + 7.324E-04 * set_value + + 4.730E-04 * uint_parse + + 4.272E-04 * int_parse + + 3.510E-04 * get_value + + 7.629E-05 * string_to_lower + + 4.578E-05 * evmgas_usage ``` where ``` -`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. -``` - -``` -`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 +`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. ``` @@ -53,42 +87,115 @@ where

Demonstration of Transaction Fees on EVM

-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. - -- 'function_or_loop_call' = 31 -- 'GetValue' = 5688 -- 'SetValue' = 1668 -- 'CreateAccount' = 0 +Assume a simple Token transfer transaction: **Scenario 1 - Cadence-only Transaction** -``` -Compute Units = 0.00478 * (31) + 0.00246 * (5668) + 0.00234 *(1668) + 8.65988 *(0) + EVMGasUsageCost * EVMGasUsage +The token transfer transaction: + +- makes 76 atree_map_get calls, +- reads 9431 bytes (get_value), +- sets 2448 bytes (set_value), +- invokes 55 cadence statements, +- makes 2 get_storage_used calls, +- makes 28 cadence function_invocation calls, +- makes 8 transfer_composite_value calls, +- makes 5 atree_map_set calls, +- makes 4 encode_event calls, +- makes 2 create_array_value calls, +- makes 2 atree_array_append calls, +- makes 4 atree_array_batch_construction calls, +- makes 2 loop calls, +- makes 2 transfer_array_value calls + + +``` +Compute Units = + 76 * 0.135 + + 9431 * 0.000 + + 2448 * 0.001 + + 55 * 0.027 + + 2 * 0.388 + + 28 * 0.021 + + 8 * 0.036 + + 5 * 0.056 + + 4 * 0.044 + + 2 * 0.067 + + 2 * 0.029 + + 4 * 0.003 + + 2 * 0.003 + + 2 * 0.001 ``` But since `EVMGasUsage` is 0 for a Cadence transaction, ``` -Compute Units = 18.04378 +Compute Units = 19.2 ``` Thus ``` -Transaction fee = [1E-6 FLOW + (18.04378 * 2.49E-07 FLOW)] x 1 = 5.5E-06 FLOW +Transaction fee = [1E-4 FLOW + (19.2 * 4E-05 FLOW)] x 1 = 8.68E-04 ``` **Scenario 2 - EVM Transaction** -If the EVMGasUsage can be assumed to be 21,000 gas (typical for a simple transfer), +If the EVMGasUsage can be assumed to be 21,000 gas (typical for a simple transfer): + +- uses 377806 evm gas (evmgas_usage), +- reads 22840 bytes (get_value), +- makes 1676 atree_array_batch_construction calls, +- makes 30 atree_map_get calls, +- makes 325 atree_array_pop_iteration calls, +- sets 3182 bytes (set_value), +- makes 273 rlpdecoding calls, +- makes 20 atree_map_read_iteration calls, +- makes 1329 transfer_array_value calls, +- invokes 25 cadence statements, +- makes 12 atree_map_set calls, +- makes 17 transfer_composite_value calls, +- makes 8 create_array_value calls, +- makes 19 function_invocation calls, +- makes 1 get_storage_used calls, +- makes 87 graphemes_iteration calls, +- makes 2 encode_event calls, +- makes 2 atree_array_append calls, +- makes 1 atree_map_pop_iteration calls, +- makes 2 loop calls, +- makes 40 string_to_lower calls + + +``` +Compute Units = + 377806 * 0.00005 + + 22840 * 0.00035 + + 1676 * 0.00270 + + 30 * 0.13484 + + 325 * 0.01123 + + 3182 * 0.00073 + + 273 * 0.00787 + + 20 * 0.05074 + + 1329 * 0.00073 + + 25 * 0.02701 + + 12 * 0.05579 + + 17 * 0.03598 + + 8 * 0.06659 + + 19 * 0.02135 + + 1 * 0.38782 + + 87 * 0.00424 + + 2 * 0.04442 + + 2 * 0.02910 + + 1 * 0.01846 + + 2 * 0.00273 + + 40 * 0.00008 + = 47.8 -``` -Compute Units = 0.00478 * (31) + 0.00246 * (5668) + 0.00234 *(1668) + 8.65988 *(0) + 1/5000 * 21000 = 22.24378 ``` Thus ``` -Transaction fee = [1E-6 FLOW + (110.97 * 2.49E-07 FLOW)] x 1 = 6.55E-06 FLOW +Transaction fee = [1E-4 FLOW + (47.8 * 4E-05 FLOW)] x 1 = 2.012E-03 FLOW ``` **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.