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

test(blockifier): max fee exceeds balance errors on new resource bounds #764

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

aner-starkware
Copy link
Contributor

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

This change is Reviewable

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

codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.40%. Comparing base (e3165c4) to head (52ec5c8).
Report is 92 commits behind head on main.

Files with missing lines Patch % Lines
crates/starknet_api/src/execution_resources.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #764       +/-   ##
===========================================
+ Coverage   40.10%   77.40%   +37.30%     
===========================================
  Files          26      100       +74     
  Lines        1895    13429    +11534     
  Branches     1895    13429    +11534     
===========================================
+ Hits          760    10395     +9635     
- Misses       1100     2578     +1478     
- Partials       35      456      +421     

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

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from cecac6d to 70f25c7 Compare September 15, 2024 08:43
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 552fd35 to 49bc1aa Compare September 15, 2024 08:44
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 70f25c7 to 0f89641 Compare September 15, 2024 13:01
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 49bc1aa to c7f3e01 Compare September 15, 2024 13:41
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 0f89641 to 808d19d Compare September 16, 2024 12:14
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from c7f3e01 to e4d8c18 Compare September 16, 2024 13:11
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 808d19d to ee3cae4 Compare September 18, 2024 08:51
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from e4d8c18 to 28319f4 Compare September 18, 2024 08:52
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from ee3cae4 to b7f9fde Compare September 18, 2024 10:05
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 28319f4 to 22e9193 Compare September 18, 2024 10:12
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from b7f9fde to e3bf0de Compare September 18, 2024 10:20
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 22e9193 to 2a11389 Compare September 18, 2024 10:40
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from e3bf0de to 44776d4 Compare September 18, 2024 14:26
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 2a11389 to 3740a56 Compare September 18, 2024 14:27
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 44776d4 to f5e0e89 Compare September 23, 2024 12:17
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 3740a56 to 52bee9c Compare September 23, 2024 12:17
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from f5e0e89 to d31516e Compare September 23, 2024 14:03
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 52bee9c to c8533f6 Compare September 23, 2024 14:04
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from d31516e to 9095f45 Compare September 24, 2024 13:48
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from c8533f6 to 343c018 Compare September 24, 2024 13:50
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch 3 times, most recently from d8fa853 to 54bc2bc Compare September 25, 2024 15:53
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 343c018 to 8d5d0b1 Compare September 25, 2024 15:53
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 54bc2bc to df26a10 Compare September 25, 2024 16:04
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from f5f0632 to 689ca5e Compare September 29, 2024 09:27
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_1 branch from 1aa10a5 to 14dba9a Compare September 30, 2024 14:57
@aner-starkware aner-starkware changed the base branch from aner/pre_validation_covers_sum_of_products_1 to main October 1, 2024 09:48
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 689ca5e to 5f62898 Compare October 1, 2024 09:52
Copy link
Contributor

@TzahiTaub TzahiTaub 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 3 files at r8.
Reviewable status: 1 of 4 files reviewed, 5 unresolved discussions (waiting on @aner-starkware, @dorimedini-starkware, and @nimrod-starkware)


crates/blockifier/src/transaction/transactions_test.rs line 912 at r4 (raw file):

Previously, aner-starkware wrote…

Done.

Nope, it should be max amount (balance >= price * amount)


crates/blockifier/src/transaction/transactions_test.rs line 961 at r4 (raw file):

Previously, aner-starkware wrote…

Yes, because here I want to test each individual resource, so the other resources, if they are 0 for example, might fail a previous check and we won't get the correct error.

Why can't we just use the maxes instead of the mins (and then avoid defining them)? I assume we fail on the per resource assertion before the total balance assertion.


crates/blockifier/src/transaction/transactions_test.rs line 969 at r4 (raw file):

Previously, aner-starkware wrote…

Yes, but in any case, it was a temporary patch because of the bug. Now, it can be done without the max (though max is more correct, but is significantly longer and seems to not be needed).

The bug? Do you mean that min_amount could have been larger than the max_amount and now it doesn't? I don't understand what happened


crates/blockifier/src/transaction/transactions_test.rs line 971 at r8 (raw file):

    let min_l2_amount = 445500;
    let min_l1_data_amount = 128;
    let max_l2_gas_price: u64 =

Suggestion:

max_l2_gas_amount

crates/blockifier/src/transaction/transactions_test.rs line 973 at r8 (raw file):

    let max_l2_gas_price: u64 =
        (BALANCE / MAX_L2_GAS_PRICE).try_into().expect("Failed to convert u128 to u64.");
    let max_l1_data_gas_price: u64 =

