Skip to content

Commit

Permalink
Account for subassemblies in tag size calculation, test adjustments a…
Browse files Browse the repository at this point in the history
…nd changelog entry.
  • Loading branch information
ekpyron committed Feb 20, 2024
1 parent 4d163ff commit 8e21255
Show file tree
Hide file tree
Showing 53 changed files with 125 additions and 112 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Compiler Features:


Bugfixes:
* Assembler: Prevent incorrect calculation of tag sizes.
* SMTChecker: Fix internal error caused by not respecting the sign of an integer type when constructing zero-value SMT expressions.


Expand Down
12 changes: 12 additions & 0 deletions libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,18 @@ LinkerObject const& Assembly::assemble() const
std::multimap<size_t, size_t> subRef;
std::vector<unsigned> sizeRef; ///< Pointers to code locations where the size of the program is inserted
unsigned bytesPerTag = numberEncodingSize(bytesRequiredForCode);
// Adjust bytesPerTag for references to sub assemblies.
for (AssemblyItem const& i: m_items)
if (i.type() == PushTag)
{
auto [subId, tagId] = i.splitForeignPushTag();
if (subId == std::numeric_limits<size_t>::max())
continue;
assertThrow(subId < m_subs.size(), AssemblyException, "Invalid sub id");
auto subTagPosition = m_subs[subId]->m_tagPositionsInBytecode.at(tagId);
assertThrow(subTagPosition != std::numeric_limits<size_t>::max(), AssemblyException, "Reference to tag without position.");
bytesPerTag = std::max(bytesPerTag, numberEncodingSize(subTagPosition));
}
uint8_t tagPush = static_cast<uint8_t>(pushInstruction(bytesPerTag));

unsigned bytesRequiredIncludingData = bytesRequiredForCode + 1 + static_cast<unsigned>(m_auxiliaryData.size());
Expand Down
2 changes: 1 addition & 1 deletion test/cmdlineTests/function_debug_info/output
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"abi_decode_tuple_t_uint256_fromMemory":
{
"entryPoint": 92,
"entryPoint": 88,
"parameterSlots": 2,
"returnSlots": 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
[
{
"length": 20,
"start": 174
"start": 173
},
{
"length": 20,
"start": 350
"start": 349
}
]
}
Expand Down
16 changes: 8 additions & 8 deletions test/libsolidity/GasCosts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
if (CommonOptions::get().useABIEncoderV1)
CHECK_DEPLOY_GAS(133045, 129731, evmVersion);
else
CHECK_DEPLOY_GAS(144999, 121229, evmVersion);
CHECK_DEPLOY_GAS(144995, 121229, evmVersion);
}
// This is only correct on >=Constantinople.
else if (!CommonOptions::get().useABIEncoderV1)
Expand All @@ -110,30 +110,30 @@ BOOST_AUTO_TEST_CASE(string_storage)
{
// Costs with 0 are cases which cannot be triggered in tests.
if (evmVersion < EVMVersion::istanbul())
CHECK_DEPLOY_GAS(0, 109241, evmVersion);
CHECK_DEPLOY_GAS(0, 109237, evmVersion);
else if (evmVersion < EVMVersion::shanghai())
CHECK_DEPLOY_GAS(0, 97697, evmVersion);
CHECK_DEPLOY_GAS(0, 97693, evmVersion);
// Shanghai is cheaper due to `push0`
else
CHECK_DEPLOY_GAS(0, 97071, evmVersion);
CHECK_DEPLOY_GAS(0, 97067, evmVersion);
}
else
{
if (evmVersion < EVMVersion::istanbul())
CHECK_DEPLOY_GAS(139013, 123969, evmVersion);
CHECK_DEPLOY_GAS(139009, 123969, evmVersion);
else if (evmVersion < EVMVersion::shanghai())
CHECK_DEPLOY_GAS(123361, 110969, evmVersion);
CHECK_DEPLOY_GAS(123357, 110969, evmVersion);
// Shanghai is cheaper due to `push0`
else
CHECK_DEPLOY_GAS(121493, 110969, evmVersion);
CHECK_DEPLOY_GAS(121489, 110969, evmVersion);
}
}
else if (evmVersion < EVMVersion::istanbul())
CHECK_DEPLOY_GAS(125829, 118559, evmVersion);
else if (evmVersion < EVMVersion::shanghai())
CHECK_DEPLOY_GAS(114077, 96461, evmVersion);
else
CHECK_DEPLOY_GAS(114077, 95835, evmVersion);
CHECK_DEPLOY_GAS(114077, 95831, evmVersion);

