Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fee calculation formula #1092

Merged
merged 13 commits into from
Feb 4, 2024
Merged

fix: fee calculation formula #1092

merged 13 commits into from
Feb 4, 2024

Conversation

ArielElp
Copy link
Collaborator

@ArielElp ArielElp commented Jan 21, 2024

Description of the Changes

More adjustments to the fee formulate following some discrepancies from the actual calculation that happens in the blockifier.

PR Preview URL

Gas and transaction fees

Check List

  • Changes have been done against main branch, and PR does not conflict
  • PR title follows the convention: <docs/feat/fix/chore>(optional scope): <description>, e.g: fix: minor typos in code

This change is Reviewable

@ArielElp ArielElp requested a review from stoobie January 21, 2024 15:10
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

3 similar comments
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

@ArielElp ArielElp force-pushed the fix_fee_calculation branch from 8ee3375 to 2aa5291 Compare January 21, 2024 15:54
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

++++

where:

* stem:[$v$] is a vector that represents resource usage, where each of its entries, stem:[$v_k$], correspond to different resource types: Cairo steps and number of applications of each builtin.
* stem:[$v$] is a vector that represents resource usage, where each of its entries, stem:[$v_k$], corresponds to different resource types: Cairo steps and number of applications of each builtin.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked two folks to take a look at this, and one of them didn't understand what k is. The other person explained that k is a number that corresponds to one of the resources listed in Table 1, so k is a value 1-8, (or 0-7?). Which means that the table should have a column for resource identifier k.

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link
Collaborator Author

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r6.
Reviewable status: 0 of 1 files reviewed, 7 unresolved discussions (waiting on @stoobie)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 31 at r1 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 2$] is always true, because the balance of the account sending the transaction and the sequencer's balance are always updated.

Added "always holds"


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 35 at r1 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$\text{calldata_cost}$] is 550 gas per 32-byte word. This cost is derived as follows: 512 gas per 32-byte word for calldata, ~100 gas for onchain hashing that happens for every word sent, and a 10% discount that applies because the sequencer does not incur additional costs for repeated updates to the same storage slot within a single block. So the gas cost is calculated as follows: stem:[0.9 \cot 612 = 550 gas], rounded down.

It's eventually 551 not 550. I'ts not rounded up, but rather we get it by doing 512-512*10/100 where both sides are integers, I don't want to get into it here.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 197 at r1 (raw file):

Previously, stoobie (Steve Goodman) wrote…
Taking into account that zero bytes only cost 4 gas, the cost difference between a full 32-byte word, which is entirely non-zero, and a word with only six non-zero bytes is stem:[$32\cdot16-(6\cdot16+26\cdot4)=312$].

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 27 at r2 (raw file):

Previously, stoobie (Steve Goodman) wrote…

I asked two folks to take a look at this, and one of them didn't understand what k is. The other person explained that k is a number that corresponds to one of the resources listed in Table 1, so k is a value 1-8, (or 0-7?). Which means that the table should have a column for resource identifier k.

I don't want to explicitly refer to it, it is indexing the entries of v and w, so if you go to read about v and w you understand what the entries are (it is also mentioned in the first point)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 188 at r2 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 2$] is always true,  because the balance of the account sending the transaction and the sequencer's balance are always updated. The sender's balance is treated separately, as described below, and the sequencer's balance is ignored since it is touched by all the transactions within a block.

Added "always holds"


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 189 at r2 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[\text{contract_update_discount}] is 312 gas, which is discounted for every updated contract. This discount is a result of the fact that out of the stem:[$2n$] words caused by updating contracts, stem:[$n$] words are short, including at most 6 non-zero bytes:

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 198 at r2 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$310$] is the cost of updating the sender's balance, and is derived by assuming the balance requires at most 12 non-zero bytes, which is enough for 1.2B ETH or STRK, resulting in the following discounted price: stem:[$0.9 \cdot 612-(512-(16 \cdot12+20 \cdot 4))=310$], rounded down.

Done.

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

1 similar comment
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

1 similar comment
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

1 similar comment
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Changes to be committed:
	modified:   components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc
@stoobie stoobie force-pushed the fix_fee_calculation branch from d0cf791 to 5bd6e6d Compare January 28, 2024 11:47
Copy link

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link
Collaborator

@stoobie stoobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 14 unresolved discussions (waiting on @ArielElp)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 31 at r1 (raw file):

Previously, ArielElp wrote…

Added "always holds"

I changed the sentence to

* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 1$] is always true, because the sequencer's balance is always updated, which does not incur any fee.

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 35 at r1 (raw file):

Previously, ArielElp wrote…

It's eventually 551 not 550. I'ts not rounded up, but rather we get it by doing 512-512*10/100 where both sides are integers, I don't want to get into it here.

So is this what you want to say (with my edits):

* stem:[$\text{da_calldata_cost}$] is 551 gas per 32-byte word. This cost is derived as follows: 
+
** 512 gas per 32-byte word for calldata.
** ~100 gas for onchain hashing that happens for every sent word.
** a 10% discount, because the sequencer does not incur additional costs for repeated updates to the same storage slot within a single block.

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 188 at r2 (raw file):

Previously, ArielElp wrote…

Added "always holds"

Please approve my edits.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 36 at r9 (raw file):

+
For more information see xref:#calculation_of_computation_costs[Calculation of computation costs].
* stem:[$n$] is xref:#storage_updates[the number of unique contracts updated]. Note that this also takes into account contract deployment, even if the storage of the newly deployed contract was untouched, i.e. stem:[$n\ge\ell$].