Suggestion:

max_l1_data_gas_amount

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 5f62898 to f0da620 Compare October 1, 2024 15:42
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: 1 of 4 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/blockifier/src/transaction/transactions_test.rs line 912 at r4 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Nope, it should be max amount (balance >= price * amount)

Done. Sorry, I must have been super tired 😬


crates/blockifier/src/transaction/transactions_test.rs line 961 at r4 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Why can't we just use the maxes instead of the mins (and then avoid defining them)? I assume we fail on the per resource assertion before the total balance assertion.

  1. It wouldn't help if min_amount>`max_amount' (as was the case before the bug-fix)
  2. It's better to make the test as tight as possible; I'm adding the min_amount only because it's necessary, putting max_amount slightly defeats the point of the test.

crates/blockifier/src/transaction/transactions_test.rs line 969 at r4 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

The bug? Do you mean that min_amount could have been larger than the max_amount and now it doesn't? I don't understand what happened

There was a bug that made the l2_gas_price super high, so the max_amount was very low (in particular, lower than min_amount); now that it's back to normal, there's no reason min_amount should be bigger than max_amount (though, technically, it can happen...). Your call if you want me to insert max(...).


crates/blockifier/src/transaction/transactions_test.rs line 971 at r8 (raw file):

    let min_l2_amount = 445500;
    let min_l1_data_amount = 128;
    let max_l2_gas_price: u64 =

Done.


crates/blockifier/src/transaction/transactions_test.rs line 973 at r8 (raw file):

    let max_l2_gas_price: u64 =
        (BALANCE / MAX_L2_GAS_PRICE).try_into().expect("Failed to convert u128 to u64.");
    let max_l1_data_gas_price: u64 =

Done.

Copy link
Contributor

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


crates/blockifier/src/transaction/transactions_test.rs line 968 at r4 (raw file):

Previously, aner-starkware wrote…

I didn't understand your suggestion.

Never mind, too much of a change, I'll try to open a PR later on.


crates/blockifier/src/transaction/transactions_test.rs line 969 at r4 (raw file):

Previously, aner-starkware wrote…

There was a bug that made the l2_gas_price super high, so the max_amount was very low (in particular, lower than min_amount); now that it's back to normal, there's no reason min_amount should be bigger than max_amount (though, technically, it can happen...). Your call if you want me to insert max(...).

Replace with asserts that max_amount/3 >= min_amount


crates/blockifier/src/transaction/transactions_test.rs line 964 at r8 (raw file):

        class_info,
    );
    assert_failure_if_resource_bounds_exceed_balance(state, block_context, invalid_tx);

Suggestion:

    // V3 invoke.
    
    for (l1_max_amount, l2_max_amount, l1_data_max_amount) in [
        (max_l1_gas_price + 1, min_l2_amount, min_l1_data_amount),
        (min_l1_amount, max_l2_gas_price + 1, min_l1_data_amount),
        (min_l1_amount, min_l2_amount, max_l1_data_gas_price + 1),
        (max_l1_gas_price / 3 + 1, max_l2_gas_price / 3 + 1, max_l1_data_gas_price / 3 + 1),
    ] {
        let invalid_resource_bounds = ValidResourceBounds::AllResources(AllResourceBounds {
            l1_gas: ResourceBounds {
                max_amount: l1_max_amount,
                max_price_per_unit: MAX_L1_GAS_PRICE,
            },
            l2_gas: ResourceBounds {
                max_amount: l2_max_amount,
                max_price_per_unit: MAX_L2_GAS_PRICE,
            },
            l1_data_gas: ResourceBounds {
                max_amount: l1_data_max_amount,
                max_price_per_unit: MAX_L1_DATA_GAS_PRICE,
            },
        });

    let invalid_tx = account_invoke_tx(invoke_tx_args! {
        resource_bounds: invalid_l1_resource_bounds,
        ..default_args.clone()
    });
    assert_failure_if_resource_bounds_exceed_balance(state, block_context, invalid_tx);

    // Deploy.
    let invalid_tx = AccountTransaction::DeployAccount(deploy_account_tx(
        deploy_account_tx_args! {
            resource_bounds: max_l1_resource_bounds,
            class_hash: test_contract.get_class_hash()
        },
        &mut NonceManager::default(),
    ));
    assert_failure_if_resource_bounds_exceed_balance(state, block_context, invalid_tx);

    // Declare.
    let contract_to_declare = FeatureContract::Empty(CairoVersion::Cairo1);
    let class_info = calculate_class_info_for_testing(contract_to_declare.get_class());
    let invalid_tx = declare_tx(
        declare_tx_args! {
            class_hash: contract_to_declare.get_class_hash(),
            compiled_class_hash: contract_to_declare.get_compiled_class_hash(),
            sender_address: account_contract_address,
            resource_bounds: invalid_l1_resource_bounds,
        },
        class_info,
    );
    assert_failure_if_resource_bounds_exceed_balance(state, block_context, invalid_tx);

Copy link
Contributor

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


crates/blockifier/src/transaction/transactions_test.rs line 968 at r4 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Never mind, too much of a change, I'll try to open a PR later on.

FYI https://reviewable.io/reviews/starkware-libs/sequencer/1228

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch 2 times, most recently from 42f5a52 to ddca4aa Compare October 7, 2024 12:45
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 4 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/blockifier/src/transaction/transactions_test.rs line 969 at r4 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Replace with asserts that max_amount/3 >= min_amount

Done.

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from ddca4aa to f1233e6 Compare October 7, 2024 17:31
Copy link
Contributor

@TzahiTaub TzahiTaub 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 3 files at r12.
Reviewable status: 1 of 4 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @nimrod-starkware)

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch 2 times, most recently from d4feb60 to db4962d Compare October 13, 2024 11:07
@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from db4962d to 5c6940f Compare October 27, 2024 13:15
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@TzahiTaub TzahiTaub 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 4 files at r13, 3 of 3 files at r15, all commit messages.
Reviewable status: 4 of 5 files reviewed, 3 unresolved discussions (waiting on @aner-starkware, @dorimedini-starkware, and @nimrod-starkware)


