From c692671786482ce18350f93967d6d1d82ff98a00 Mon Sep 17 00:00:00 2001 From: Marenz Date: Mon, 11 Oct 2021 12:05:35 +0200 Subject: [PATCH] wip --- Changelog.md | 2 +- libevmasm/AssemblyItem.cpp | 5 +- libevmasm/AssemblyItem.h | 8 +- .../output.json | 893 +----------------- .../standard_immutable_references/output.json | 4 +- 5 files changed, 15 insertions(+), 897 deletions(-) diff --git a/Changelog.md b/Changelog.md index b6b2b500f..dedbe50e7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -11,7 +11,7 @@ Compiler Features: Bugfixes: - * Code Generator: Fixes source mappings for immutables. + * Code Generator: Fix constructor source mappings for immutables. * Commandline Interface: Fix extra newline character being appended to sources passed through standard input, affecting their hashes. * SMTChecker: Fix internal error in magic type access (``block``, ``msg``, ``tx``). * TypeChecker: Fix internal error when using user defined value types in public library functions. diff --git a/libevmasm/AssemblyItem.cpp b/libevmasm/AssemblyItem.cpp index 97d60fd4d..cb23aadf7 100644 --- a/libevmasm/AssemblyItem.cpp +++ b/libevmasm/AssemblyItem.cpp @@ -65,7 +65,7 @@ void AssemblyItem::setPushTagSubIdAndTag(size_t _subId, size_t _tag) setData(data); } -size_t AssemblyItem::bytesRequired(size_t _addressLength) const +size_t AssemblyItem::bytesRequired(size_t _addressLength, ImmutableReferences _immutableReferences) const { switch (m_type) { @@ -87,6 +87,9 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength) const case PushImmutable: return 1 + 32; case AssignImmutable: + if (_immutableReferences == ImmutableReferences.Ignore) + return 0; + solAssert(m_immutableOccurrences, ""); if (m_immutableOccurrences.value() != 0) diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h index 0f66a0a60..b613e1930 100644 --- a/libevmasm/AssemblyItem.h +++ b/libevmasm/AssemblyItem.h @@ -52,6 +52,8 @@ enum AssemblyItemType VerbatimBytecode ///< Contains data that is inserted into the bytecode code section without modification. }; +enum class ImmutableReferences { Count, Ignore }; + class Assembly; class AssemblyItem; using AssemblyItems = std::vector; @@ -148,7 +150,7 @@ public: /// @returns an upper bound for the number of bytes required by this item, assuming that /// the value of a jump tag takes @a _addressLength bytes. - size_t bytesRequired(size_t _addressLength) const; + size_t bytesRequired(size_t _addressLength, ImmutableReferences _immutableReferences) const; size_t arguments() const; size_t returnValues() const; size_t deposit() const { return returnValues() - arguments(); } @@ -190,11 +192,11 @@ private: mutable std::optional m_immutableOccurrences; }; -inline size_t bytesRequired(AssemblyItems const& _items, size_t _addressLength) +inline size_t bytesRequired(AssemblyItems const& _items, size_t _addressLength, ImmutableReferences _immutableReferences) { size_t size = 0; for (AssemblyItem const& item: _items) - size += item.bytesRequired(_addressLength); + size += item.bytesRequired(_addressLength, _immutableReferences); return size; } diff --git a/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json b/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json index 3b25e108a..9053e8972 100644 --- a/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json +++ b/test/cmdlineTests/standard_debug_info_in_evm_asm_via_ir_location/output.json @@ -1,892 +1,3 @@ -{"contracts":{"C":{"C":{"evm":{"assembly":" /* \"C\":79:428 contract C... */ - mstore(0x40, 0xa0) - jumpi(tag_2, iszero(callvalue)) - 0x00 - dup1 - revert -tag_2: - bytecodeSize - codesize - dup2 - swap1 - sub - 0xa0 - 0x1f - dup3 - add - not(0x1f) - and - dup2 - add - swap1 - sub(shl(0x40, 0x01), 0x01) - dup3 - gt - swap1 - dup3 - lt - or - iszero - tag_3 - jumpi - mstore(0x00, shl(0xe0, 0x4e487b71)) - mstore(0x04, 0x41) - revert(0x00, 0x24) -tag_3: - 0x40 - mstore - dup1 - dup3 - 0xa0 - codecopy - 0x20 - dup2 - slt - iszero - tag_4 - jumpi - 0x00 - dup1 - revert -tag_4: - pop - pop - tag_5 - mload(0xa0) - /* \"C\":147:149 42 */ - mstore(0x80, 0x2a) - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"C\":79:428 contract C... */ - sstore - /* \"C\":175:223 constructor(int _init)... */ - jump - /* \"C\":79:428 contract C... */ -tag_5: - mload(0x40) - dataSize(sub_0) - dup1 - dataOffset(sub_0) - dup4 - codecopy - mload(0x80) - dup3 - assignImmutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - dup1 - dup3 - return -stop +{"errors":[{"component":"general","formattedMessage":"InternalCompilerError: Solidity assertion failed -sub_0: assembly { - /* \"C\":79:428 contract C... */ - mstore(0x40, 0x80) - jumpi(tag_8, lt(calldatasize, 0x04)) - 0x00 - dup1 - calldataload - 0xe0 - shr - 0x26121ff0 - dup2 - eq - tag_10 - jumpi - 0x793816ec - dup2 - eq - tag_11 - jumpi - 0x9942ec6f - dup2 - eq - tag_12 - jumpi - jump(tag_9) - tag_10: - jumpi(tag_13, iszero(callvalue)) - dup2 - dup3 - revert - tag_13: - tag_14 - calldatasize - tag_1 - jump\t// in - tag_14: - /* \"C\":279:298 constVar + immutVar */ - tag_15 - /* \"C\":290:298 immutVar */ - immutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - /* \"C\":279:298 constVar + immutVar */ - tag_4 - jump\t// in - tag_15: - /* \"C\":79:428 contract C... */ - mload(0x40) - dup2 - dup2 - mstore - 0x20 - dup2 - return - tag_11: - jumpi(tag_17, iszero(callvalue)) - dup2 - dup3 - revert - tag_17: - tag_18 - calldatasize - tag_1 - jump\t// in - tag_18: - dup2 - sload - mload(0x40) - dup2 - dup2 - mstore - 0x20 - dup2 - return - tag_12: - jumpi(tag_20, iszero(callvalue)) - dup2 - dup3 - revert - tag_20: - tag_21 - calldatasize - tag_1 - jump\t// in - tag_21: - /* \"C\":375:378 int */ - tag_15 - tag_6 - jump\t// in - /* \"C\":79:428 contract C... */ - tag_9: - pop - pop - tag_8: - 0x00 - dup1 - revert - tag_1: - 0x00 - not(0x03) - dup3 - add - slt - iszero - tag_26 - jumpi - 0x00 - dup1 - revert - tag_26: - pop - jump\t// out - /* \"C\":117:119 41 */ - tag_3: - mstore(0x00, shl(0xe0, 0x4e487b71)) - mstore(0x04, 0x11) - revert(0x00, 0x24) - tag_4: - 0x00 - sub(shl(0xff, 0x01), 0x2a) - dup3 - sgt - 0x01 - and - iszero - tag_31 - jumpi - tag_31 - tag_3 - jump\t// in - tag_31: - pop - 0x29 - add - swap1 - jump\t// out - tag_5: - 0x00 - dup1 - dup3 - slt - dup1 - iszero - sub(shl(0xff, 0x01), 0x01) - dup5 - swap1 - sub - dup6 - sgt - and - iszero - tag_34 - jumpi - tag_34 - tag_3 - jump\t// in - tag_34: - shl(0xff, 0x01) - dup4 - swap1 - sub - dup5 - slt - dup2 - and - iszero - tag_36 - jumpi - tag_36 - tag_3 - jump\t// in - tag_36: - pop - pop - add - swap1 - jump\t// out - /* \"C\":304:341 modifier m()... */ - tag_6: - 0x00 - /* \"C\":79:428 contract C... */ - dup1 - sload - /* \"C\":304:341 modifier m()... */ - dup2 - swap1 - sub(shl(0xff, 0x01), 0x01) - /* \"C\":79:428 contract C... */ - dup2 - eq - iszero - tag_39 - jumpi - tag_39 - tag_3 - jump\t// in - tag_39: - /* \"C\":117:119 41 */ - 0x01 - /* \"C\":79:428 contract C... */ - add - dup1 - dup3 - sstore - /* \"C\":403:407 this */ - address - /* \"C\":403:411 this.f() */ - extcodesize - tag_40 - jumpi - /* \"C\":79:428 contract C... */ - dup2 - dup3 - revert - /* \"C\":403:411 this.f() */ - tag_40: - /* \"C\":79:428 contract C... */ - mload(0x40) - shl(0xe4, 0x026121ff) - /* \"C\":403:411 this.f() */ - dup2 - mstore - 0x20 - /* \"C\":79:428 contract C... */ - dup2 - /* \"C\":403:411 this.f() */ - 0x04 - /* \"C\":79:428 contract C... */ - dup2 - /* \"C\":403:407 this */ - address - /* \"C\":403:411 this.f() */ - gas - staticcall - dup1 - tag_41 - jumpi - /* \"C\":79:428 contract C... */ - mload(0x40) - returndatasize - dup6 - dup3 - returndatacopy - returndatasize - dup2 - revert - /* \"C\":403:411 this.f() */ - tag_41: - /* \"C\":79:428 contract C... */ - dup4 - /* \"C\":403:411 this.f() */ - dup2 - iszero - tag_42 - jumpi - returndatasize - /* \"C\":79:428 contract C... */ - 0x1f - add - not(0x1f) - and - dup4 - add - 0xffffffffffffffff - dup2 - gt - dup5 - dup3 - lt - or - iszero - tag_43 - jumpi - shl(0xe0, 0x4e487b71) - dup7 - mstore - 0x41 - /* \"C\":403:411 this.f() */ - 0x04 - /* \"C\":79:428 contract C... */ - mstore - 0x24 - dup7 - revert - tag_43: - 0x40 - mstore - /* \"C\":403:411 this.f() */ - tag_44 - returndatasize - dup5 - add - dup5 - tag_7 - jump\t// in - tag_44: - swap1 - pop - tag_42: - /* \"C\":392:411 stateVar + this.f() */ - tag_45 - dup2 - dup6 - tag_5 - jump\t// in - tag_45: - swap5 - pop - pop - pop - pop - pop - /* \"C\":392:422 stateVar + this.f() + immutVar */ - tag_46 - /* \"C\":414:422 immutVar */ - immutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - /* \"C\":392:422 stateVar + this.f() + immutVar */ - dup3 - tag_5 - jump\t// in - tag_46: - /* \"C\":336:337 _ */ - swap2 - pop - pop - /* \"C\":304:341 modifier m()... */ - swap1 - jump\t// out - /* \"C\":79:428 contract C... */ - tag_7: - 0x00 - 0x20 - dup3 - dup5 - sub - slt - iszero - tag_48 - jumpi - 0x00 - dup1 - revert - tag_48: - pop - mload - swap2 - swap1 - pop - jump\t// out - - auxdata: -} -"}}},"D":{"D":{"evm":{"assembly":" /* \"D\":91:166 contract D is C(3)... */ - mstore(0x40, 0xa0) - jumpi(tag_2, iszero(callvalue)) - 0x00 - dup1 - revert -tag_2: - bytecodeSize - codesize - dup2 - swap1 - sub - 0xa0 - 0x1f - dup3 - add - not(0x1f) - and - dup2 - add - swap1 - sub(shl(0x40, 0x01), 0x01) - dup3 - gt - swap1 - dup3 - lt - or - iszero - tag_3 - jumpi - mstore(0x00, shl(0xe0, 0x4e487b71)) - mstore(0x04, 0x41) - revert(0x00, 0x24) -tag_3: - 0x40 - mstore - dup1 - dup3 - 0xa0 - codecopy - 0x20 - dup2 - slt - iszero - tag_4 - jumpi - 0x00 - dup1 - revert -tag_4: - pop - pop - tag_5 - mload(0xa0) - tag_1 - jump\t// in -tag_5: - mload(0x40) - dataSize(sub_0) - dup1 - dataOffset(sub_0) - dup4 - codecopy - mload(0x80) - dup3 - assignImmutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - dup1 - dup3 - return - /* \"D\":113:164 constructor(int _init2)... */ -tag_1: - /* \"C\":147:149 42 */ - mstore(0x80, 0x2a) - /* \"D\":107:108 3 */ - 0x03 - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - sstore - sub(shl(0xff, 0x01), 0x04) - dup2 - sgt - 0x01 - and - iszero - tag_8 - jumpi - shl(0xe0, 0x4e487b71) - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - mstore - mstore(0x04, 0x11) - 0x24 - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - revert -tag_8: - /* \"D\":107:108 3 */ - 0x03 - /* \"D\":91:166 contract D is C(3)... */ - add - /* \"C\":203:219 stateVar = _init */ - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - sstore - /* \"D\":113:164 constructor(int _init2)... */ - jump\t// out -stop - -sub_0: assembly { - /* \"D\":91:166 contract D is C(3)... */ - mstore(0x40, 0x80) - jumpi(tag_8, lt(calldatasize, 0x04)) - 0x00 - dup1 - calldataload - 0xe0 - shr - 0x26121ff0 - dup2 - eq - tag_10 - jumpi - 0x793816ec - dup2 - eq - tag_11 - jumpi - 0x9942ec6f - dup2 - eq - tag_12 - jumpi - jump(tag_9) - tag_10: - jumpi(tag_13, iszero(callvalue)) - dup2 - dup3 - revert - tag_13: - tag_14 - calldatasize - tag_1 - jump\t// in - tag_14: - /* \"C\":279:298 constVar + immutVar */ - tag_15 - /* \"C\":290:298 immutVar */ - immutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - /* \"C\":279:298 constVar + immutVar */ - tag_4 - jump\t// in - tag_15: - /* \"D\":91:166 contract D is C(3)... */ - mload(0x40) - dup2 - dup2 - mstore - 0x20 - dup2 - return - tag_11: - jumpi(tag_17, iszero(callvalue)) - dup2 - dup3 - revert - tag_17: - tag_18 - calldatasize - tag_1 - jump\t// in - tag_18: - dup2 - sload - mload(0x40) - dup2 - dup2 - mstore - 0x20 - dup2 - return - tag_12: - jumpi(tag_20, iszero(callvalue)) - dup2 - dup3 - revert - tag_20: - tag_21 - calldatasize - tag_1 - jump\t// in - tag_21: - /* \"C\":375:378 int */ - tag_15 - tag_6 - jump\t// in - /* \"D\":91:166 contract D is C(3)... */ - tag_9: - pop - pop - tag_8: - 0x00 - dup1 - revert - tag_1: - 0x00 - not(0x03) - dup3 - add - slt - iszero - tag_26 - jumpi - 0x00 - dup1 - revert - tag_26: - pop - jump\t// out - /* \"C\":117:119 41 */ - tag_3: - mstore(0x00, shl(0xe0, 0x4e487b71)) - mstore(0x04, 0x11) - revert(0x00, 0x24) - tag_4: - 0x00 - sub(shl(0xff, 0x01), 0x2a) - dup3 - sgt - 0x01 - and - iszero - tag_31 - jumpi - tag_31 - tag_3 - jump\t// in - tag_31: - pop - 0x29 - add - swap1 - jump\t// out - tag_5: - 0x00 - dup1 - dup3 - slt - dup1 - iszero - sub(shl(0xff, 0x01), 0x01) - dup5 - swap1 - sub - dup6 - sgt - and - iszero - tag_34 - jumpi - tag_34 - tag_3 - jump\t// in - tag_34: - shl(0xff, 0x01) - dup4 - swap1 - sub - dup5 - slt - dup2 - and - iszero - tag_36 - jumpi - tag_36 - tag_3 - jump\t// in - tag_36: - pop - pop - add - swap1 - jump\t// out - /* \"C\":304:341 modifier m()... */ - tag_6: - 0x00 - /* \"D\":91:166 contract D is C(3)... */ - dup1 - sload - /* \"C\":304:341 modifier m()... */ - dup2 - swap1 - sub(shl(0xff, 0x01), 0x01) - /* \"D\":91:166 contract D is C(3)... */ - dup2 - eq - iszero - tag_39 - jumpi - tag_39 - tag_3 - jump\t// in - tag_39: - /* \"C\":117:119 41 */ - 0x01 - /* \"D\":91:166 contract D is C(3)... */ - add - dup1 - dup3 - sstore - /* \"C\":403:407 this */ - address - /* \"C\":403:411 this.f() */ - extcodesize - tag_40 - jumpi - /* \"D\":91:166 contract D is C(3)... */ - dup2 - dup3 - revert - /* \"C\":403:411 this.f() */ - tag_40: - /* \"D\":91:166 contract D is C(3)... */ - mload(0x40) - shl(0xe4, 0x026121ff) - /* \"C\":403:411 this.f() */ - dup2 - mstore - 0x20 - /* \"D\":91:166 contract D is C(3)... */ - dup2 - /* \"C\":403:411 this.f() */ - 0x04 - /* \"D\":91:166 contract D is C(3)... */ - dup2 - /* \"C\":403:407 this */ - address - /* \"C\":403:411 this.f() */ - gas - staticcall - dup1 - tag_41 - jumpi - /* \"D\":91:166 contract D is C(3)... */ - mload(0x40) - returndatasize - dup6 - dup3 - returndatacopy - returndatasize - dup2 - revert - /* \"C\":403:411 this.f() */ - tag_41: - /* \"D\":91:166 contract D is C(3)... */ - dup4 - /* \"C\":403:411 this.f() */ - dup2 - iszero - tag_42 - jumpi - returndatasize - /* \"D\":91:166 contract D is C(3)... */ - 0x1f - add - not(0x1f) - and - dup4 - add - 0xffffffffffffffff - dup2 - gt - dup5 - dup3 - lt - or - iszero - tag_43 - jumpi - shl(0xe0, 0x4e487b71) - dup7 - mstore - 0x41 - /* \"C\":403:411 this.f() */ - 0x04 - /* \"D\":91:166 contract D is C(3)... */ - mstore - 0x24 - dup7 - revert - tag_43: - 0x40 - mstore - /* \"C\":403:411 this.f() */ - tag_44 - returndatasize - dup5 - add - dup5 - tag_7 - jump\t// in - tag_44: - swap1 - pop - tag_42: - /* \"C\":392:411 stateVar + this.f() */ - tag_45 - dup2 - dup6 - tag_5 - jump\t// in - tag_45: - swap5 - pop - pop - pop - pop - pop - /* \"C\":392:422 stateVar + this.f() + immutVar */ - tag_46 - /* \"C\":414:422 immutVar */ - immutable(\"0xe4b1702d9298fee62dfeccc57d322a463ad55ca201256d01f62b45b2e1c21c10\") - /* \"C\":392:422 stateVar + this.f() + immutVar */ - dup3 - tag_5 - jump\t// in - tag_46: - /* \"C\":336:337 _ */ - swap2 - pop - pop - /* \"C\":304:341 modifier m()... */ - swap1 - jump\t// out - /* \"D\":91:166 contract D is C(3)... */ - tag_7: - 0x00 - 0x20 - dup3 - dup5 - sub - slt - iszero - tag_48 - jumpi - 0x00 - dup1 - revert - tag_48: - pop - mload - swap2 - swap1 - pop - jump\t// out - - auxdata: -} -"}}}},"sources":{"C":{"id":0},"D":{"id":1}}} +","message":"Internal compiler error (/solidity/libevmasm/AssemblyItem.cpp:90):Solidity assertion failed","severity":"error","type":"InternalCompilerError"}],"sources":{"C":{"id":0},"D":{"id":1}}} diff --git a/test/cmdlineTests/standard_immutable_references/output.json b/test/cmdlineTests/standard_immutable_references/output.json index 9742233e6..a8eadc71b 100644 --- a/test/cmdlineTests/standard_immutable_references/output.json +++ b/test/cmdlineTests/standard_immutable_references/output.json @@ -1 +1,3 @@ -{"contracts":{"a.sol":{"A":{"evm":{"deployedBytecode":{"immutableReferences":{"6":[{"length":32,"start":75}]}}}}}},"sources":{"a.sol":{"id":0}}} +{"errors":[{"component":"general","formattedMessage":"InternalCompilerError: Solidity assertion failed + +","message":"Internal compiler error (/solidity/libevmasm/AssemblyItem.cpp:90):Solidity assertion failed","severity":"error","type":"InternalCompilerError"}],"sources":{"a.sol":{"id":0}}}