if (evmVersion >= EVMVersion::byzantium())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ contract D {
// ----
// f() -> FAILURE, hex"4e487b71", 0x11
// g(), 100 wei -> 1
// gas legacy: 100388
// gas legacy: 100380
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract C {
}
// ----
// constructor(): 1, 2, 3 ->
// gas irOptimized: 139656
// gas irOptimized: 139616
// gas legacy: 180517
// gas legacyOptimized: 150462
// a(uint256): 0 -> 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract C {
}
// ----
// constructor()
// gas irOptimized: 226349
// gas legacy: 215757
// gas legacyOptimized: 181760
// gas irOptimized: 226321
// gas legacy: 215753
// gas legacyOptimized: 181756
// f() -> 0
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Creator {
}
// ----
// constructor(): 1, 2, 3, 4 ->
// gas irOptimized: 126363
// gas irOptimized: 126327
// gas legacy: 174186
// gas legacyOptimized: 128709
// r() -> 4
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/semanticTests/array/reusing_memory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ contract Main {
// ----
// f(uint256): 0x34 -> 0x46bddb1178e94d7f2892ff5f366840eb658911794f2c3a44c450aa2c505186c1
// gas irOptimized: 111924
// gas legacy: 125162
// gas legacy: 125154
// gas legacyOptimized: 113012
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ contract C {
// compileViaYul: also
// ----
// constructor() ->
// gas irOptimized: 443406
// gas legacy: 711299
// gas legacyOptimized: 482382
// gas irOptimized: 443402
// gas legacy: 711295
// gas legacyOptimized: 482378
// h() -> 0x20, 0x40, 0x00, 0
// ~ emit ev(uint256[],uint256): 0x40, 0x21, 0x02, 0x00, 0x00
// g() -> 0x20, 0x40, 0, 0x00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ contract Creator {
// ----
// f(uint256,address[]): 7, 0x40, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 -> 7, 8
// gas irOptimized: 424526
// gas legacy: 581443
// gas legacy: 581426
// gas legacyOptimized: 444599
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ contract Creator {
// ----
// f(uint256,bytes): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" -> 7, "h"
// gas irOptimized: 275102
// gas legacy: 418462
// gas legacy: 418433
// gas legacyOptimized: 291960
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Test {
// ----
// constructor(): 7, 0x40, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz" ->
// gas irOptimized: 269225
// gas legacy: 311324
// gas legacy: 310820
// gas legacyOptimized: 258604
// m_x() -> 7
// m_s() -> 0x20, 78, "abcdefghijklmnopqrstuvwxyzabcdef", "ghijklmnopqrstuvwxyzabcdefghijkl", "mnopqrstuvwxyz"
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ contract Main {
}
// ----
// constructor(): "abc", true
// gas irOptimized: 104394
// gas irOptimized: 104374
// gas legacy: 143300
// gas legacyOptimized: 102961
// gas legacyOptimized: 102933
// getFlag() -> true
// getName() -> "abc"
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract C {
}
// ----
// constructor(): 1, 2, 3, 4 ->
// gas irOptimized: 171015
// gas irOptimized: 170975
// gas legacy: 218378
// gas legacyOptimized: 176211
// a() -> 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ contract B is A {
// compileViaYul: true
// ----
// constructor() ->
// gas irOptimized: 119640
// gas irOptimized: 119636
// y() -> 42
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract B is A {
}
// ----
// constructor() ->
// gas irOptimized: 119640
// gas legacy: 133594
// gas legacyOptimized: 115341
// gas irOptimized: 119636
// gas legacy: 133574
// gas legacyOptimized: 115337
// y() -> 42
4 changes: 2 additions & 2 deletions test/libsolidity/semanticTests/constructor_with_params.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract C {
}
// ----
// constructor(): 2, 0 ->
// gas irOptimized: 101390
// gas legacy: 115678
// gas irOptimized: 101370
// gas legacy: 115614
// i() -> 2
// k() -> 0
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ contract D is B, C {
}
// ----
// constructor(): 2, 0 ->
// gas irOptimized: 151966
// gas irOptimized: 151950
// gas legacy: 168623
// gas legacyOptimized: 144577
// gas legacyOptimized: 144521
// i() -> 2
// j() -> 2
// k() -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ contract D is C {
}
// ----
// constructor(): 2, 0 ->
// gas irOptimized: 121805
// gas irOptimized: 121781
// gas legacy: 137193
// gas legacyOptimized: 118548
// gas legacyOptimized: 118504
// i() -> 2
// k() -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ contract C {
}
// ----
// constructor() ->
// gas irOptimized: 165386
// gas legacy: 244800
// gas legacyOptimized: 171615
// gas irOptimized: 165370
// gas legacy: 244776
// gas legacyOptimized: 171587
// deposit(bytes32), 18 wei: 0x1234 ->
// ~ emit Deposit(address,bytes32,uint256) from 0x137aa4dfc0911524504fcd4d98501f179bc13b4a: #0xc06afe3a8444fc0004668591e8306bfb9968e79e, #0x1234, 0x00
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ contract FixedFeeRegistrar is Registrar {
}
// ----
// constructor()
// gas irOptimized: 384610
// gas legacy: 913421
// gas legacyOptimized: 476928
// gas irOptimized: 384606
// gas legacy: 913417
// gas legacyOptimized: 476924
// reserve(string), 69 ether: 0x20, 3, "abc" ->
// ~ emit Changed(string): #0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45
// gas irOptimized: 45967
Expand Down
6 changes: 3 additions & 3 deletions test/libsolidity/semanticTests/externalContracts/base64.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ contract test {
// EVMVersion: >=constantinople
// ----
// constructor()
// gas irOptimized: 405832
// gas legacy: 735054
// gas legacyOptimized: 522722
// gas irOptimized: 405828
// gas legacy: 735050
// gas legacyOptimized: 522718
// encode_inline_asm(bytes): 0x20, 0 -> 0x20, 0
// encode_inline_asm(bytes): 0x20, 1, "f" -> 0x20, 4, "Zg=="
// encode_inline_asm(bytes): 0x20, 2, "fo" -> 0x20, 4, "Zm8="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ contract DepositContract is IDepositContract, ERC165 {
// ----
// constructor()
// gas irOptimized: 1386886
// gas legacy: 2369061
// gas legacyOptimized: 1740144
// gas legacy: 2368733
// gas legacyOptimized: 1740004
// supportsInterface(bytes4): 0x0 -> 0
// supportsInterface(bytes4): 0xffffffff00000000000000000000000000000000000000000000000000000000 -> false # defined to be false by ERC-165 #
// supportsInterface(bytes4): 0x01ffc9a700000000000000000000000000000000000000000000000000000000 -> true # ERC-165 id #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ contract test {
}
// ----
// constructor()
// gas irOptimized: 1841740
// gas legacy: 2414091
// gas legacyOptimized: 1847616
// gas irOptimized: 1841736
// gas legacy: 2414087
// gas legacyOptimized: 1847612
// div(int256,int256): 3141592653589793238, 88714123 -> 35412542528203691288251815328
// gas irOptimized: 22137
// gas legacy: 22767
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ contract test {
}
// ----
// constructor()
// gas irOptimized: 1716327
// gas legacy: 2193550
// gas legacyOptimized: 1725061
// gas irOptimized: 1716323
// gas legacy: 2193546
// gas legacyOptimized: 1725057
// div(uint256,uint256): 3141592653589793238, 88714123 -> 35412542528203691288251815328
// gas irOptimized: 22004
// gas legacy: 22497
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ contract test {
}
// ----
// constructor()
// gas irOptimized: 407507
// gas legacy: 615090
// gas legacyOptimized: 451871
// gas irOptimized: 407503
// gas legacy: 615086
// gas legacyOptimized: 451867
// prb_pi() -> 3141592656369545286
// gas irOptimized: 57478
// gas legacy: 100947
Expand Down
6 changes: 3 additions & 3 deletions test/libsolidity/semanticTests/externalContracts/strings.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ contract test {
}
// ----
// constructor()
// gas irOptimized: 630224
// gas legacy: 1061957
// gas legacyOptimized: 718937
// gas irOptimized: 630220
// gas legacy: 1061953
// gas legacyOptimized: 718933
// toSlice(string): 0x20, 11, "hello world" -> 11, 0xa0
// gas irOptimized: 22660
// gas legacy: 23190
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract D {
}
// ----
// constructor(): 2 ->
// gas irOptimized: 192703
// gas legacy: 241234
// gas legacyOptimized: 192961
// gas irOptimized: 192663
// gas legacy: 241170
// gas legacyOptimized: 192897
// f() -> 2
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract D {
// EVMVersion: >=constantinople
// ----
// constructor(): 2 ->
// gas irOptimized: 192866
// gas legacy: 241606
// gas legacyOptimized: 193193
// gas irOptimized: 192826
// gas legacy: 241536
// gas legacyOptimized: 193129
// f() -> 2
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ contract test {
}
// ----
// constructor(), 20 wei ->
// gas irOptimized: 252642
// gas legacy: 391588
// gas legacyOptimized: 268089
// gas irOptimized: 252626
// gas legacy: 391568
// gas legacyOptimized: 268069
// sendAmount(uint256): 5 -> 5
// outOfGas() -> FAILURE # call to helper should not succeed but amount should be transferred anyway #
// checkState() -> false, 15
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ contract test {
}
// ----
// constructor(), 20 wei ->
// gas irOptimized: 252642
// gas legacy: 391588
// gas legacyOptimized: 268089
// gas irOptimized: 252626
// gas legacy: 391568
// gas legacyOptimized: 268069
// sendAmount(uint256): 5 -> 5
// outOfGas() -> FAILURE # call to helper should not succeed but amount should be transferred anyway #
// checkState() -> false, 15
Loading

0 comments on commit 8e21255

Please sign in to comment.