Skip to content

Commit e60f78c

Browse files
committed
Update comments in integration::gas tests
commit-id:254a8b1a
1 parent 045b917 commit e60f78c

File tree

1 file changed

+81
-74
lines changed
  • crates/forge/tests/integration

1 file changed

+81
-74
lines changed

crates/forge/tests/integration/gas.rs

Lines changed: 81 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,8 +1174,8 @@ fn declare_cost_is_omitted_sierra_gas() {
11741174
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
11751175

11761176
assert_passed(&result);
1177-
// 17980 = reported consumed sierra gas
1178-
// 0 l1_gas + 0 l1_data_gas + 17980 l2 gas
1177+
// 17_980 = reported consumed sierra gas
1178+
// 0 l1_gas + 0 l1_data_gas + 17_980 l2 gas = 17_980 total gas
11791179
assert_gas(
11801180
&result,
11811181
"declare_cost_is_omitted",
@@ -1216,14 +1216,14 @@ fn deploy_syscall_cost_sierra_gas() {
12161216
// n = 1 (unique contracts updated - in this case it's the new contract address)
12171217
// ( l + n * 2 ) * felt_size_in_bytes(32) = 96 (total l1 data cost)
12181218
//
1219-
// 20000 = cost of 2 keccak syscall (because 2 * 100 * 100) (from constructor)
1219+
// 20_000 = cost of 2 keccak syscall (because 2 * 100 * 100) (from constructor)
12201220
// -> 1 keccak syscall costs 100 cairo steps
1221-
// 147660 = cost of 1 deploy syscall (because 1 * (1132 + 8) * 100 + (7 + 1) * 4050 + 18 * 70)
1221+
// 151_970 = cost of 1 deploy syscall (because 1 * (1173 + 8) * 100 + (7 + 1) * 4050 + 21 * 70)
12221222
// -> 1 deploy syscall costs 1132 cairo steps, 7 pedersen and 18 range check builtins
12231223
// -> 1 calldata element costs 8 cairo steps and 1 pedersen
12241224
// -> 1 pedersen costs 4050, 1 range check costs 70
1225-
// 434734 = reported consumed sierra gas
1226-
// 0 l1_gas + 96 l1_data_gas + (20000 + 147660 + 434734) l2 gas
1225+
// 430_424 = reported consumed sierra gas
1226+
// 0 l1_gas + 96 l1_data_gas + (20_000 + 151_970 + 430_424) l2 gas
12271227
assert_gas(
12281228
&result,
12291229
"deploy_syscall_cost",
@@ -1260,10 +1260,10 @@ fn snforge_std_deploy_cost_sierra_gas() {
12601260

12611261
assert_passed(&result);
12621262
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1263-
// 20000 = cost of 2 keccak syscall (see `deploy_syscall_cost_sierra_gas` test)
1264-
// 147660 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1265-
// 447984 = reported consumed sierra gas
1266-
// 0 l1_gas + 96 l1_data_gas + (20000 + 147660 + 447984) l2 gas
1263+
// 20_000 = cost of 2 keccak syscall (see `deploy_syscall_cost_sierra_gas` test)
1264+
// 151_970 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1265+
// 433_694 = reported consumed sierra gas
1266+
// 0 l1_gas + 96 l1_data_gas + (20_000 + 151_970 + 433_694) l2 gas
12671267
assert_gas(
12681268
&result,
12691269
"deploy_cost",
@@ -1275,6 +1275,7 @@ fn snforge_std_deploy_cost_sierra_gas() {
12751275
);
12761276
}
12771277

1278+
// TODO(#3292): This test is incorrect because executing `keccak_u256s_le_inputs` consumes significantly more than 50_000 L2 gas.
12781279
#[test]
12791280
fn keccak_cost_sierra_gas() {
12801281
let test = test_case!(indoc!(
@@ -1289,10 +1290,10 @@ fn keccak_cost_sierra_gas() {
12891290
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
12901291

12911292
assert_passed(&result);
1292-
// 10000 = cost of 1 keccak syscall (1 * 100 * 100)
1293+
// 10_000 = cost of 1 keccak syscall (1 * 100 * 100)
12931294
// -> 1 keccak syscall costs 100 cairo steps
1294-
// 37290 = reported consumed sierra gas
1295-
// 0 l1_gas + 0 l1_data_gas + (10000 + 37290) l2 gas
1295+
// 37_290 = reported consumed sierra gas
1296+
// 0 l1_gas + 0 l1_data_gas + (10_000 + 37_290) l2 gas
12961297
assert_gas(
12971298
&result,
12981299
"keccak_cost",
@@ -1304,6 +1305,8 @@ fn keccak_cost_sierra_gas() {
13041305
);
13051306
}
13061307

1308+
// TODO(#3292): `keccak_u256s_le_inputs` has significantly higher costs than `keccak_syscall` which is not included in the calculations below.
1309+
// This is the reason why reported consumed gas is so high.
13071310
#[test]
13081311
fn contract_keccak_cost_sierra_gas() {
13091312
let test = test_case!(
@@ -1334,14 +1337,14 @@ fn contract_keccak_cost_sierra_gas() {
13341337

13351338
assert_passed(&result);
13361339
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1337-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1338-
// 50000 = cost of 5 keccak syscall (5 * 100 * 100)
1340+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1341+
// 50_000 = cost of 5 keccak syscall (5 * 100 * 100)
13391342
// -> 1 keccak syscall costs 100 cairo steps
1340-
// 87650 = cost of 1 call contract syscall (because 1 * 866 * 100 + 15 * 70)
1343+
// 91_560 = cost of 1 call contract syscall (because 1 * 903 * 100 + 18 * 70)
13411344
// -> 1 call contract syscall costs 866 cairo steps and 15 range check builtins
13421345
// -> 1 range check costs 70
1343-
// 1070775 = reported consumed sierra gas
1344-
// 0 l1_gas + 96 l1_data_gas + (142810 + 50000 + 87650 + 1070775) l2 gas
1346+
// 1_053_745 = reported consumed sierra gas
1347+
// 0 l1_gas + 96 l1_data_gas + (147_120 + 50_000 + 91_560 + 1_053_745) l2 gas
13451348
assert_gas(
13461349
&result,
13471350
"contract_keccak_cost",
@@ -1383,10 +1386,10 @@ fn contract_range_check_cost_sierra_gas() {
13831386

13841387
assert_passed(&result);
13851388
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1386-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1387-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1388-
// 109280 = reported consumed sierra gas
1389-
// 0 l1_gas + 96 l1_data_gas + (142810 + 87650 + 109280) l2 gas
1389+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1390+
// 91_560 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1391+
// 92_250 = reported consumed sierra gas
1392+
// 0 l1_gas + 96 l1_data_gas + (147_120 + 91_560 + 92_250) l2 gas
13901393
assert_gas(
13911394
&result,
13921395
"contract_range_check_cost",
@@ -1430,14 +1433,14 @@ fn storage_write_cost_sierra_gas() {
14301433
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
14311434
// 64 = storage_updates(1) * 2 * 32
14321435
// 32 = storage updates from zero value(1) * 32 (https://community.starknet.io/t/starknet-v0-13-4-pre-release-notes/115257#p-2358763-da-costs-27)
1433-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1434-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1435-
// 10000 = cost of 1 storage write syscall (because 1 * 93 * 100 + 1 * 70 = 9370)
1436+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1437+
// 91_560 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1438+
// 10_000 = cost of 1 storage write syscall (because 1 * 96 * 100 + 1 * 70 = 9670)
14361439
// -> 1 storage write syscall costs 93 cairo steps and 1 range check builtin
14371440
// -> 1 range check costs 70
14381441
// -> the minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler (atm it is 100 * 100)
1439-
// 47100 = reported consumed sierra gas
1440-
// 0 l1_gas + (96 + 64 + 32) l1_data_gas + (142810 + 87650 + 10000 + 47100) l2 gas
1442+
// 30_070 = reported consumed sierra gas
1443+
// 0 l1_gas + (96 + 64 + 32 = 192) l1_data_gas + (147_120 + 91_560 + 10_000 + 30_070) l2 gas
14411444
assert_gas(
14421445
&result,
14431446
"storage_write_cost",
@@ -1486,16 +1489,16 @@ fn multiple_storage_writes_cost_sierra_gas() {
14861489
// -> n = unique contracts updated
14871490
// -> m = unique(!) values updated
14881491
// 32 = storage updates from zero value(1) * 32 (https://community.starknet.io/t/starknet-v0-13-4-pre-release-notes/115257#p-2358763-da-costs-27)
1489-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1490-
// 175300 = cost of 2 call contract syscalls (because 2 * 866 * 100 + 2 * 15 * 70)
1492+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1493+
// 183_120 = cost of 2 call contract syscalls (2 * 91_560)
14911494
// -> 1 call contract syscall costs 866 cairo steps and 15 range check builtins
14921495
// -> 1 range check costs 70
1493-
// 20000 = cost of 2 storage write syscall (because 2 * 93 * 100 + 2 * 70 = 18740)
1496+
// 20_000 = cost of 2 storage write syscall (because 2 * 96 * 100 + 2 * 70 = 19340)
14941497
// -> 1 storage write syscall costs 93 cairo steps and 1 range check builtin
14951498
// -> 1 range check costs 70
14961499
// -> the minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler (atm it is 100 * 100)
1497-
// 56910 = reported consumed sierra gas
1498-
// 0 l1_gas + (64 + 64 + 32 + 32) l1_data_gas + (142810 + 175300 + 20000 + 56910) l2 gas
1500+
// 35_970 = reported consumed sierra gas
1501+
// 0 l1_gas + (64 + 64 + 32 + 32 = 192) l1_data_gas + (147_120 + 183_120 + 20_000 + 35_970) l2 gas
14991502
assert_gas(
15001503
&result,
15011504
"multiple_storage_writes_cost",
@@ -1537,15 +1540,15 @@ fn l1_message_cost_sierra_gas() {
15371540

15381541
assert_passed(&result);
15391542
// todo(2960): verify l2 -> l1 message cost
1540-
// 29524 = gas cost of l2 -> l1 message
1543+
// 29_524 = gas cost of l2 -> l1 message
15411544
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1542-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1543-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1544-
// 14170 = cost of 1 SendMessageToL1 syscall (because 1 * 141 * 100 + 1 * 70 )
1545-
// -> 1 storage write syscall costs 141 cairo steps and 1 range check builtin
1545+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1546+
// 91_560 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1547+
// 14_470 = cost of 1 SendMessageToL1 syscall (because 1 * 144 * 100 + 1 * 70 )
1548+
// -> 1 storage write syscall costs 144 cairo steps and 1 range check builtin
15461549
// -> 1 range check costs 70
1547-
// 46760 = reported consumed sierra gas
1548-
// 29524 l1_gas + 96 l1_data_gas + (142810 + 87650 + 14170 + 46760) l2 gas
1550+
// 29_430 = reported consumed sierra gas
1551+
// 29_524 l1_gas + 96 l1_data_gas + (147_120 + 91_560 + 14_470 + 29_430) l2 gas
15491552
assert_gas(
15501553
&result,
15511554
"l1_message_cost",
@@ -1598,23 +1601,21 @@ fn l1_message_cost_for_proxy_sierra_gas() {
15981601

15991602
assert_passed(&result);
16001603
// todo(2960): verify l2 -> l1 message cost
1601-
// 29524 = gas cost of l2 -> l1 message
1604+
// 29_524 = gas cost of l2 -> l1 message
16021605
// 128 = n(2) * 2 * 32
16031606
// 64 = l(2) * 32
16041607
// -> l = number of class hash updates
16051608
// -> n = unique contracts updated
1606-
// 285620 = cost of 2 deploy syscall (because 2 * 1132 * 100 + 2 * 7 * 4050 + 2 * 18 * 70)
1607-
// -> 1 deploy syscall costs 1132 cairo steps, 7 pedersen and 18 range check builtins
1608-
// -> 1 pedersen costs 4050, 1 range check costs 70
1609-
// 175300 = cost of 2 call contract syscalls (see `multiple_storage_writes_cost_sierra_gas` test)
1610-
// 14170 = cost of 1 SendMessageToL1 syscall (see `l1_message_cost_sierra_gas` test)
1611-
// 86000 = reported consumed sierra gas
1612-
// 29524 l1_gas + (128 + 64) l1_data_gas + (285620 + 175300 + 14170 + 86000) l2 gas
1609+
// 294_240 = cost of 2 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1610+
// 183_120 = cost of 2 call contract syscalls (see `multiple_storage_writes_cost_sierra_gas` test)
1611+
// 14_470 = cost of 1 SendMessageToL1 syscall (see `l1_message_cost_sierra_gas` test)
1612+
// 51_340 = reported consumed sierra gas
1613+
// 29_524 l1_gas + (128 + 64 = 192) l1_data_gas + (294_240 + 183_120 + 14_470 + 51_340) l2 gas
16131614
assert_gas(
16141615
&result,
16151616
"l1_message_cost_for_proxy",
16161617
GasVector {
1617-
l1_gas: GasAmount(29524),
1618+
l1_gas: GasAmount(29_524),
16181619
l1_data_gas: GasAmount(192),
16191620
l2_gas: GasAmount(543_170),
16201621
},
@@ -1644,18 +1645,18 @@ fn events_cost_sierra_gas() {
16441645
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
16451646

16461647
assert_passed(&result);
1647-
// 512000 = 50 * 10240
1648+
// 512_000 = 50 * 10240
16481649
// -> we emit 50 keys, each taking up 1 felt of space
16491650
// -> L2 gas cost for event key is 10240 gas/felt
1650-
// 256000 = 50 * 5120
1651+
// 256_000 = 50 * 5120
16511652
// -> we emit 50 keys, each having 1 felt of data
16521653
// -> L2 gas cost for event data is 5120 gas/felt
1653-
// 10000 = cost of 1 emit event syscall (because 1 * 61 * 100 + 1 * 70 = 6170)
1654+
// 10_000 = cost of 1 emit event syscall (because 1 * 61 * 100 + 1 * 70 = 6170)
16541655
// -> 1 emit event syscall costs 61 cairo steps and 1 range check builtin
16551656
// -> 1 range check costs 70
16561657
// -> the minimum total cost is `syscall_base_gas_cost`, which is pre-charged by the compiler (atm it is 100 * 100)
1657-
// 137150 = reported consumed sierra gas
1658-
// 0 l1_gas + 0 l1_data_gas + (512000 + 256000 + 10000 + 137150) l2 gas
1658+
// 137_150 = reported consumed sierra gas
1659+
// 0 l1_gas + 0 l1_data_gas + (512_000 + 256_000 + 10_000 + 137_150) l2 gas
16591660
assert_gas(
16601661
&result,
16611662
"events_cost",
@@ -1695,13 +1696,13 @@ fn events_contract_cost_sierra_gas() {
16951696
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
16961697
assert_passed(&result);
16971698
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1698-
// 512000 = event keys cost (see `events_cost_sierra_gas` test)
1699-
// 256000 = event data cost (see `events_cost_sierra_gas` test)
1700-
// 10000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1701-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1702-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1703-
// 176840 = reported consumed sierra gas
1704-
// 0 l1_gas + 96 l1_data_gas + (512000 + 256000 + 10000 + 142810 + 87650 + 176840) l2 gas
1699+
// 512_000 = event keys cost (see `events_cost_sierra_gas` test)
1700+
// 256_000 = event data cost (see `events_cost_sierra_gas` test)
1701+
// 10_000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1702+
// 147_120 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1703+
// 91_560 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1704+
// 159_810 = reported consumed sierra gas
1705+
// 0 l1_gas + 96 l1_data_gas + (512_000 + 256_000 + 10_000 + 147_120 + 91_560 + 159_810) l2 gas
17051706
assert_gas(
17061707
&result,
17071708
"event_emission_cost",
@@ -1764,13 +1765,16 @@ fn nested_call_cost_sierra_gas() {
17641765
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
17651766

17661767
assert_passed(&result);
1767-
// 512000 = event keys cost (see `events_cost_sierra_gas` test)
1768-
// 256000 = event data cost (see `events_cost_sierra_gas` test)
1769-
// 10000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1770-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1771-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1772-
// 580532 = reported consumed sierra gas
1773-
// 0 l1_gas + 288 l1_data_gas + (512000 + 256000 + 10000 + 3 * 142810 + 2 * 87650 + 580532) l2 gas
1768+
// 10_240 = event keys cost (see `events_cost_sierra_gas` test)
1769+
// 5120 = event data cost (see `events_cost_sierra_gas` test)
1770+
// 10_000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1771+
// 10_000 = cost of 1 keccak syscall (1 * 100 * 100)
1772+
// 10_840 = cost of 1 get block hash syscall (107 * 100 + 2 * 70)
1773+
// 441_360 = cost of 3 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1774+
// 274_680 = cost of 3 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1775+
// 841_295 = cost of 1 sha256_process_block_syscall syscall (1867 * 100 + 1115 * 583 + 65 * 70)
1776+
// 335_297 = reported consumed sierra gas
1777+
// 0 l1_gas + 288 l1_data_gas + (10_240 + 5120 + 10_000 + 10_000 + 10_840 + 441_360 + 274_680 + 841_295 + 335_297) l2 gas
17741778
assert_gas(
17751779
&result,
17761780
"test_call_other_contract",
@@ -1835,13 +1839,16 @@ fn nested_call_cost_in_forked_contract_sierra_gas() {
18351839
let result = run_test_case(&test, ForgeTrackedResource::SierraGas);
18361840

18371841
assert_passed(&result);
1838-
// 512000 = event keys cost (see `events_cost_sierra_gas` test)
1839-
// 256000 = event data cost (see `events_cost_sierra_gas` test)
1840-
// 10000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1841-
// 142810 = cost of 1 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1842-
// 87650 = cost of 1 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1843-
// 579442 = reported consumed sierra gas
1844-
// 0 l1_gas + 192 l1_data_gas + (512000 + 256000 + 10000 + 2 * 142810 + 2 * 87650 + 579442) l2 gas
1842+
// 10_240 = event keys cost (see `events_cost_sierra_gas` test)
1843+
// 5120 = event data cost (see `events_cost_sierra_gas` test)
1844+
// 10_000 = cost of 1 emit event syscall (see `events_cost_sierra_gas` test)
1845+
// 10_000 = cost of 1 keccak syscall (1 * 100 * 100)
1846+
// 10_840 = cost of 1 get block hash syscall (107 * 100 + 2 * 70)
1847+
// 294_240 = cost of 2 deploy syscall (see `deploy_syscall_cost_sierra_gas` test)
1848+
// 274_680 = cost of 3 call contract syscall (see `contract_keccak_cost_sierra_gas` test)
1849+
// 841_295 = cost of 1 sha256_process_block_syscall syscall (1867 * 100 + 1115 * 583 + 65 * 70)
1850+
// 346_427 = reported consumed sierra gas
1851+
// 0 l1_gas + 192 l1_data_gas + (10_240 + 5120 + 10_000 + 10_000 + 10_840 + 294_240 + 274_680 + 841_295 + 346_427) l2 gas
18451852
assert_gas(
18461853
&result,
18471854
"test_call_other_contract_fork",

0 commit comments

Comments
 (0)