crates/blockifier/src/test_utils.rs line 105 at r15 (raw file):

pub const MAX_L1_GAS_PRICE: NonzeroGasPrice = DEFAULT_STRK_L1_GAS_PRICE;
pub const MAX_RESOURCE_COMMITMENT: Fee =
    DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(MAX_L1_GAS_PRICE);

Not used

Code quote:

pub const MAX_RESOURCE_COMMITMENT: Fee =
    DEFAULT_L1_GAS_AMOUNT.nonzero_saturating_mul(MAX_L1_GAS_PRICE);

crates/blockifier/src/transaction/transactions_test.rs line 937 at r15 (raw file):

    #[values(CairoVersion::Cairo0, CairoVersion::Cairo1)] account_cairo_version: CairoVersion,
) {
    use starknet_api::execution_resources::GasAmount;

move up


crates/starknet_api/src/execution_resources.rs line 28 at r15 (raw file):

    Hash,
)]
#[cfg_attr(any(test, feature = "testing"), derive(derive_more::Div))]

Suggestion:

#[cfg_attr(
    any(test, feature = "testing"),
    derive(derive_more::Add, derive_more::Div, derive_more::Sum, derive_more::AddAssign)
)]
#[derive(
    derive_more::Display,
    Clone,
    Copy,
    Debug,
    Default,
    Eq,
    PartialEq,
    PartialOrd,
    Ord,
    Serialize,
    Deserialize,
    Hash,
)]

@aner-starkware aner-starkware force-pushed the aner/pre_validation_covers_sum_of_products_2 branch from 5c6940f to 52ec5c8 Compare October 30, 2024 10:01
Copy link

Artifacts upload triggered. View details here

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: 1 of 5 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/blockifier/src/test_utils.rs line 105 at r15 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

Not used

Done.


crates/blockifier/src/transaction/transactions_test.rs line 937 at r15 (raw file):

Previously, TzahiTaub (Tzahi) wrote…

move up

Done.


crates/starknet_api/src/execution_resources.rs line 28 at r15 (raw file):

    Hash,
)]
#[cfg_attr(any(test, feature = "testing"), derive(derive_more::Div))]

Done.

Copy link
Contributor

@TzahiTaub TzahiTaub 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 3 of 3 files at r16, all commit messages.
Reviewable status: 4 of 5 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @nimrod-starkware)

Copy link
Contributor

@TzahiTaub TzahiTaub 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 3 files at r5.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @aner-starkware)

@aner-starkware aner-starkware merged commit b52bd3e into main Oct 30, 2024
15 checks passed
@aner-starkware aner-starkware deleted the aner/pre_validation_covers_sum_of_products_2 branch October 30, 2024 15:35
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2024
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.

2 participants