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

feat(blockifier): add get_syscall_gas_cost to versioned constants impl #2188

Conversation

Yonatan-Starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants.rs line 347 at r1 (raw file):

        let mut total_builtin_gas_cost: u64 = 0;
        for (builtin, amount) in &execution_resources.builtin_instance_counter {
            let builtin_cost = constant_gas_costs.get_builtin_gas_cost(builtin).unwrap_or(0);

for now, returning zero by default in the case of unsupported builtin. Would love to consider a better way to handle this error.

Copy link

codecov bot commented Nov 19, 2024

Codecov Report

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

Project coverage is 68.84%. Comparing base (e3165c4) to head (e5ebc1e).
Report is 613 commits behind head on main.

Files with missing lines Patch % Lines
crates/blockifier/src/versioned_constants.rs 96.29% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2188       +/-   ##
===========================================
+ Coverage   40.10%   68.84%   +28.74%     
===========================================
  Files          26      108       +82     
  Lines        1895    14025    +12130     
  Branches     1895    14025    +12130     
===========================================
+ Hits          760     9656     +8896     
- Misses       1100     3956     +2856     
- Partials       35      413      +378     

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

@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants_test.rs line 177 at r1 (raw file):

    assert_eq!(versioned_constants.get_syscall_gas_cost(&SyscallSelector::CallContract), 87650);
    assert_eq!(versioned_constants.get_syscall_gas_cost(&SyscallSelector::Secp256k1Mul), 8143650);
    assert_eq!(versioned_constants.get_syscall_gas_cost(&SyscallSelector::Sha256ProcessBlock), 841095);

will change the magic numbers to one of two options:
(1) named constants as in other tests
(2)the matching value in the GasCosts struct.

The problem with the first option is that it will require maintenance every time the values in the json will change.
The problem with the second option is that after we will delete the gas costs from the OsConstants as planned it will become a bug.

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: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @Yonatan-Starkware)


crates/blockifier/src/versioned_constants.rs line 347 at r1 (raw file):

Previously, Yonatan-Starkware wrote…

for now, returning zero by default in the case of unsupported builtin. Would love to consider a better way to handle this error.

It's okay to panic. All builtins should be there.


crates/blockifier/src/versioned_constants.rs line 337 at r1 (raw file):

    /// Calculates a syscall's gas costs from the os resources
    pub fn get_syscall_gas_cost(&self, syscall_selector: &SyscallSelector) -> u64 {
        let constant_gas_costs = &self.os_constants.gas_costs;

Suggestion:

 gas_costs 

crates/blockifier/src/versioned_constants.rs line 343 at r1 (raw file):

            .get(syscall_selector)
            .expect("Fetching the execution resources of a syscall should not fail.");
        let n_steps = std::cmp::max(u64_from_usize(execution_resources.n_steps), 100);

The max should be with syscall_base_gas_cost.
We should take the max at the end of the calculation. This will require further changes in python.
cc @meship-starkware

Suggestion:

        // The minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler.
        let n_steps = std::cmp::max(u64_from_usize(execution_resources.n_steps), 100);

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 1624253 to 4bae353 Compare November 24, 2024 09:02
@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants.rs line 347 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

It's okay to panic. All builtins should be there.

Done.

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 2441d87 to 54def71 Compare November 24, 2024 09:51
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 86f183e to 215da8b Compare November 24, 2024 09:52
Copy link

Artifacts upload triggered. View details here

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 54def71 to 2f133bb Compare November 24, 2024 09:59
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 215da8b to 2ea8126 Compare November 24, 2024 10:04
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 2f133bb to 7f1ff03 Compare November 24, 2024 10:06
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 2ea8126 to 7363e9e Compare November 24, 2024 10:06
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 7363e9e to 9024d8b Compare November 24, 2024 11:20
Copy link

Artifacts upload triggered. View details here

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 7f1ff03 to 87d6285 Compare November 24, 2024 11:40
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 9024d8b to 9b0da15 Compare November 24, 2024 11:40
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch from 87d6285 to 5d273b8 Compare November 24, 2024 11:50
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 9b0da15 to 031e2fa Compare November 24, 2024 11:50
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 8e62d52 to 3aa46ab Compare November 24, 2024 12:48
@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants_test.rs line 177 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Why do you need this test? What does it give you that the syscalls test does not?

for now the function is just there, nothing call it. so by adding the test i verify that it works correctly, and prevent the error of it being unused

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 3aa46ab to dbae55c Compare November 24, 2024 13:33
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_impl_for_gas_cost branch 3 times, most recently from 9619604 to 640e1dc Compare November 24, 2024 14:07
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from dbae55c to 58755ee Compare November 24, 2024 14:22
@Yonatan-Starkware Yonatan-Starkware changed the base branch from yonatank/blockifier/add_impl_for_gas_cost to graphite-base/2188 November 24, 2024 14:56
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 58755ee to d7b5bc8 Compare November 24, 2024 14:56
@Yonatan-Starkware Yonatan-Starkware changed the base branch from graphite-base/2188 to main November 24, 2024 14:57
@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from d7b5bc8 to c0ec97c Compare November 24, 2024 14:57
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.

Reviewed all commit messages.
Reviewable status: 0 of 2 files reviewed, 6 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @Yonatan-Starkware)


