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(blockifier): enforce fee for allresourcebounds when l1 gas is 0 #846

Merged
merged 3 commits into from
Sep 24, 2024

Conversation

aner-starkware
Copy link
Contributor

@aner-starkware aner-starkware commented Sep 17, 2024

This change is Reviewable

@aner-starkware aner-starkware self-assigned this Sep 17, 2024
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

Attention: Patch coverage is 84.37500% with 10 lines in your changes missing coverage. Please review.

Project coverage is 75.52%. Comparing base (b0cfe82) to head (641d5ce).
Report is 49 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/versioned_constants.rs 52.94% 8 Missing ⚠️
crates/blockifier/src/transaction/objects.rs 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #846      +/-   ##
==========================================
+ Coverage   74.18%   75.52%   +1.33%     
==========================================
  Files         359       87     -272     
  Lines       36240    11120   -25120     
  Branches    36240    11120   -25120     
==========================================
- Hits        26886     8398   -18488     
+ Misses       7220     2311    -4909     
+ Partials     2134      411    -1723     
Flag Coverage Δ
75.52% <84.37%> (+1.33%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@nimrod-starkware nimrod-starkware 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 @aner-starkware)

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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 r1, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @aner-starkware, @nimrod-starkware, and @TzahiTaub)


crates/blockifier/src/transaction/objects.rs line 120 at r1 (raw file):

                        + u128::from(l1_data_gas.max_amount) * l1_data_gas.max_price_per_unit
                        > 0
                }

I think ValidResourceBounds should have a max_possible_fee method that returns the scalar product of the amounts and the prices; this will replace the two match arms here

Code quote:

                ValidResourceBounds::L1Gas(l1_bounds) => {
                    let max_amount: u128 = l1_bounds.max_amount.into();
                    max_amount * l1_bounds.max_price_per_unit > 0
                }
                ValidResourceBounds::AllResources(AllResourceBounds {
                    l1_gas,
                    l2_gas,
                    l1_data_gas,
                }) => {
                    u128::from(l1_gas.max_amount) * l1_gas.max_price_per_unit
                        + u128::from(l2_gas.max_amount) * l2_gas.max_price_per_unit
                        + u128::from(l1_data_gas.max_amount) * l1_data_gas.max_price_per_unit
                        > 0
                }

crates/blockifier/src/transaction/objects.rs line 121 at r1 (raw file):

                        > 0
                }
            },

flatten the match please (or, see comment above)

Suggestion:

            TransactionInfo::Current(ValidResourceBounds::L1Gas(l1_bounds)) =>  {
                let max_amount: u128 = l1_bounds.max_amount.into();
                max_amount * l1_bounds.max_price_per_unit > 0
            }
            TransactionInfo::Current(ValidResourceBounds::AllResources(AllResourceBounds {
                    l1_gas,
                    l2_gas,
                    l1_data_gas,
            })) => {
                u128::from(l1_gas.max_amount) * l1_gas.max_price_per_unit
                    + u128::from(l2_gas.max_amount) * l2_gas.max_price_per_unit
                    + u128::from(l1_data_gas.max_amount) * l1_data_gas.max_price_per_unit
                    > 0
            },

Copy link
Contributor Author

@aner-starkware aner-starkware 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: all files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/blockifier/src/transaction/objects.rs line 120 at r1 (raw file):

Previously, dorimedini-starkware wrote…

I think ValidResourceBounds should have a max_possible_fee method that returns the scalar product of the amounts and the prices; this will replace the two match arms here

Done.


crates/blockifier/src/transaction/objects.rs line 121 at r1 (raw file):

Previously, dorimedini-starkware wrote…

flatten the match please (or, see comment above)

Took the above option.

Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [66.775 ms 66.876 ms 67.006 ms]
change: [-9.0514% -5.8887% -3.0941%] (p = 0.00 < 0.05)
Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
3 (3.00%) high severe

@aner-starkware aner-starkware changed the base branch from main to aner/fix_l1_to_l2_gas_price_ratio September 23, 2024 12:03
@aner-starkware aner-starkware force-pushed the aner/fix_l1_to_l2_gas_price_ratio branch 2 times, most recently from e9676fc to f07cd9a Compare September 23, 2024 13:50
Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [66.527 ms 66.982 ms 67.648 ms]
change: [-8.9707% -5.5627% -2.2541%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
6 (6.00%) high severe

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @aner-starkware, @nimrod-starkware, and @TzahiTaub)


crates/starknet_api/src/transaction.rs line 998 at r3 (raw file):

            }
        }
    }

wrap in this type, for clarity

Suggestion:

    pub fn max_possible_fee(&self) -> Fee {
        Fee(match self {
            ValidResourceBounds::L1Gas(l1_bounds) => {
                let max_amount: u128 = l1_bounds.max_amount.into();
                max_amount * l1_bounds.max_price_per_unit
            }
            ValidResourceBounds::AllResources(AllResourceBounds {
                l1_gas,
                l2_gas,
                l1_data_gas,
            }) => {
                u128::from(l1_gas.max_amount) * l1_gas.max_price_per_unit
                    + u128::from(l2_gas.max_amount) * l2_gas.max_price_per_unit
                    + u128::from(l1_data_gas.max_amount) * l1_data_gas.max_price_per_unit
            }
        })
    }

Copy link
Contributor Author

@aner-starkware aner-starkware 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 2 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/starknet_api/src/transaction.rs line 998 at r3 (raw file):

Previously, dorimedini-starkware wrote…

wrap in this type, for clarity

Done. Though the name fn name is probably clear enough ;)

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nimrod-starkware and @TzahiTaub)


crates/starknet_api/src/transaction.rs line 998 at r3 (raw file):

Previously, aner-starkware wrote…

Done. Though the name fn name is probably clear enough ;)

it's clear, but type enforcement is better.
it enforces that we don't perform addition/subtraction on different numeric types, for example (basic physics, can't add meters to seconds :) )

Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware 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 r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nimrod-starkware and @TzahiTaub)

@aner-starkware aner-starkware changed the base branch from aner/fix_l1_to_l2_gas_price_ratio to main September 24, 2024 11:05
@aner-starkware aner-starkware merged commit 902c2b0 into main Sep 24, 2024
32 of 41 checks passed
@aner-starkware aner-starkware deleted the aner/pre_validation_enforce_fee branch September 24, 2024 13:02
@aner-starkware aner-starkware restored the aner/pre_validation_enforce_fee branch September 24, 2024 13:02
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2024
@aner-starkware aner-starkware deleted the aner/pre_validation_enforce_fee branch October 5, 2024 06:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants