Skip to content

Commit 464f038

Browse files
Merge pull request #7736 from starkware-libs/meshi/merge-main-v0.13.6-into-main-v0.14.0-1751523971
Merge main-v0.13.6 into main-v0.14.0
2 parents e5e5a7c + 924f734 commit 464f038

File tree

7 files changed

+177
-77
lines changed

7 files changed

+177
-77
lines changed

crates/apollo_deployments/resources/base_app_config.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.n_events": 5000,
77
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.n_txs": 2000,
88
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.sierra_gas": 4000000000,
9-
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": 4000000000,
9+
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": 5000000000,
1010
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.state_diff_size": 4000,
11-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": 8100,
11+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": 10125,
1212
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check": 70,
13-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": 1333333,
14-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": 571900,
13+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": 1666666,
14+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": 714875,
1515
"batcher_config.block_builder_config.bouncer_config.builtin_weights.bitwise": 583,
16-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": 408566,
17-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": 8334,
18-
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": 250,
16+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": 510707,
17+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": 6250,
18+
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": 312,
1919
"batcher_config.block_builder_config.bouncer_config.builtin_weights.mul_mod": 604,
2020
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check96": 56,
2121
"batcher_config.block_builder_config.execute_config.n_workers": 4,

crates/apollo_node/resources/config_schema.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.proving_gas": {
4343
"description": "An upper bound on the total builtins and steps gas usage used in a block.",
4444
"privacy": "Public",
45-
"value": 4000000000
45+
"value": 5000000000
4646
},
4747
"batcher_config.block_builder_config.bouncer_config.block_max_capacity.sierra_gas": {
4848
"description": "An upper bound on the total sierra_gas used in a block.",
@@ -57,7 +57,7 @@
5757
"batcher_config.block_builder_config.bouncer_config.builtin_weights.add_mod": {
5858
"description": "Add_mod gas weight.",
5959
"privacy": "Public",
60-
"value": 250
60+
"value": 312
6161
},
6262
"batcher_config.block_builder_config.bouncer_config.builtin_weights.bitwise": {
6363
"description": "Bitwise gas weight.",
@@ -67,17 +67,17 @@
6767
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ec_op": {
6868
"description": "Ec_op gas weight.",
6969
"privacy": "Public",
70-
"value": 571900
70+
"value": 714875
7171
},
7272
"batcher_config.block_builder_config.bouncer_config.builtin_weights.ecdsa": {
7373
"description": "Ecdsa gas weight.",
7474
"privacy": "Public",
75-
"value": 1333333
75+
"value": 1666666
7676
},
7777
"batcher_config.block_builder_config.bouncer_config.builtin_weights.keccak": {
7878
"description": "Keccak gas weight.",
7979
"privacy": "Public",
80-
"value": 408566
80+
"value": 510707
8181
},
8282
"batcher_config.block_builder_config.bouncer_config.builtin_weights.mul_mod": {
8383
"description": "Mul_mod gas weight.",
@@ -87,12 +87,12 @@
8787
"batcher_config.block_builder_config.bouncer_config.builtin_weights.pedersen": {
8888
"description": "Pedersen gas weight.",
8989
"privacy": "Public",
90-
"value": 8100
90+
"value": 10125
9191
},
9292
"batcher_config.block_builder_config.bouncer_config.builtin_weights.poseidon": {
9393
"description": "Poseidon gas weight.",
9494
"privacy": "Public",
95-
"value": 8334
95+
"value": 6250
9696
},
9797
"batcher_config.block_builder_config.bouncer_config.builtin_weights.range_check": {
9898
"description": "Range_check gas weight.",

crates/blockifier/src/bouncer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Default for BouncerWeights {
163163
n_txs: 600,
164164
state_diff_size: 4000,
165165
sierra_gas: GasAmount(4000000000),
166-
proving_gas: GasAmount(4000000000),
166+
proving_gas: GasAmount(5000000000),
167167
}
168168
}
169169
}
@@ -373,14 +373,14 @@ impl BuiltinWeights {
373373
impl Default for BuiltinWeights {
374374
fn default() -> Self {
375375
Self {
376-
pedersen: 8100,
376+
pedersen: 10125,
377377
range_check: 70,
378-
ecdsa: 1333333,
379-
ec_op: 571900,
378+
ecdsa: 1666666,
379+
ec_op: 714875,
380380
bitwise: 583,
381-
keccak: 408566,
382-
poseidon: 8334,
383-
add_mod: 250,
381+
keccak: 510707,
382+
poseidon: 6250,
383+
add_mod: 312,
384384
mul_mod: 604,
385385
range_check96: 56,
386386
}

crates/blockifier/src/bouncer_test.rs

Lines changed: 89 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::{HashMap, HashSet};
33
use assert_matches::assert_matches;
44
use blockifier_test_utils::cairo_versions::{CairoVersion, RunnableCairo1};
55
use blockifier_test_utils::contracts::FeatureContract;
6+
use cairo_vm::types::builtin_name::BuiltinName;
67
use rstest::{fixture, rstest};
78
use starknet_api::execution_resources::GasAmount;
89
use starknet_api::transaction::fields::Fee;
@@ -190,19 +191,49 @@ fn test_bouncer_update(#[case] initial_bouncer: Bouncer) {
190191
assert_eq!(updated_bouncer, expected_bouncer);
191192
}
192193

193-
/// This parameterized test verifies `Bouncer::try_update` behavior when varying only `sierra_gas`.
194194
#[rstest]
195-
#[case::positive_flow(GasAmount(1), "ok")]
196-
#[case::block_full(GasAmount(11), "block_full")]
197-
#[case::transaction_too_large(GasAmount(21), "too_large")]
198-
fn test_bouncer_try_update_sierra_gas(
199-
#[case] added_gas: GasAmount,
200-
#[case] scenario: &'static str,
201-
block_context: BlockContext,
202-
block_max_capacity: BouncerWeights,
203-
bouncer_config: BouncerConfig,
204-
mut state: CachedState<DictStateReader>,
205-
) {
195+
#[case::sierra_gas_positive_flow("ok")]
196+
#[case::sierra_gas_block_full("sierra_gas_block_full")]
197+
#[case::proving_gas_positive_flow("ok")]
198+
#[case::proving_gas_block_full("proving_gas_block_full")]
199+
fn test_bouncer_try_update_gas_based(#[case] scenario: &'static str, block_context: BlockContext) {
200+
let state = &mut test_state(&block_context.chain_info, Fee(0), &[]);
201+
let mut transactional_state = TransactionalState::create_transactional(state);
202+
let builtin_weights = BuiltinWeights::default();
203+
204+
let range_check_count = 2;
205+
let max_capacity_builtin_counters =
206+
HashMap::from([(BuiltinName::range_check, range_check_count)]);
207+
let builtin_counters = match scenario {
208+
"proving_gas_block_full" => max_capacity_builtin_counters.clone(),
209+
// Use a minimal or empty map.
210+
"ok" | "sierra_gas_block_full" => {
211+
HashMap::from([(BuiltinName::range_check, range_check_count - 1)])
212+
}
213+
_ => panic!("Unexpected scenario: {}", scenario),
214+
};
215+
216+
// Derive sierra_gas from scenario
217+
let sierra_gas = match scenario {
218+
"sierra_gas_block_full" => GasAmount(11), // Exceeds capacity
219+
"ok" | "proving_gas_block_full" => GasAmount(1), // Within capacity
220+
_ => panic!("Unexpected scenario: {}", scenario),
221+
};
222+
223+
let proving_gas_max_capacity =
224+
builtin_weights.calc_proving_gas_from_builtin_counter(&max_capacity_builtin_counters);
225+
226+
let block_max_capacity = BouncerWeights {
227+
l1_gas: 20,
228+
message_segment_length: 20,
229+
n_events: 20,
230+
state_diff_size: 20,
231+
n_txs: 20,
232+
sierra_gas: GasAmount(20),
233+
proving_gas: proving_gas_max_capacity,
234+
};
235+
let bouncer_config = BouncerConfig { block_max_capacity, builtin_weights };
236+
206237
let accumulated_weights = BouncerWeights {
207238
l1_gas: 10,
208239
message_segment_length: 10,
@@ -217,57 +248,71 @@ fn test_bouncer_try_update_sierra_gas(
217248

218249
// Prepare the resources to be added to the bouncer.
219250
let execution_summary = ExecutionSummary::default();
220-
let builtin_counters = BuiltinCounterMap::default();
221251
let tx_resources = TransactionResources {
222-
// Only the `sierra_gas` field is varied.
223-
computation: ComputationResources { sierra_gas: added_gas, ..Default::default() },
252+
computation: ComputationResources { sierra_gas, ..Default::default() },
224253
..Default::default()
225254
};
226-
let mut transactional_state = TransactionalState::create_transactional(&mut state);
227255
let tx_state_changes_keys = transactional_state.to_state_diff().unwrap().state_maps.keys();
228256

229-
// TODO(Yoni, 1/10/2024): simplify this test and move tx-too-large cases out.
257+
let result = bouncer.try_update(
258+
&transactional_state,
259+
&tx_state_changes_keys,
260+
&execution_summary,
261+
&builtin_counters,
262+
&tx_resources,
263+
&block_context.versioned_constants,
264+
);
265+
266+
match scenario {
267+
"ok" => assert_matches!(result, Ok(())),
268+
"proving_gas_block_full" | "sierra_gas_block_full" => {
269+
assert_matches!(result, Err(TransactionExecutorError::BlockFull))
270+
}
271+
_ => panic!("Unexpected scenario: {}", scenario),
272+
}
273+
}
274+
275+
#[rstest]
276+
fn test_transaction_too_large_sierra_gas_based(block_context: BlockContext) {
277+
let mut state = test_state(&block_context.chain_info, Fee(0), &[]);
278+
let mut transactional_state = TransactionalState::create_transactional(&mut state);
279+
let block_max_capacity = BouncerWeights { sierra_gas: GasAmount(20), ..Default::default() };
280+
let bouncer_config =
281+
BouncerConfig { block_max_capacity, builtin_weights: BuiltinWeights::default() };
282+
283+
// Use gas amount > block_max_capacity's.
284+
let exceeding_gas = GasAmount(30);
285+
let execution_summary = ExecutionSummary::default();
286+
let builtin_counters = BuiltinCounterMap::default();
287+
let tx_resources = TransactionResources {
288+
computation: ComputationResources { sierra_gas: exceeding_gas, ..Default::default() },
289+
..Default::default()
290+
};
291+
let tx_state_changes_keys = transactional_state.to_state_diff().unwrap().state_maps.keys();
230292

231-
// Check that the transaction is not too large.
232-
let mut result = verify_tx_weights_within_max_capacity(
293+
let result = verify_tx_weights_within_max_capacity(
233294
&transactional_state,
234295
&execution_summary,
235296
&builtin_counters,
236297
&tx_resources,
237298
&tx_state_changes_keys,
238-
&bouncer.bouncer_config,
299+
&bouncer_config,
239300
&block_context.versioned_constants,
240301
)
241302
.map_err(TransactionExecutorError::TransactionExecutionError);
303+
242304
let expected_weights = BouncerWeights {
243-
sierra_gas: added_gas,
305+
sierra_gas: exceeding_gas,
244306
n_txs: 1,
245-
proving_gas: added_gas,
307+
proving_gas: exceeding_gas,
246308
..BouncerWeights::empty()
247309
};
248310

249-
if result.is_ok() {
250-
// Try to update the bouncer.
251-
result = bouncer.try_update(
252-
&transactional_state,
253-
&tx_state_changes_keys,
254-
&execution_summary,
255-
&builtin_counters,
256-
&tx_resources,
257-
&block_context.versioned_constants,
258-
);
259-
}
260-
261-
match scenario {
262-
"ok" => assert_matches!(result, Ok(())),
263-
"block_full" => assert_matches!(result, Err(TransactionExecutorError::BlockFull)),
264-
"too_large" => assert_matches!(result, Err(
265-
TransactionExecutorError::TransactionExecutionError(
266-
TransactionExecutionError::TransactionTooLarge { max_capacity, tx_size }
267-
)
268-
) if *max_capacity == block_max_capacity && *tx_size == expected_weights),
269-
_ => panic!("Unexpected scenario: {}", scenario),
270-
}
311+
assert_matches!(result, Err(
312+
TransactionExecutorError::TransactionExecutionError(
313+
TransactionExecutionError::TransactionTooLarge { max_capacity, tx_size }
314+
)
315+
) if *max_capacity == bouncer_config.block_max_capacity && *tx_size == expected_weights);
271316
}
272317

273318
#[rstest]

crates/blockifier/src/test_utils/struct_impls.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ impl BlockContext {
202202
n_events: max_n_events_in_block,
203203
..BouncerWeights::max()
204204
},
205-
// TODO(Meshi): Check what should be the values here.
206205
..BouncerConfig::max()
207206
},
208207
..Self::create_for_account_testing()

0 commit comments

Comments
 (0)