-
Notifications
You must be signed in to change notification settings - Fork 65
chore(blockifier): add test_proving_gas_minus_sierra_gas_equals_builtin_gas #7686
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
chore(blockifier): add test_proving_gas_minus_sierra_gas_equals_builtin_gas #7686
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
18d95ba to
0c967b3
Compare
meship-starkware
left a comment
There was a problem hiding this 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 r2, all commit messages.
Reviewable status: 1 of 2 files reviewed, all discussions resolved (waiting on @noaov1)
meship-starkware
left a comment
There was a problem hiding this 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 r1.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @noaov1)
crates/blockifier/src/bouncer_test.rs line 313 at r2 (raw file):
#[case] executed_class_hashes: HashSet<ClassHash>, // Builtin counters for CASM hash computation. #[case] additional_os_resources: HashMap<BuiltinName, usize>,
This is for both Casm and Patricia, right?
Code quote:
#[case] additional_os_resources: HashMap<BuiltinName, usize>,crates/blockifier/src/bouncer_test.rs line 319 at r2 (raw file):
// Transaction resources builtins. let mut builtins = HashMap::from([(BuiltinName::range_check, 2), (BuiltinName::pedersen, 1)]);
Suggestion:
tx_builtin_counterscrates/blockifier/src/bouncer_test.rs line 337 at r2 (raw file):
&state, &executed_class_hashes, 0,
Suggestion:
// n_visited_storage_entries
0,crates/blockifier/src/bouncer_test.rs line 339 at r2 (raw file):
0, &tx_resources, &StateMaps::default().keys(),
Suggestion:
// state changes keys
&StateMaps::default().keys(),crates/blockifier/src/bouncer_test.rs line 364 at r2 (raw file):
let swo_gas_total = u64_from_usize(swo_gas * count); let stone_gas_total = stone_gas * u64_from_usize(*count);
Consider using a checked mul for a better error in case of overflow. It's a test, so it's not mandatory, but I think an overflow might be hard to catch.
Code quote:
let swo_gas_total = u64_from_usize(swo_gas * count);
let stone_gas_total = stone_gas * u64_from_usize(*count);
noaov1
left a comment
There was a problem hiding this 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 r1, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @avivg-starkware and @meship-starkware)
crates/blockifier/src/bouncer_test.rs line 313 at r2 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
This is for both Casm and Patricia, right?
Should be. Note that since n_visited_storage_entries = 0 we get trivial patricia update resources.
crates/blockifier/src/bouncer_test.rs line 250 at r2 (raw file):
/// Verifies that the difference between proving gas and Sierra gas is fully explained /// by the builtin gas delta (between Stone and Stwo). Covers combinations of OS computation
I'm confused.
proving_gas - sierra_gas = builtins_proving_gas,
no?
Code quote:
/// Verifies that the difference between proving gas and Sierra gas is fully explained
/// by the builtin gas delta (between Stone and Stwo). Covers combinations of OS computationcrates/blockifier/src/bouncer_test.rs line 325 at r2 (raw file):
sierra_gas: GasAmount(100), tx_vm_resources: ExecutionResources { builtin_instance_counter: builtins.clone(),
Note that, in theory, if we have sierra gas, then
builtin_instance_counter ! = builtins.
Code quote:
builtin_instance_counter: builtins.clone(),crates/blockifier/src/bouncer_test.rs line 354 at r2 (raw file):
.iter() .map(|(name, count)| { let swo_gas = block_context.bouncer_config.builtin_weights.builtin_weight(name);
Maybe proving_gas is more consistent with the code.
Suggestion:
let stwo_gas = block_context.bouncer_config.builtin_weights.builtin_weight(name);crates/blockifier/src/bouncer_test.rs line 361 at r2 (raw file):
.builtins .get_builtin_gas_cost(name) .unwrap_or_else(|_| panic!("Expected gas cost for builtin: {}", name));
It's informative enough
Suggestion:
.expect();crates/blockifier/src/bouncer_test.rs line 366 at r2 (raw file):
let stone_gas_total = stone_gas * u64_from_usize(*count); swo_gas_total - stone_gas_total
Note that this can be negative
Code quote:
swo_gas_total - stone_gas_total0c967b3 to
b1d2ab1
Compare
|
Previously, noaov1 (Noa Oved) wrote…
all gas prices of stow are currently >= stone , is this to be changed? |
b3de0fd to
6460f60
Compare
avivg-starkware
left a comment
There was a problem hiding this 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 2 files reviewed, 4 unresolved discussions (waiting on @meship-starkware and @noaov1)
crates/blockifier/src/bouncer_test.rs line 313 at r2 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Should be. Note that since
n_visited_storage_entries = 0we get trivial patricia update resources.
see refactor below ``n_visited_storage_entries != 0ifcasm_hash_computation_builtins` is not empty
6460f60 to
6cc5802
Compare
6cc5802 to
4ec8fe4
Compare
|
Previously, noaov1 (Noa Oved) wrote…
changed the Sierra to ZERO |
4ec8fe4 to
166a7fe
Compare
|
Previously, noaov1 (Noa Oved) wrote…
IIUC your question - you're right - the goal of this test is to confirm exactly that: I wrote the test to catch any potential drift if builtin accounting changes or if gas costs are misapplied across Stone/Stwo. |
meship-starkware
left a comment
There was a problem hiding this 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: all files reviewed, 3 unresolved discussions (waiting on @noaov1)
noaov1
left a comment
There was a problem hiding this 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: all files reviewed, 3 unresolved discussions (waiting on @avivg-starkware)
crates/blockifier/src/bouncer_test.rs line 366 at r2 (raw file):
Previously, avivg-starkware wrote…
all gas prices of stow are currently >= stone , is this to be changed?
This can change
avivg-starkware
left a comment
There was a problem hiding this 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, 3 unresolved discussions (waiting on @noaov1)
crates/blockifier/src/bouncer_test.rs line 366 at r2 (raw file):
Previously, noaov1 (Noa Oved) wrote…
This can change
added doc
noaov1
left a comment
There was a problem hiding this 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.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @avivg-starkware)
crates/blockifier/src/bouncer_test.rs line 254 at r5 (raw file):
/// Covers combinations of OS computation builtins and CASM hash computation builtins. #[rstest] #[case::no_os_no_casm(
Not sure if it is better
Suggestion:
#[case::no_tx_overhead_no_os_additional_cost(crates/blockifier/src/bouncer_test.rs line 312 at r5 (raw file):
#[case] contract_instances: &[(FeatureContract, u16)], #[case] os_vm_resources: ExecutionResources, #[case] executed_class_hashes: HashSet<ClassHash>,
Can this be deduced from contract_instances?
Same question for casm_hash_computation_builtins
Code quote:
#[case] executed_class_hashes: HashSet<ClassHash>,crates/blockifier/src/bouncer_test.rs line 335 at r5 (raw file):
}; // If we simulate CASM hash computation, we assume storage entries were visited. let n_visited_storage_entries = if casm_hash_computation_builtins.is_empty() { 0 } else { 1 };
Suggestion:
// The os additional resources contains both patricia updates and
// CASM hash computation.
let n_visited_storage_entries = if casm_hash_computation_builtins.is_empty() { 0 } else { 1 };crates/blockifier/src/bouncer_test.rs line 349 at r5 (raw file):
.unwrap(); // Combine TX + OS + CASM builtin usage.
What about the patricia builtins?
Suggestion:
// Combine TX + TX overhaed (OS) + CASM and patricia builtin usage.crates/blockifier/src/bouncer_test.rs line 364 at r5 (raw file):
.builtins .get_builtin_gas_cost(name) .expect("");
I meant unwrap(), sorry.
Suggestion:
.get_builtin_gas_cost(name)
.unwrap();166a7fe to
f48ced9
Compare
avivg-starkware
left a comment
There was a problem hiding this 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 2 files reviewed, 3 unresolved discussions (waiting on @meship-starkware and @noaov1)
crates/blockifier/src/bouncer_test.rs line 254 at r5 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Not sure if it is better
What do you think of the current names?
crates/blockifier/src/bouncer_test.rs line 312 at r5 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Can this be deduced from
contract_instances?
Same question forcasm_hash_computation_builtins
Done.
crates/blockifier/src/bouncer_test.rs line 349 at r5 (raw file):
Previously, noaov1 (Noa Oved) wrote…
What about the patricia builtins?
Done.
crates/blockifier/src/bouncer_test.rs line 364 at r5 (raw file):
Previously, noaov1 (Noa Oved) wrote…
I meant
unwrap(), sorry.
my bad
noaov1
left a comment
There was a problem hiding this 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: all files reviewed (commit messages unreviewed), 4 unresolved discussions (waiting on @avivg-starkware)
crates/blockifier/src/bouncer_test.rs line 255 at r6 (raw file):
#[rstest] #[case::tx_builtins_only(&[], ExecutionResources::default())] #[case::tx_builtins_plus_os_builtins(
Suggestion:
tx_builtins_plus_os_tx_builtinscrates/blockifier/src/bouncer_test.rs line 264 at r6 (raw file):
}, )] #[case::tx_builtins_plus_casm_hash_computation(
Suggestion:
tx_builtins_plus_os_additional_costcrates/blockifier/src/bouncer_test.rs line 299 at r6 (raw file):
HashMap::new() } else { HashMap::from([(BuiltinName::poseidon, 11699), (BuiltinName::pedersen, 2205)])
Please try to avoid hard-coded numbers. Consider using get_particia_update_resources and estimate_casm_hash_computation_resources.
Code quote:
HashMap::from([(BuiltinName::poseidon, 11699), (BuiltinName::pedersen, 2205)])f48ced9 to
53d4c4b
Compare
53d4c4b to
05efe2e
Compare
avivg-starkware
left a comment
There was a problem hiding this 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 2 files reviewed, 2 unresolved discussions (waiting on @noaov1)
crates/blockifier/src/bouncer_test.rs line 299 at r6 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Please try to avoid hard-coded numbers. Consider using
get_particia_update_resourcesandestimate_casm_hash_computation_resources.
Done.
meship-starkware
left a comment
There was a problem hiding this 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 r7, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @noaov1)
noaov1
left a comment
There was a problem hiding this 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 r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @avivg-starkware)
crates/blockifier/src/bouncer_test.rs line 290 at r7 (raw file):
) { use crate::bouncer::get_particia_update_resources; use crate::transaction::objects::ExecutionResourcesTraits;
Please move to the top of the file.
Code quote:
use crate::bouncer::get_particia_update_resources;
use crate::transaction::objects::ExecutionResourcesTraits;|
Previously, noaov1 (Noa Oved) wrote…
thank you!! |
meship-starkware
left a comment
There was a problem hiding this 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, 1 unresolved discussion (waiting on @noaov1)
05efe2e to
cf1cad3
Compare
meship-starkware
left a comment
There was a problem hiding this 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 r8, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @noaov1)

0.13.6