Does "the number of unique contracts updated" include "the number of contracts whose class was changed"? It's not clear, but I think that's what you mean. Assuming I'm correct, then the following text should be correct:

  • stem:[$n$] is xref:#storage_updates[the number of unique contracts updated], which includes changes to, or new deployments of, classes of existing contract instances, even if the storage of the newly deployed contract is untouched. In other words, stem:[$n\ge\ell$].

Code quote:

* stem:[$n$] is xref:#storage_updates[the number of unique contracts updated]. Note that this also takes into account contract deployment, even if the storage of the newly deployed contract was untouched, i.e. stem:[$n\ge\ell$].

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 39 at r9 (raw file):

* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Note that stem:[$m\ge 1$] always holds since the sequencer balance is always updated (this is not charged for).
* stem:[$t$] is the number of L2->L1 messages sent, where the corresponding payload sizes are denoted by stem:[$q_1,...,q_t$].
* stem:[$\ell$] is the number of contracts whose class was changed. This can happen on deployment or on applying the `replace_class` syscall.

s whose class was changed, which can happen on deployment of a new version of the class, or on applying the replace_class syscall.

Code quote:

s whose class was changed. This can happen on deployment or on applying the `replace_class` syscall.

components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 248 at r14 (raw file):

* class hash

The first two elements are counted in the number of unique modified contracts, denoted by stem:[$n$] throughout this page, such as with stem:[$n\ge\ell$]. So the only additional comes from publishing the class hash,
 So the only additional cost comes from publishing the class hash,

Code quote:

 So the only additional comes from publishing the class hash,

Copy link

github-actions bot commented Feb 4, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link
Collaborator Author

@ArielElp ArielElp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 1 files at r13.
Reviewable status: 0 of 1 files reviewed, 14 unresolved discussions (waiting on @stoobie)


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 31 at r1 (raw file):

Previously, stoobie (Steve Goodman) wrote…

I changed the sentence to

* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 1$] is always true, because the sequencer's balance is always updated, which does not incur any fee.

slightly changed


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 35 at r1 (raw file):

Previously, stoobie (Steve Goodman) wrote…

So is this what you want to say (with my edits):

* stem:[$\text{da_calldata_cost}$] is 551 gas per 32-byte word. This cost is derived as follows: 
+
** 512 gas per 32-byte word for calldata.
** ~100 gas for onchain hashing that happens for every sent word.
** a 10% discount, because the sequencer does not incur additional costs for repeated updates to the same storage slot within a single block.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 188 at r2 (raw file):

Previously, stoobie (Steve Goodman) wrote…

Please approve my edits.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 36 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…

Does "the number of unique contracts updated" include "the number of contracts whose class was changed"? It's not clear, but I think that's what you mean. Assuming I'm correct, then the following text should be correct:

  • stem:[$n$] is xref:#storage_updates[the number of unique contracts updated], which includes changes to, or new deployments of, classes of existing contract instances, even if the storage of the newly deployed contract is untouched. In other words, stem:[$n\ge\ell$].

Changed it slightly


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 37 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 1$] is always true, because the sequencer's balance is always updated, which does not incur any fee.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 39 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$\ell$] is the number of contracts whose class was changed, which can happen on deployment of a new version of the class, or on applying the `replace_class` syscall.

This is not true, changed it back to either contract deployment of class replacement


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 39 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…

s whose class was changed, which can happen on deployment of a new version of the class, or on applying the replace_class syscall.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 41 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$\text{da_calldata_cost}$] is 551 gas per 32-byte word. This cost is derived as follows: 
+
** 512 gas per 32-byte word for calldata.
** ~100 gas for onchain hashing that happens for every sent word.
** a 10% discount, because the sequencer does not incur additional costs for repeated updates to the same storage slot within a single block.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 195 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$m$] is the number of values updated, not counting multiple updates for the same key. Notice that stem:[$m\ge 1$] is always true, because the sequencer's balance is always updated, which does not incur any fee.

Changed to the same thing I did above


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 224 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
Consequently, the gas cost associated with a single L2→L1 message is:

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 231 at r9 (raw file):

Previously, stoobie (Steve Goodman) wrote…
Where stem:[$\text{da_calldata_cost}$] is 551 gas, and stem:[$\text{message_calldata_cost}$] is 512 gas.

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 36 at r10 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$n$] is xref:#storage_updates[the number of unique contracts updated], which includes changes to, or new deployments of, classes of existing contract instances, even if the storage of the newly deployed contract is untouched. In other words, stem:[$n\ge\ell$].

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 198 at r10 (raw file):

Previously, stoobie (Steve Goodman) wrote…
* stem:[$n$] is xref:#storage_updates[the number of unique contracts updated], which includes changes to, or new deployments of, classes of existing contract instances, even if the storage of the newly deployed contract is untouched. In other words, stem:[$n\ge\ell$].

Done.


components/Starknet/modules/architecture_and_concepts/pages/Network_Architecture/fee-mechanism.adoc line 249 at r11 (raw file):

Previously, stoobie (Steve Goodman) wrote…
which adds 551 gas. For more information, see stem:[$\text{da_calldata_cost}$] and stem:[$\text{message_calldata_cost}$] in xref:#l_2-l_1_messages[Onchain data: L2->L1 messages].

This is unrelated to messages, changed the link to the final formula

Copy link

github-actions bot commented Feb 4, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

github-actions bot commented Feb 4, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link

github-actions bot commented Feb 4, 2024

Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/pr-1092/documentation/ .

Copy link
Collaborator

@stoobie stoobie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @ArielElp)

@stoobie stoobie merged commit 0c36768 into main Feb 4, 2024
2 of 4 checks passed
@stoobie stoobie deleted the fix_fee_calculation branch February 4, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants