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): global validate and execute sierra_gas #2596

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

aner-starkware
Copy link
Contributor

No description provided.

@aner-starkware aner-starkware self-assigned this Dec 9, 2024
@reviewable-StarkWare
Copy link

This change is Reviewable

@aner-starkware aner-starkware changed the base branch from main to aner/global_max_sierra_gas_2 December 9, 2024 15:35
@aner-starkware aner-starkware changed the title Aner/global max sierra gas 3 test(blockifier): global validate and execute sierra_gas; invoke Dec 9, 2024
@aner-starkware aner-starkware changed the title test(blockifier): global validate and execute sierra_gas; invoke test(blockifier): global validate and execute sierra_gas Dec 9, 2024
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.28%. Comparing base (bda947b) to head (603bea0).

Additional details and impacted files
@@                       Coverage Diff                        @@
##           aner/global_max_sierra_gas_2    #2596      +/-   ##
================================================================
- Coverage                         75.85%   68.28%   -7.57%     
================================================================
  Files                               109      105       -4     
  Lines                             14440    14356      -84     
  Branches                          14440    14356      -84     
================================================================
- Hits                              10953     9803    -1150     
- Misses                             3004     4124    +1120     
+ Partials                            483      429      -54     

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

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from 408101f to 2004c14 Compare December 10, 2024 11:36
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 4 of 5 files at r1, 1 of 1 files at r2, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @aner-starkware)


crates/blockifier/src/transaction/test_utils.rs line 98 at r2 (raw file):

    l2_gas_amount: GasAmount,
    l1_data_gas_amount: GasAmount,
) -> ValidResourceBounds {

consider making this input a GasVector

Suggestion:

pub fn create_gas_amount_bounds_with_default_price(
    GasVector { l1_gas, l2_gas, l1_data_gas }
) -> ValidResourceBounds {

crates/blockifier/src/transaction/test_utils.rs line 107 at r2 (raw file):

        DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
    )
}

cool!
I see three places where this function can be dropped in; can you search for usages of create_all_resource_bounds and use this util where applicable?

Code quote:

pub fn create_gas_amount_bounds_with_default_price(
    l1_gas_amount: GasAmount,
    l2_gas_amount: GasAmount,
    l1_data_gas_amount: GasAmount,
) -> ValidResourceBounds {
    create_all_resource_bounds(
        l1_gas_amount,
        DEFAULT_STRK_L1_GAS_PRICE.into(),
        l2_gas_amount,
        DEFAULT_STRK_L2_GAS_PRICE.into(),
        l1_data_gas_amount,
        DEFAULT_STRK_L1_DATA_GAS_PRICE.into(),
    )
}

crates/blockifier/src/transaction/test_utils.rs line 117 at r2 (raw file):

pub fn versioned_constants(block_context: BlockContext) -> VersionedConstants {
    block_context.versioned_constants().clone()
}

can you use references...? cloning the VC can be slow if it really copies data,
VC instances should be 'static refs so no cloning should be necessary unless the test edits the VC
non-blocking

Code quote:

pub fn versioned_constants(block_context: BlockContext) -> VersionedConstants {
    block_context.versioned_constants().clone()
}

crates/blockifier/feature_contracts/cairo1/test_contract.cairo line 654 at r2 (raw file):

    fn return_result(ref self: ContractState, num: felt252) -> felt252 {
        let result = num;
        result

this doesn't compile? non-blocking

Suggestion:

        num

crates/blockifier/src/transaction/transactions_test.rs line 2620 at r2 (raw file):

#[test]
fn test_balance_print() {
    let int = balance_to_big_uint(&Felt::from(16_u64), &Felt::from(1_u64));

in both tests: deprecated tx testing is also required, not just different user bounds in V3 txs.
I suggest changing the type of #[case] param you have, from ResourceBounds to InvokeTxArgs / DeployAccountTxArgs. also pass a version field (v1 or v3) and a max_fee field if the version is v1. this will require very minimal changes to inputs, though you will need to update the checks as well.


crates/blockifier/src/transaction/transactions_test.rs line 2630 at r2 (raw file):

    GasAmount(0)
))]
#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(GasAmount(1652), versioned_constants.validate_max_sierra_gas + GasAmount(1234567), GasAmount(0)))]

break lines

Code quote:

#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(GasAmount(1652), versioned_constants.validate_max_sierra_gas + GasAmount(1234567), GasAmount(0)))]

crates/blockifier/src/transaction/transactions_test.rs line 2707 at r2 (raw file):

        // DOES THIS MAKE SENSE?!
        actual_execute_initial_gas
            - actual_execution_info.execute_call_info.as_ref().unwrap().execution.gas_consumed

hmmm... it looks like the initial gas of the inner call actually takes into account the gas consumption of the entire tree, right?
that doesn't sound right
@Yoni-Starkware ?

Code quote:

        // DOES THIS MAKE SENSE?!
        actual_execute_initial_gas
            - actual_execution_info.execute_call_info.as_ref().unwrap().execution.gas_consumed

crates/blockifier/src/transaction/transactions_test.rs line 2720 at r2 (raw file):

    GasAmount(0)
))]
#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(GasAmount(2203), versioned_constants.validate_max_sierra_gas + GasAmount(1234567), GasAmount(0)))]

break lines

Code quote:

#[case::user_bounds_between_validate_and_execute(create_gas_amount_bounds_with_default_price(GasAmount(2203), versioned_constants.validate_max_sierra_gas + GasAmount(1234567), GasAmount(0)))]

crates/blockifier/src/transaction/transactions_test.rs line 2759 at r2 (raw file):

            )
            .unwrap();
    }

we have a fund_account test util for this

Code quote:

    for fee_type in FeeType::iter() {
        state
            .set_storage_at(
                chain_info.fee_token_address(&fee_type),
                deployed_account_balance_key,
                felt!(BALANCE.0),
            )
            .unwrap();
    }

crates/blockifier/src/transaction/transactions_test.rs line 2781 at r2 (raw file):

                .validate_max_sierra_gas
                .min(GasAmount(
                    actual_execute_initial_gas

isn't this the expected amount to subtract from...?

Suggestion:

user_initial_gas

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch 4 times, most recently from 5fd6f90 to 6b29c9a Compare December 10, 2024 14:08
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: 3 of 7 files reviewed, 7 unresolved discussions (waiting on @dorimedini-starkware)


crates/blockifier/feature_contracts/cairo1/test_contract.cairo line 654 at r2 (raw file):

Previously, dorimedini-starkware wrote…

this doesn't compile? non-blocking

Compiles. I just tried to make it as similar to the Cairo0 function as possible (though it's subjective).


crates/blockifier/src/transaction/test_utils.rs line 98 at r2 (raw file):

Previously, dorimedini-starkware wrote…

consider making this input a GasVector

Good idea!


crates/blockifier/src/transaction/test_utils.rs line 107 at r2 (raw file):

Previously, dorimedini-starkware wrote…

cool!
I see three places where this function can be dropped in; can you search for usages of create_all_resource_bounds and use this util where applicable?

Done.


crates/blockifier/src/transaction/test_utils.rs line 117 at r2 (raw file):

Previously, dorimedini-starkware wrote…

can you use references...? cloning the VC can be slow if it really copies data,
VC instances should be 'static refs so no cloning should be necessary unless the test edits the VC
non-blocking

Not sure. I can try, but there seem to be issues with borrowing & lifetimes.


crates/blockifier/src/transaction/transactions_test.rs line 2630 at r2 (raw file):

Previously, dorimedini-starkware wrote…

break lines

Done.


crates/blockifier/src/transaction/transactions_test.rs line 2720 at r2 (raw file):

Previously, dorimedini-starkware wrote…

break lines

Done.


crates/blockifier/src/transaction/transactions_test.rs line 2781 at r2 (raw file):

Previously, dorimedini-starkware wrote…

isn't this the expected amount to subtract from...?

Done.

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from 6b29c9a to 8b3304c Compare December 10, 2024 14:14
@aner-starkware
Copy link
Contributor Author

crates/blockifier/src/transaction/transactions_test.rs line 2759 at r2 (raw file):

Previously, dorimedini-starkware wrote…

we have a fund_account test util for this

Done.

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 4 of 4 files at r6, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @aner-starkware)


crates/blockifier/src/transaction/post_execution_test.rs line 265 at r6 (raw file):

    use starknet_api::execution_resources::GasVector;

    use crate::transaction::test_utils::create_gas_amount_bounds_with_default_price;

move to top

Code quote:

    use starknet_api::execution_resources::GasVector;

    use crate::transaction::test_utils::create_gas_amount_bounds_with_default_price;

crates/blockifier/src/transaction/account_transactions_test.rs line 197 at r6 (raw file):

    #[values(true, false)] zero_bounds: bool,
) {
    use crate::transaction::test_utils::create_gas_amount_bounds_with_default_price;

move to top

Code quote:

use crate::transaction::test_utils::create_gas_amount_bounds_with_default_price;

crates/blockifier/src/transaction/transactions_test.rs line 2614 at r6 (raw file):

#[rstest]
#[case::small_user_bounds(create_gas_amount_bounds_with_default_price(
    GasVector{ l1_gas: GasAmount(1652), l2_gas: GasAmount(654321), l1_data_gas: GasAmount(0) }

is this over 100 chars? need to line break if so

Code quote:

GasVector{ l1_gas: GasAmount(1652), l2_gas: GasAmount(654321), l1_data_gas: GasAmount(0) }

crates/blockifier/src/transaction/transactions_test.rs line 2708 at r6 (raw file):

#[rstest]
#[case::small_user_bounds(create_gas_amount_bounds_with_default_price(
    GasVector{ l1_gas: GasAmount(2203), l1_data_gas: GasAmount(0), l2_gas: GasAmount(654321) }

line break?

Code quote:

GasVector{ l1_gas: GasAmount(2203), l1_data_gas: GasAmount(0), l2_gas: GasAmount(654321) }

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from e575f59 to bbd9bea Compare December 10, 2024 14:28
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from 8b3304c to ca1fe92 Compare December 10, 2024 14:57
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 3 of 7 files at r7, 4 of 4 files at r8, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @aner-starkware)

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from bbd9bea to 825b072 Compare December 10, 2024 15:07
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from ca1fe92 to 29742c2 Compare December 10, 2024 15:11
Copy link
Collaborator

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


crates/blockifier/src/transaction/transactions_test.rs line 2707 at r2 (raw file):

Previously, dorimedini-starkware wrote…

hmmm... it looks like the initial gas of the inner call actually takes into account the gas consumption of the entire tree, right?
that doesn't sound right
@Yoni-Starkware ?

It is only possible if the inner call has gas_consumed 0 and the caller exists immediately after the call; please check that.
It can happen if the function is super cheap - below 10K gas (remember we put the initial 10K on the caller)

If it's indeed the case, please make the inner call more expensive.


crates/blockifier/src/transaction/transactions_test.rs line 2656 at r10 (raw file):

    let contract_tracked_resource = test_contract
        .get_runnable_class()
        .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas, None);

Right?
If this account is the caller of the test contract.

I don't know what's the intention of this test though

Suggestion:

    let contract_tracked_resource = test_contract
        .get_runnable_class()
        .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas, account_tracked_resource);

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from 29742c2 to ee5e587 Compare December 15, 2024 05:15
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: 3 of 7 files reviewed, 7 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)


crates/blockifier/src/transaction/account_transactions_test.rs line 197 at r6 (raw file):

Previously, dorimedini-starkware wrote…

move to top

Done.


crates/blockifier/src/transaction/post_execution_test.rs line 265 at r6 (raw file):

Previously, dorimedini-starkware wrote…

move to top

Done.


crates/blockifier/src/transaction/transactions_test.rs line 2620 at r2 (raw file):

Previously, dorimedini-starkware wrote…

in both tests: deprecated tx testing is also required, not just different user bounds in V3 txs.
I suggest changing the type of #[case] param you have, from ResourceBounds to InvokeTxArgs / DeployAccountTxArgs. also pass a version field (v1 or v3) and a max_fee field if the version is v1. this will require very minimal changes to inputs, though you will need to update the checks as well.

Sounds like it's not such a small change; added a TODO and will do it in the next PR. Though I'm not actually sure I understand what it is that I'm supposed to check and what is the expected result.


crates/blockifier/src/transaction/transactions_test.rs line 2707 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

It is only possible if the inner call has gas_consumed 0 and the caller exists immediately after the call; please check that.
It can happen if the function is super cheap - below 10K gas (remember we put the initial 10K on the caller)

If it's indeed the case, please make the inner call more expensive.

