Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/apollo_deployments/resources/base_app_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.n_events": 5000,
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.n_txs": 2000,
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.sierra_gas": 4000000000,
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": 4000000000,
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": 5000000000,
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.state_diff_size": 4000,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": 8100,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": 10125,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check": 70,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": 1333333,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": 571900,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": 1666666,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": 714875,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.bitwise": 583,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": 408566,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": 8334,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": 250,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": 510707,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": 6250,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": 312,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.mul_mod": 604,
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check96": 56,
"batcher_config.block_builder_config.execute_config.n_workers": 4,
Expand Down
14 changes: 7 additions & 7 deletions crates/apollo_node/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": {
"description": "An upper bound on the total builtins and steps gas usage used in a block.",
"privacy": "Public",
"value": 4000000000
"value": 5000000000
},
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.sierra_gas": {
"description": "An upper bound on the total sierra_gas used in a block.",
Expand All @@ -57,7 +57,7 @@
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": {
"description": "Add_mod gas weight.",
"privacy": "Public",
"value": 250
"value": 312
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.bitwise": {
"description": "Bitwise gas weight.",
Expand All @@ -67,17 +67,17 @@
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": {
"description": "Ec_op gas weight.",
"privacy": "Public",
"value": 571900
"value": 714875
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": {
"description": "Ecdsa gas weight.",
"privacy": "Public",
"value": 1333333
"value": 1666666
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": {
"description": "Keccak gas weight.",
"privacy": "Public",
"value": 408566
"value": 510707
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.mul_mod": {
"description": "Mul_mod gas weight.",
Expand All @@ -87,12 +87,12 @@
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": {
"description": "Pedersen gas weight.",
"privacy": "Public",
"value": 8100
"value": 10125
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": {
"description": "Poseidon gas weight.",
"privacy": "Public",
"value": 8334
"value": 6250
},
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check": {
"description": "Range_check gas weight.",
Expand Down
14 changes: 7 additions & 7 deletions crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl Default for BouncerWeights {
n_txs: 600,
state_diff_size: 4000,
sierra_gas: GasAmount(4000000000),
proving_gas: GasAmount(4000000000),
proving_gas: GasAmount(5000000000),
}
}
}
Expand Down Expand Up @@ -373,14 +373,14 @@ impl BuiltinWeights {
impl Default for BuiltinWeights {
fn default() -> Self {
Self {
pedersen: 8100,
pedersen: 10125,
range_check: 70,
ecdsa: 1333333,
ec_op: 571900,
ecdsa: 1666666,
ec_op: 714875,
bitwise: 583,
keccak: 408566,
poseidon: 8334,
add_mod: 250,
keccak: 510707,
poseidon: 6250,
add_mod: 312,
mul_mod: 604,
range_check96: 56,
}
Expand Down
133 changes: 89 additions & 44 deletions crates/blockifier/src/bouncer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::{HashMap, HashSet};
use assert_matches::assert_matches;
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
use blockifier_test_utils::contracts::FeatureContract;
use cairo_vm::types::builtin_name::BuiltinName;
use rstest::{fixture, rstest};
use starknet_api::execution_resources::GasAmount;
use starknet_api::transaction::fields::Fee;
Expand Down Expand Up @@ -190,19 +191,49 @@ fn test_bouncer_update(#[case] initial_bouncer: Bouncer) {
assert_eq!(updated_bouncer, expected_bouncer);
}

/// This parameterized test verifies `Bouncer::try_update` behavior when varying only `sierra_gas`.
#[rstest]
#[case::positive_flow(GasAmount(1), "ok")]
#[case::block_full(GasAmount(11), "block_full")]
#[case::transaction_too_large(GasAmount(21), "too_large")]
fn test_bouncer_try_update_sierra_gas(
#[case] added_gas: GasAmount,
#[case] scenario: &'static str,
block_context: BlockContext,
block_max_capacity: BouncerWeights,
bouncer_config: BouncerConfig,
mut state: CachedState<DictStateReader>,
) {
#[case::sierra_gas_positive_flow("ok")]
#[case::sierra_gas_block_full("sierra_gas_block_full")]
#[case::proving_gas_positive_flow("ok")]
#[case::proving_gas_block_full("proving_gas_block_full")]
fn test_bouncer_try_update_gas_based(#[case] scenario: &'static str, block_context: BlockContext) {
let state = &mut test_state(&block_context.chain_info, Fee(0), &[]);
let mut transactional_state = TransactionalState::create_transactional(state);
let builtin_weights = BuiltinWeights::default();

let range_check_count = 2;
let max_capacity_builtin_counters =
HashMap::from([(BuiltinName::range_check, range_check_count)]);
let builtin_counters = match scenario {
"proving_gas_block_full" => max_capacity_builtin_counters.clone(),
// Use a minimal or empty map.
"ok" | "sierra_gas_block_full" => {
HashMap::from([(BuiltinName::range_check, range_check_count - 1)])
}
_ => panic!("Unexpected scenario: {}", scenario),
};

// Derive sierra_gas from scenario
let sierra_gas = match scenario {
"sierra_gas_block_full" => GasAmount(11), // Exceeds capacity
"ok" | "proving_gas_block_full" => GasAmount(1), // Within capacity
_ => panic!("Unexpected scenario: {}", scenario),
};

let proving_gas_max_capacity =
builtin_weights.calc_proving_gas_from_builtin_counter(&max_capacity_builtin_counters);

let block_max_capacity = BouncerWeights {
l1_gas: 20,
message_segment_length: 20,
n_events: 20,
state_diff_size: 20,
n_txs: 20,
sierra_gas: GasAmount(20),
proving_gas: proving_gas_max_capacity,
};
let bouncer_config = BouncerConfig { block_max_capacity, builtin_weights };

let accumulated_weights = BouncerWeights {
l1_gas: 10,
message_segment_length: 10,
Expand All @@ -217,57 +248,71 @@ fn test_bouncer_try_update_sierra_gas(

// Prepare the resources to be added to the bouncer.
let execution_summary = ExecutionSummary::default();
let builtin_counters = BuiltinCounterMap::default();
let tx_resources = TransactionResources {
// Only the `sierra_gas` field is varied.
computation: ComputationResources { sierra_gas: added_gas, ..Default::default() },
computation: ComputationResources { sierra_gas, ..Default::default() },
..Default::default()
};
let mut transactional_state = TransactionalState::create_transactional(&mut state);
let tx_state_changes_keys = transactional_state.to_state_diff().unwrap().state_maps.keys();

// TODO(Yoni, 1/10/2024): simplify this test and move tx-too-large cases out.
let result = bouncer.try_update(
&transactional_state,
&tx_state_changes_keys,
&execution_summary,
&builtin_counters,
&tx_resources,
&block_context.versioned_constants,
);

match scenario {
"ok" => assert_matches!(result, Ok(())),
"proving_gas_block_full" | "sierra_gas_block_full" => {
assert_matches!(result, Err(TransactionExecutorError::BlockFull))
}
_ => panic!("Unexpected scenario: {}", scenario),
}
}

#[rstest]
fn test_transaction_too_large_sierra_gas_based(block_context: BlockContext) {
let mut state = test_state(&block_context.chain_info, Fee(0), &[]);
let mut transactional_state = TransactionalState::create_transactional(&mut state);
let block_max_capacity = BouncerWeights { sierra_gas: GasAmount(20), ..Default::default() };
let bouncer_config =
BouncerConfig { block_max_capacity, builtin_weights: BuiltinWeights::default() };

// Use gas amount > block_max_capacity's.
let exceeding_gas = GasAmount(30);
let execution_summary = ExecutionSummary::default();
let builtin_counters = BuiltinCounterMap::default();
let tx_resources = TransactionResources {
computation: ComputationResources { sierra_gas: exceeding_gas, ..Default::default() },
..Default::default()
};
let tx_state_changes_keys = transactional_state.to_state_diff().unwrap().state_maps.keys();

// Check that the transaction is not too large.
let mut result = verify_tx_weights_within_max_capacity(
let result = verify_tx_weights_within_max_capacity(
&transactional_state,
&execution_summary,
&builtin_counters,
&tx_resources,
&tx_state_changes_keys,
&bouncer.bouncer_config,
&bouncer_config,
&block_context.versioned_constants,
)
.map_err(TransactionExecutorError::TransactionExecutionError);

let expected_weights = BouncerWeights {
sierra_gas: added_gas,
sierra_gas: exceeding_gas,
n_txs: 1,
proving_gas: added_gas,
proving_gas: exceeding_gas,
..BouncerWeights::empty()
};

if result.is_ok() {
// Try to update the bouncer.
result = bouncer.try_update(
&transactional_state,
&tx_state_changes_keys,
&execution_summary,
&builtin_counters,
&tx_resources,
&block_context.versioned_constants,
);
}

match scenario {
"ok" => assert_matches!(result, Ok(())),
"block_full" => assert_matches!(result, Err(TransactionExecutorError::BlockFull)),
"too_large" => assert_matches!(result, Err(
TransactionExecutorError::TransactionExecutionError(
TransactionExecutionError::TransactionTooLarge { max_capacity, tx_size }
)
) if *max_capacity == block_max_capacity && *tx_size == expected_weights),
_ => panic!("Unexpected scenario: {}", scenario),
}
assert_matches!(result, Err(
TransactionExecutorError::TransactionExecutionError(
TransactionExecutionError::TransactionTooLarge { max_capacity, tx_size }
)
) if *max_capacity == bouncer_config.block_max_capacity && *tx_size == expected_weights);
}

#[rstest]
Expand Down
1 change: 0 additions & 1 deletion crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ impl BlockContext {
n_events: max_n_events_in_block,
..BouncerWeights::max()
},
// TODO(Meshi): Check what should be the values here.
..BouncerConfig::max()
},
..Self::create_for_account_testing()
Expand Down
Loading
Loading