Merge pull request #11433 from ethereum/panic-dedup

Insert a call to panic function in legacy codegen (and not inline it every single time)
This commit is contained in:
chriseth
2021-05-31 11:23:30 +02:00
committed by GitHub
18 changed files with 146 additions and 65 deletions
+46 -18
View File
@@ -162,6 +162,12 @@ bytes compileFirstExpression(
context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(
resolveDeclaration(*sourceUnit, function, resolver)
));
context.appendMissingLowLevelFunctions();
// NOTE: We intentionally disable optimisations for utility functions to simplfy the tests
context.appendYulUtilityFunctions({});
BOOST_REQUIRE(context.appendYulUtilityFunctionsRan());
BOOST_REQUIRE(context.assemblyPtr());
LinkerObject const& object = context.assemblyPtr()->assemble();
BOOST_REQUIRE(object.immutableReferences.empty());
@@ -336,7 +342,10 @@ BOOST_AUTO_TEST_CASE(arithmetic)
bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "y"}});
bytes panic =
bytes{uint8_t(Instruction::PUSH32)} +
bytes{
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::PUSH32)
} +
fromHex("4E487B7100000000000000000000000000000000000000000000000000000000") +
bytes{
uint8_t(Instruction::PUSH1), 0x0,
@@ -346,7 +355,10 @@ BOOST_AUTO_TEST_CASE(arithmetic)
uint8_t(Instruction::MSTORE),
uint8_t(Instruction::PUSH1), 0x24,
uint8_t(Instruction::PUSH1), 0x0,
uint8_t(Instruction::REVERT)
uint8_t(Instruction::REVERT),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::JUMP),
uint8_t(Instruction::JUMPDEST)
};
bytes expectation;
@@ -368,22 +380,30 @@ BOOST_AUTO_TEST_CASE(arithmetic)
uint8_t(Instruction::DUP2),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::PUSH1), 0x48,
uint8_t(Instruction::JUMPI)
} + panic + bytes{
uint8_t(Instruction::PUSH1), 0x20,
uint8_t(Instruction::JUMPI),
uint8_t(Instruction::PUSH1), 0x1f,
uint8_t(Instruction::PUSH1), 0x36,
uint8_t(Instruction::JUMP),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::MOD),
uint8_t(Instruction::DUP2),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::PUSH1), 0x7e,
uint8_t(Instruction::JUMPI)
} + panic + bytes{
uint8_t(Instruction::PUSH1), 0x2e,
uint8_t(Instruction::JUMPI),
uint8_t(Instruction::PUSH1), 0x2d,
uint8_t(Instruction::PUSH1), 0x36,
uint8_t(Instruction::JUMP),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::DIV),
uint8_t(Instruction::PUSH1), 0x1,
uint8_t(Instruction::MUL)
};
uint8_t(Instruction::MUL),
uint8_t(Instruction::PUSH1), 0x67,
uint8_t(Instruction::JUMP)
} + panic;
else
expectation = bytes{
uint8_t(Instruction::PUSH1), 0x1,
@@ -403,21 +423,29 @@ BOOST_AUTO_TEST_CASE(arithmetic)
uint8_t(Instruction::DUP2),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::PUSH1), 0x4a,
uint8_t(Instruction::JUMPI)
} + panic + bytes{
uint8_t(Instruction::PUSH1), 0x22,
uint8_t(Instruction::JUMPI),
uint8_t(Instruction::PUSH1), 0x21,
uint8_t(Instruction::PUSH1), 0x36,
uint8_t(Instruction::JUMP),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::MOD),
uint8_t(Instruction::DUP2),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::ISZERO),
uint8_t(Instruction::PUSH1), 0x80,
uint8_t(Instruction::JUMPI)
} + panic + bytes{
uint8_t(Instruction::PUSH1), 0x30,
uint8_t(Instruction::JUMPI),
uint8_t(Instruction::PUSH1), 0x2f,
uint8_t(Instruction::PUSH1), 0x36,
uint8_t(Instruction::JUMP),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::JUMPDEST),
uint8_t(Instruction::DIV),
uint8_t(Instruction::MUL)
};
uint8_t(Instruction::MUL),
uint8_t(Instruction::PUSH1), 0x67,
uint8_t(Instruction::JUMP)
} + panic;
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
}
+3 -3
View File
@@ -24,9 +24,9 @@ contract Large {
}
// ----
// creation:
// codeDepositCost: 904400
// executionCost: 942
// totalCost: 905342
// codeDepositCost: 640200
// executionCost: 676
// totalCost: 640876
// external:
// a(): 2475
// b(uint256): infinite
@@ -27,9 +27,9 @@ contract Large {
// optimize-runs: 2
// ----
// creation:
// codeDepositCost: 256400
// executionCost: 300
// totalCost: 256700
// codeDepositCost: 232800
// executionCost: 275
// totalCost: 233075
// external:
// a(): 2283
// b(uint256): 4937
@@ -11,9 +11,9 @@ contract Medium {
}
// ----
// creation:
// codeDepositCost: 351400
// executionCost: 386
// totalCost: 351786
// codeDepositCost: 269600
// executionCost: 312
// totalCost: 269912
// external:
// a(): 2452
// b(uint256): infinite
@@ -14,9 +14,9 @@ contract Medium {
// optimize-runs: 2
// ----
// creation:
// codeDepositCost: 146800
// executionCost: 190
// totalCost: 146990
// codeDepositCost: 131600
// executionCost: 177
// totalCost: 131777
// external:
// a(): 2283
// b(uint256): 4695
+3 -3
View File
@@ -6,9 +6,9 @@ contract Small {
}
// ----
// creation:
// codeDepositCost: 114600
// executionCost: 159
// totalCost: 114759
// codeDepositCost: 108800
// executionCost: 153
// totalCost: 108953
// external:
// fallback: 129
// a(): 2407
@@ -9,9 +9,9 @@ contract Small {
// optimize-runs: 2
// ----
// creation:
// codeDepositCost: 62000
// codeDepositCost: 60800
// executionCost: 111
// totalCost: 62111
// totalCost: 60911
// external:
// fallback: 118
// a(): 2261
@@ -22,5 +22,5 @@ contract B {
// ----
// f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004
// gas irOptimized: 133483
// gas legacy: 263810
// gas legacy: 235167
// gas legacyOptimized: 133299
@@ -46,5 +46,5 @@ contract C {
// ----
// test() -> 5, 6, 7
// gas irOptimized: 337455
// gas legacy: 499937
// gas legacyOptimized: 300513
// gas legacy: 463662
// gas legacyOptimized: 296513
@@ -27,5 +27,5 @@ contract Creator {
// ----
// f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8
// gas irOptimized: 486618
// gas legacy: 590826
// gas legacyOptimized: 448624
// gas legacy: 592626
// gas legacyOptimized: 450224
@@ -27,5 +27,5 @@ contract Creator {
// ----
// f(uint256,bytes): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> 7, "h"
// gas irOptimized: 336157
// gas legacy: 427373
// gas legacyOptimized: 296781
// gas legacy: 429173
// gas legacyOptimized: 298384
@@ -19,8 +19,8 @@ contract C {
// test_boundary_check(uint256,uint256): 10, 10 -> FAILURE, hex"4e487b71", 0x32
// test_boundary_check(uint256,uint256): 256, 256 -> FAILURE, hex"4e487b71", 0x32
// gas irOptimized: 151436
// gas legacy: 131815
// gas legacyOptimized: 112039
// gas legacy: 131830
// gas legacyOptimized: 112054
// test_boundary_check(uint256,uint256): 256, 255 -> 0
// gas irOptimized: 153717
// gas legacy: 134149