Done. Though I'm not sure I completely understand the logic here.


crates/blockifier/src/transaction/transactions_test.rs line 2614 at r6 (raw file):

Previously, dorimedini-starkware wrote…

is this over 100 chars? need to line break if so

I don't think it is. There are longer lines above, for example in test_balance_print.


crates/blockifier/src/transaction/transactions_test.rs line 2708 at r6 (raw file):

Previously, dorimedini-starkware wrote…

line break?

I don't think it's needed here.


crates/blockifier/src/transaction/transactions_test.rs line 2656 at r10 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Right?
If this account is the caller of the test contract.

I don't know what's the intention of this test though

Done. It's for the inner call initial_gas check.

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from ee5e587 to a138a4c Compare December 15, 2024 05:17
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from 825b072 to 37ff6e0 Compare December 15, 2024 05:26
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from a138a4c to b4b52ec Compare December 15, 2024 05:31
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from 37ff6e0 to bda947b Compare December 15, 2024 05:44
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from b4b52ec to 603bea0 Compare December 15, 2024 05:45
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 4 of 4 files at r14, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)


crates/blockifier/src/transaction/transactions_test.rs line 2620 at r2 (raw file):

Previously, aner-starkware wrote…

Sounds like it's not such a small change; added a TODO and will do it in the next PR. Though I'm not actually sure I understand what it is that I'm supposed to check and what is the expected result.

we want to test that sierra gas tracking works, regardless of the tx version / resource bounds.
you are currently only testing v3.
unblocking; maybe it's not such a small change, although I think if you parametrize like this

#[case(InvokeTxArgs { resource_bounds: default_l1_bounds(), ..Default::default() })]
#[case(InvokeTxArgs { resource_bounds: default_all_bounds(), ..Default::default() })]
#[case(InvokeTxArgs { max_fee: MAX_FEE, ..Default::default() })]
fn test_...(tx_args: InvokeTxArgs, ...) {
...
    let invoke_tx = account_invoke_tx(InvokeTxArgs {
        <your params>,
        ...tx_args
    }

... it should work ok

@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from bda947b to ac4ed34 Compare December 15, 2024 19:53
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from 603bea0 to e5e7392 Compare December 15, 2024 19:54
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_2 branch from ac4ed34 to 444ca94 Compare December 16, 2024 09:22
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch from e5e7392 to 1b011e4 Compare December 16, 2024 09:23
@aner-starkware aner-starkware changed the base branch from aner/global_max_sierra_gas_2 to main December 16, 2024 13:05
@aner-starkware aner-starkware force-pushed the aner/global_max_sierra_gas_3 branch 2 times, most recently from 8784fc8 to 17bc607 Compare December 16, 2024 15:37
@aner-starkware
Copy link
Contributor Author

crates/blockifier/src/transaction/transactions_test.rs line 2620 at r2 (raw file):

Previously, dorimedini-starkware wrote…

we want to test that sierra gas tracking works, regardless of the tx version / resource bounds.
you are currently only testing v3.
unblocking; maybe it's not such a small change, although I think if you parametrize like this

#[case(InvokeTxArgs { resource_bounds: default_l1_bounds(), ..Default::default() })]
#[case(InvokeTxArgs { resource_bounds: default_all_bounds(), ..Default::default() })]
#[case(InvokeTxArgs { max_fee: MAX_FEE, ..Default::default() })]
fn test_...(tx_args: InvokeTxArgs, ...) {
...
    let invoke_tx = account_invoke_tx(InvokeTxArgs {
        <your params>,
        ...tx_args
    }

... it should work ok

Done. (Merged commit above)

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.

Dismissed @Yoni-Starkware from a discussion.
Reviewable status: 3 of 7 files reviewed, all discussions resolved (waiting on @dorimedini-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 3 of 4 files at r16, 1 of 1 files at r17, all commit messages.
Reviewable status: :shipit: complete! all 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.

:lgtm:

Reviewed 3 of 4 files at r19, 1 of 1 files at r20, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @aner-starkware)

@aner-starkware aner-starkware merged commit 21cd7a8 into main Dec 17, 2024
12 checks passed
@aner-starkware aner-starkware deleted the aner/global_max_sierra_gas_3 branch December 17, 2024 10:21
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 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.

4 participants