Skip to content

Commit

Permalink
Merge pull request ethereum#13695 from ethereum/evmc-refund
Browse files Browse the repository at this point in the history
test: Support tracking gas refunds
  • Loading branch information
axic authored Nov 10, 2022
2 parents 50747d6 + 54b4598 commit 310a58d
Show file tree
Hide file tree
Showing 53 changed files with 117 additions and 110 deletions.
15 changes: 11 additions & 4 deletions test/ExecutionFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,21 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
if (_isCreation)
m_contractAddress = EVMHost::convertFromEVMC(result.create_address);

m_gasUsed = InitialGas - result.gas_left;
unsigned const refundRatio = (m_evmVersion >= langutil::EVMVersion::london() ? 5 : 2);
auto const totalGasUsed = InitialGas - result.gas_left;
auto const gasRefund = min(u256(result.gas_refund), totalGasUsed / refundRatio);

m_gasUsed = totalGasUsed - gasRefund;
m_transactionSuccessful = (result.status_code == EVMC_SUCCESS);

if (m_showMessages)
{
cout << " out: " << util::toHex(m_output) << endl;
cout << " result: " << static_cast<size_t>(result.status_code) << endl;
cout << " gas used: " << m_gasUsed.str() << endl;
cout << " out: " << util::toHex(m_output) << endl;
cout << " result: " << static_cast<size_t>(result.status_code) << endl;
cout << " gas used: " << m_gasUsed.str() << endl;
cout << " gas used (without refund): " << totalGasUsed.str() << endl;
cout << " gas refund (total): " << result.gas_refund << endl;
cout << " gas refund (bound): " << gasRefund.str() << endl;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ contract C {
// gas legacy: 3071683
// gas legacyOptimized: 3014415
// test_indices(uint256): 5 ->
// gas irOptimized: 722510
// gas legacy: 719151
// gas legacyOptimized: 716139
// gas irOptimized: 578008
// gas legacy: 575321
// gas legacyOptimized: 572912
// test_indices(uint256): 10 ->
// gas irOptimized: 158347
// gas legacy: 162657
Expand All @@ -40,14 +40,14 @@ contract C {
// gas legacy: 18602799
// gas legacyOptimized: 18179744
// test_indices(uint256): 129 ->
// gas irOptimized: 5197778
// gas legacy: 5212013
// gas legacyOptimized: 5157889
// gas irOptimized: 4158223
// gas legacy: 4169611
// gas legacyOptimized: 4126312
// test_indices(uint256): 128 ->
// gas irOptimized: 416732
// gas legacy: 470568
// gas legacyOptimized: 423768
// gas irOptimized: 411932
// gas legacy: 465768
// gas legacyOptimized: 418968
// test_indices(uint256): 1 ->
// gas irOptimized: 726962
// gas legacy: 721789
// gas legacyOptimized: 720209
// gas irOptimized: 581570
// gas legacy: 577432
// gas legacyOptimized: 576168
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ contract C {
// ----
// test_zeroed_indicies(uint256): 1 ->
// test_zeroed_indicies(uint256): 5 ->
// gas irOptimized: 165044
// gas legacy: 166201
// gas legacyOptimized: 163439
// gas irOptimized: 132036
// gas legacy: 132961
// gas legacyOptimized: 130752
// test_zeroed_indicies(uint256): 10 ->
// gas irOptimized: 282617
// gas legacy: 285088
// gas legacyOptimized: 280012
// gas irOptimized: 226094
// gas legacy: 228071
// gas legacyOptimized: 224010
// test_zeroed_indicies(uint256): 15 ->
// gas irOptimized: 405332
// gas legacy: 409138
// gas legacyOptimized: 401827
// gas irOptimized: 324266
// gas legacy: 327311
// gas legacyOptimized: 321462
// test_zeroed_indicies(uint256): 0xFF ->
// gas irOptimized: 6403282
// gas legacy: 6466233
// gas legacyOptimized: 6333077
// gas irOptimized: 5122626
// gas legacy: 5172987
// gas legacyOptimized: 5066462
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ contract C {
// gas legacy: 105722
// gas legacyOptimized: 103508
// set_get_length(uint256): 0xFF -> 0
// gas irOptimized: 841772
// gas legacy: 830227
// gas legacyOptimized: 806158
// gas irOptimized: 821872
// gas legacy: 810327
// gas legacyOptimized: 786258
// set_get_length(uint256): 0xFFF -> 0
// gas irOptimized: 12860984
// gas legacy: 12668959
// gas legacyOptimized: 12287770
// gas irOptimized: 12841084
// gas legacy: 12649059
// gas legacyOptimized: 12267870
// set_get_length(uint256): 0xFFFF -> FAILURE # Out-of-gas #
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ contract c {
// storageEmpty -> 0
// test_long() -> 67
// gas irOptimized: 89148
// gas legacy: 108639
// gas legacyOptimized: 106093
// gas legacy: 105839
// gas legacyOptimized: 103293
// storageEmpty -> 0
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020
// gas legacy: 61930
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ contract c {
}
// ----
// test() -> 0
// gas irOptimized: 157188
// gas legacy: 188576
// gas legacyOptimized: 183333
// gas irOptimized: 125751
// gas legacy: 150861
// gas legacyOptimized: 146667
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ contract C {
}
// ----
// f() -> true
// gas irOptimized: 146756
// gas legacy: 155961
// gas legacyOptimized: 153588
// gas irOptimized: 117405
// gas legacy: 124769
// gas legacyOptimized: 122871
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ contract C {
}
// ----
// f() -> 0
// gas irOptimized: 134365
// gas legacy: 135313
// gas legacyOptimized: 134548
// gas irOptimized: 107492
// gas legacy: 108251
// gas legacyOptimized: 107639
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ contract c {
}
// ----
// test() -> 0x02000202
// gas irOptimized: 4649835
// gas legacy: 4578446
// gas legacyOptimized: 4548309
// gas irOptimized: 4550335
// gas legacy: 4478946
// gas legacyOptimized: 4448809
// storageEmpty -> 1
// clear() -> 0, 0
// gas irOptimized: 4517023
// gas legacy: 4450548
// gas legacyOptimized: 4422289
// gas irOptimized: 4477223
// gas legacy: 4410748
// gas legacyOptimized: 4382489
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ contract c {
}
// ----
// test() -> 5, 4
// gas irOptimized: 224973
// gas legacy: 233801
// gas legacyOptimized: 232816
// gas irOptimized: 205073
// gas legacy: 213901
// gas legacyOptimized: 212916
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ contract c {
// compileToEwasm: also
// ----
// test() -> 3, 4
// gas irOptimized: 189516
// gas legacy: 215253
// gas legacyOptimized: 212341
// gas irOptimized: 169616
// gas legacy: 175453
// gas legacyOptimized: 172541
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ contract c {

// ----
// test() -> 5, 4
// gas irOptimized: 272893
// gas legacy: 270834
// gas legacyOptimized: 269960
// gas irOptimized: 252993
// gas legacy: 250934
// gas legacyOptimized: 250060
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ contract c {
// compileToEwasm: also
// ----
// test() -> 8, 0
// gas irOptimized: 236079
// gas legacy: 234695
// gas legacyOptimized: 234103
// gas irOptimized: 196279
// gas legacy: 194895
// gas legacyOptimized: 194303
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract c {
}
// ----
// test() -> 4, 5
// gas irOptimized: 238623
// gas legacy: 238736
// gas legacyOptimized: 237159
// gas irOptimized: 190899
// gas legacy: 190989
// gas legacyOptimized: 189728
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ contract c {
// compileToEwasm: also
// ----
// test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000
// gas irOptimized: 124640
// gas legacy: 187414
// gas legacyOptimized: 165659
// gas irOptimized: 104740
// gas legacy: 167514
// gas legacyOptimized: 145759
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ contract c {
// compileToEwasm: also
// ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0
// gas irOptimized: 293486
// gas legacy: 303626
// gas legacyOptimized: 301945
// gas irOptimized: 273586
// gas legacy: 283726
// gas legacyOptimized: 282045
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ contract c {
// compileToEwasm: also
// ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00
// gas irOptimized: 273093
// gas legacy: 276360
// gas legacyOptimized: 275411
// gas irOptimized: 233293
// gas legacy: 236560
// gas legacyOptimized: 235611
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ contract Test {
// test1() -> 3
// test2() -> 6
// test3() -> 24
// gas irOptimized: 155660
// gas legacy: 156683
// gas legacyOptimized: 155793
// gas irOptimized: 141260
// gas legacy: 142283
// gas legacyOptimized: 141393
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ contract C {
// gas legacy: 181047
// gas legacyOptimized: 180029
// g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000
// gas irOptimized: 121097
// gas legacy: 124201
// gas legacyOptimized: 121353
// gas irOptimized: 106697
// gas legacy: 109801
// gas legacyOptimized: 106953
// h() -> 0x40, 0x60, 0x00, 0x00
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ contract C {
}
// ----
// f() -> 0xff
// gas irOptimized: 179284
// gas legacy: 191974
// gas legacyOptimized: 183456
// gas irOptimized: 143428
// gas legacy: 153580
// gas legacyOptimized: 146765
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ contract C {
// gas legacyOptimized: 117021
// test2() -> 0x20, 0x14, "[b called][a called]"
// test3() -> 0x20, 0x14, "[b called][a called]"
// gas irOptimized: 106056
// gas legacy: 105614
// gas legacyOptimized: 104506
// gas irOptimized: 103256
// gas legacy: 102814
// gas legacyOptimized: 101706
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract c {
}
// ----
// test() -> 1, 2, 3
// gas irOptimized: 2285747
// gas legacy: 2279034
// gas legacyOptimized: 2267444
// gas irOptimized: 1828598
// gas legacy: 1823228
// gas legacyOptimized: 1813956
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract c {
}
// ----
// test() -> 38, 28, 18
// gas irOptimized: 185650
// gas legacy: 189492
// gas legacyOptimized: 178318
// gas irOptimized: 148520
// gas legacy: 151594
// gas legacyOptimized: 142655
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract c {
}
// ----
// test() -> 20, 10
// gas irOptimized: 157570
// gas legacy: 159279
// gas legacyOptimized: 152937
// gas irOptimized: 126056
// gas legacy: 127424
// gas legacyOptimized: 122350
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ contract c {

// ----
// test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000
// gas irOptimized: 109301
// gas legacy: 126702
// gas irOptimized: 109310
// gas legacy: 101362
// gas legacyOptimized: 123422
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract c {
}
// ----
// test() -> true
// gas irOptimized: 175619
// gas legacy: 224093
// gas legacyOptimized: 205152
// gas irOptimized: 140496
// gas legacy: 179275
// gas legacyOptimized: 164122
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract c {
}
// ----
// test() ->
// gas irOptimized: 142528
// gas legacy: 164430
// gas legacyOptimized: 158513
// gas irOptimized: 114023
// gas legacy: 131544
// gas legacyOptimized: 126811
// storageEmpty -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ contract C {
}
// ----
// f() ->
// gas irOptimized: 141557
// gas legacy: 142032
// gas legacyOptimized: 141400
// gas irOptimized: 113246
// gas legacy: 113626
// gas legacyOptimized: 113120
// g() ->
// gas irOptimized: 148272
// gas legacy: 148507
// gas legacyOptimized: 147740
// gas irOptimized: 118618
// gas legacy: 118806
// gas legacyOptimized: 118192

0 comments on commit 310a58d

Please sign in to comment.