From 7d791f471eb24c36b49c47c0e418fd47285c8a7b Mon Sep 17 00:00:00 2001 From: Mitchell Turner Date: Wed, 15 Nov 2023 13:58:24 -0800 Subject: [PATCH] Add documentation for our calculation of a _reasonable_ gas fee for storage (#1478) Closes https://github.com/FuelLabs/fuel-core/issues/1404 --------- Co-authored-by: Green Baneling --- .../scripts/chainspec/beta_chainspec.json | 2 +- .../scripts/chainspec/dev_chainspec.json | 2 +- docs/fee_calculations.md | 65 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 docs/fee_calculations.md diff --git a/deployment/scripts/chainspec/beta_chainspec.json b/deployment/scripts/chainspec/beta_chainspec.json index cd8d0fcf366..80274588506 100644 --- a/deployment/scripts/chainspec/beta_chainspec.json +++ b/deployment/scripts/chainspec/beta_chainspec.json @@ -64,7 +64,7 @@ }, "fee_params": { "gas_price_factor": 92, - "gas_per_byte": 4 + "gas_per_byte": 63 }, "chain_id": 0, "gas_costs": { diff --git a/deployment/scripts/chainspec/dev_chainspec.json b/deployment/scripts/chainspec/dev_chainspec.json index bb9408e07f8..3362a634128 100644 --- a/deployment/scripts/chainspec/dev_chainspec.json +++ b/deployment/scripts/chainspec/dev_chainspec.json @@ -34,7 +34,7 @@ }, "fee_params": { "gas_price_factor": 1000000000, - "gas_per_byte": 4 + "gas_per_byte": 63 }, "chain_id": 0, "gas_costs": { diff --git a/docs/fee_calculations.md b/docs/fee_calculations.md new file mode 100644 index 00000000000..88bc91cce0e --- /dev/null +++ b/docs/fee_calculations.md @@ -0,0 +1,65 @@ +## Fee calculations + +### Storage fees + +Fuel doesn't currently support separate fees for execution costs vs storage costs. +This is a planned future feature, but in the mean time we need a system for +compensating the network for storing contract data. The temporary solution is +to include an additional cost to op codes that write new data to storage or to +transactions that add new contracts to the chain. + +There are a number of ways we might calculate this value; we have decided to go +with a simple calculatoin based on the our target storage growth and working +backward from there. + +#### Pessimistic Estimate + +If we arbitrarily set the target growth to 500 GB/year, we can ask, "what would +be the gas price if users maxed out each block gas limit with storage?" +This gives us this graph: + +| bytes per year | block gas limit | blocks per year | bytes per block | gas per bytes | +| --------------- | --------------- | --------------- | --------------- | ------------- | +| 500,000,000,000 | 10,000,000 | 31536000 | **15,855** | **630.72** | + +This is a harsh estimate that isn't taking into the additional base cost of tx +execution and the cost of any additional op codes. It is also assuming that +all blocks would be maxing out the storage. + +#### Generous Estimate + +Additionally, this will only apply to our early networks, which won't be long-live. +This allows us to take a bigger risk on the storage price and increas it over +time to compensate for users adding a lot of data. + +All this included, if we re-estimate the yearly storage limit as 5 TB we get: + +| bytes per year | block gas limit | blocks per year | bytes per block | gas per bytes | +| ----------------- | --------------- | --------------- | --------------- | ------------- | +| 5,000,000,000,000 | 10,000,000 | 31536000 | **158,549** | **63.07** | + +Giving us a cost per byte of **63 gas** as our initial gas price for storage. + +#### Additional justifications + +If we compare our numbers to what Ethereum charges for gas, we get similar numbers. + +If we had a pessimistic estimate for Ethereum and every block on Ethereum was full of new contract creations: + +max_contract_size = 24,000 bytes +gas_per_max_contract = 32,000 + max_contract_size * 200 = 4,832,000 + +gas_per_block = 30,000,000 +contracts_per_block = gas_per_block / gas_per_max_contract = ~6 + +blocks_per_year = 365 * 24 * 60 * ~5 = ~2628000 + +yearly_new_contract_bytes = blocks_per_year * contracts_per_block * max_contract_size = **378,432,000,000** + +Which rougly lines up with our pessimistic estimate. + +#### Conclusion + +We'd recommend starting at something like **63 gas/byte**. If this is underpriced, +this will be tested in a testnet before being launched, hopefully giving us +ample time to gather more data and update the price