crates/blockifier/src/versioned_constants.rs line 343 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

this will break Python. Lets put in the Os_constants the number according to the calculation without the max and add the maximum where needed. @Yoni-Starkware WDYT?

@meship-starkware why? he is not using this func yet
@Yonatan-Starkware please add my comment.


crates/blockifier/src/versioned_constants.rs line 335 at r3 (raw file):

    }

    /// Calculates a syscall's gas costs from the os resources

Suggestion:

/// Calculates the syscall gas cost from the OS resources.

crates/blockifier/src/versioned_constants.rs line 346 at r3 (raw file):

        let n_memory_holes = u64_from_usize(execution_resources.n_memory_holes);
        let mut total_builtin_gas_cost: u64 = 0;
        for (builtin, amount) in &execution_resources.builtin_instance_counter {

Use rust style instead (iter + map + sum)

Code quote:

        let mut total_builtin_gas_cost: u64 = 0;
        for (builtin, amount) in &execution_resources.builtin_instance_counter {

crates/blockifier/src/versioned_constants.rs line 349 at r3 (raw file):

            let builtin_cost = gas_costs
                .get_builtin_gas_cost(builtin)
                .unwrap_or_else(|err| panic!("Failed to get gas cost: {}", err));

Suggestion:

(|err| panic!("Failed to get gas cost: {}.",

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: 0 of 2 files reviewed, 6 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @Yonatan-Starkware)


crates/blockifier/src/versioned_constants_test.rs line 177 at r1 (raw file):

Previously, Yonatan-Starkware wrote…

for now the function is just there, nothing call it. so by adding the test i verify that it works correctly, and prevent the error of it being unused

Sounds good


crates/blockifier/src/versioned_constants_test.rs line 172 at r3 (raw file):

#[test]
fn test_correct_syscall_gas_cost_calculation() {

Suggestion:

fn test_syscall_gas_cost_calculation() {

@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants.rs line 349 at r3 (raw file):

            let builtin_cost = gas_costs
                .get_builtin_gas_cost(builtin)
                .unwrap_or_else(|err| panic!("Failed to get gas cost: {}", err));

there is already a coma in the error mesegge itself.

@Yonatan-Starkware
Copy link
Contributor Author

crates/blockifier/src/versioned_constants.rs line 349 at r3 (raw file):

Previously, Yonatan-Starkware wrote…

there is already a coma in the error mesegge itself.

the messege that goes into the curly braces

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch 3 times, most recently from 7bf221e to 03ea98e Compare November 24, 2024 16:18
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: 0 of 2 files reviewed, 4 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @Yonatan-Starkware)


crates/blockifier/src/versioned_constants.rs line 343 at r4 (raw file):

            .get(syscall_selector)
            .expect("Fetching the execution resources of a syscall should not fail.");
        // The minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler.

Move the message down to the cmp

Code quote:

// The minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler.

Copy link
Contributor

@meship-starkware meship-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: 1 of 2 files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @Yonatan-Starkware)


crates/blockifier/src/versioned_constants.rs line 343 at r1 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

@meship-starkware why? he is not using this func yet
@Yonatan-Starkware please add my comment.

Oh, I see; I'll add a Monday task to change the Python accordingly.

Copy link
Contributor

@meship-starkware meship-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 2 files at r3.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @avi-starkware and @Yonatan-Starkware)

@Yonatan-Starkware Yonatan-Starkware force-pushed the yonatank/blockifier/add_get_syscall_gas_cost_and_a_test_for_it branch from 03ea98e to e5ebc1e Compare November 28, 2024 08:03
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.

:lgtm:

Reviewed 2 of 2 files at r6, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @avi-starkware and @Yonatan-Starkware)

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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @avi-starkware)

@Yonatan-Starkware Yonatan-Starkware merged commit 8edd6d7 into main Nov 28, 2024
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 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