@@ -1174,8 +1174,8 @@ fn declare_cost_is_omitted_sierra_gas() {
1174
1174
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1175
1175
1176
1176
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
1179
1179
assert_gas (
1180
1180
& result,
1181
1181
"declare_cost_is_omitted" ,
@@ -1216,14 +1216,14 @@ fn deploy_syscall_cost_sierra_gas() {
1216
1216
// n = 1 (unique contracts updated - in this case it's the new contract address)
1217
1217
// ( l + n * 2 ) * felt_size_in_bytes(32) = 96 (total l1 data cost)
1218
1218
//
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)
1220
1220
// -> 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)
1222
1222
// -> 1 deploy syscall costs 1132 cairo steps, 7 pedersen and 18 range check builtins
1223
1223
// -> 1 calldata element costs 8 cairo steps and 1 pedersen
1224
1224
// -> 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
1227
1227
assert_gas (
1228
1228
& result,
1229
1229
"deploy_syscall_cost" ,
@@ -1260,10 +1260,10 @@ fn snforge_std_deploy_cost_sierra_gas() {
1260
1260
1261
1261
assert_passed ( & result) ;
1262
1262
// 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
1267
1267
assert_gas (
1268
1268
& result,
1269
1269
"deploy_cost" ,
@@ -1275,6 +1275,7 @@ fn snforge_std_deploy_cost_sierra_gas() {
1275
1275
) ;
1276
1276
}
1277
1277
1278
+ // TODO(#3292): This test is incorrect because executing `keccak_u256s_le_inputs` consumes significantly more than 50_000 L2 gas.
1278
1279
#[ test]
1279
1280
fn keccak_cost_sierra_gas ( ) {
1280
1281
let test = test_case ! ( indoc!(
@@ -1289,10 +1290,10 @@ fn keccak_cost_sierra_gas() {
1289
1290
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1290
1291
1291
1292
assert_passed ( & result) ;
1292
- // 10000 = cost of 1 keccak syscall (1 * 100 * 100)
1293
+ // 10_000 = cost of 1 keccak syscall (1 * 100 * 100)
1293
1294
// -> 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
1296
1297
assert_gas (
1297
1298
& result,
1298
1299
"keccak_cost" ,
@@ -1304,6 +1305,8 @@ fn keccak_cost_sierra_gas() {
1304
1305
) ;
1305
1306
}
1306
1307
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.
1307
1310
#[ test]
1308
1311
fn contract_keccak_cost_sierra_gas ( ) {
1309
1312
let test = test_case ! (
@@ -1334,14 +1337,14 @@ fn contract_keccak_cost_sierra_gas() {
1334
1337
1335
1338
assert_passed ( & result) ;
1336
1339
// 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)
1339
1342
// -> 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)
1341
1344
// -> 1 call contract syscall costs 866 cairo steps and 15 range check builtins
1342
1345
// -> 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
1345
1348
assert_gas (
1346
1349
& result,
1347
1350
"contract_keccak_cost" ,
@@ -1383,10 +1386,10 @@ fn contract_range_check_cost_sierra_gas() {
1383
1386
1384
1387
assert_passed ( & result) ;
1385
1388
// 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
1390
1393
assert_gas (
1391
1394
& result,
1392
1395
"contract_range_check_cost" ,
@@ -1430,14 +1433,14 @@ fn storage_write_cost_sierra_gas() {
1430
1433
// 96 = gas cost of onchain data (see `deploy_syscall_cost_sierra_gas` test)
1431
1434
// 64 = storage_updates(1) * 2 * 32
1432
1435
// 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 )
1436
1439
// -> 1 storage write syscall costs 93 cairo steps and 1 range check builtin
1437
1440
// -> 1 range check costs 70
1438
1441
// -> 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
1441
1444
assert_gas (
1442
1445
& result,
1443
1446
"storage_write_cost" ,
@@ -1486,16 +1489,16 @@ fn multiple_storage_writes_cost_sierra_gas() {
1486
1489
// -> n = unique contracts updated
1487
1490
// -> m = unique(!) values updated
1488
1491
// 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 )
1491
1494
// -> 1 call contract syscall costs 866 cairo steps and 15 range check builtins
1492
1495
// -> 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 )
1494
1497
// -> 1 storage write syscall costs 93 cairo steps and 1 range check builtin
1495
1498
// -> 1 range check costs 70
1496
1499
// -> 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
1499
1502
assert_gas (
1500
1503
& result,
1501
1504
"multiple_storage_writes_cost" ,
@@ -1537,15 +1540,15 @@ fn l1_message_cost_sierra_gas() {
1537
1540
1538
1541
assert_passed ( & result) ;
1539
1542
// todo(2960): verify l2 -> l1 message cost
1540
- // 29524 = gas cost of l2 -> l1 message
1543
+ // 29_524 = gas cost of l2 -> l1 message
1541
1544
// 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
1546
1549
// -> 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
1549
1552
assert_gas (
1550
1553
& result,
1551
1554
"l1_message_cost" ,
@@ -1598,23 +1601,21 @@ fn l1_message_cost_for_proxy_sierra_gas() {
1598
1601
1599
1602
assert_passed ( & result) ;
1600
1603
// todo(2960): verify l2 -> l1 message cost
1601
- // 29524 = gas cost of l2 -> l1 message
1604
+ // 29_524 = gas cost of l2 -> l1 message
1602
1605
// 128 = n(2) * 2 * 32
1603
1606
// 64 = l(2) * 32
1604
1607
// -> l = number of class hash updates
1605
1608
// -> 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
1613
1614
assert_gas (
1614
1615
& result,
1615
1616
"l1_message_cost_for_proxy" ,
1616
1617
GasVector {
1617
- l1_gas : GasAmount ( 29524 ) ,
1618
+ l1_gas : GasAmount ( 29_524 ) ,
1618
1619
l1_data_gas : GasAmount ( 192 ) ,
1619
1620
l2_gas : GasAmount ( 543_170 ) ,
1620
1621
} ,
@@ -1644,18 +1645,18 @@ fn events_cost_sierra_gas() {
1644
1645
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1645
1646
1646
1647
assert_passed ( & result) ;
1647
- // 512000 = 50 * 10240
1648
+ // 512_000 = 50 * 10240
1648
1649
// -> we emit 50 keys, each taking up 1 felt of space
1649
1650
// -> L2 gas cost for event key is 10240 gas/felt
1650
- // 256000 = 50 * 5120
1651
+ // 256_000 = 50 * 5120
1651
1652
// -> we emit 50 keys, each having 1 felt of data
1652
1653
// -> 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)
1654
1655
// -> 1 emit event syscall costs 61 cairo steps and 1 range check builtin
1655
1656
// -> 1 range check costs 70
1656
1657
// -> 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
1659
1660
assert_gas (
1660
1661
& result,
1661
1662
"events_cost" ,
@@ -1695,13 +1696,13 @@ fn events_contract_cost_sierra_gas() {
1695
1696
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1696
1697
assert_passed ( & result) ;
1697
1698
// 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
1705
1706
assert_gas (
1706
1707
& result,
1707
1708
"event_emission_cost" ,
@@ -1764,13 +1765,16 @@ fn nested_call_cost_sierra_gas() {
1764
1765
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1765
1766
1766
1767
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
1774
1778
assert_gas (
1775
1779
& result,
1776
1780
"test_call_other_contract" ,
@@ -1835,13 +1839,16 @@ fn nested_call_cost_in_forked_contract_sierra_gas() {
1835
1839
let result = run_test_case ( & test, ForgeTrackedResource :: SierraGas ) ;
1836
1840
1837
1841
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
1845
1852
assert_gas (
1846
1853
& result,
1847
1854
"test_call_other_contract_fork" ,
0 commit comments