Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE in CompilerContext::appendInlineAssembly()::(anonymous class)::operator()(const std::__cxx11::string &) [Invalid assembly generated by code generator] #8368

Closed
agroce opened this issue Feb 22, 2020 · 6 comments
Assignees
Labels

Comments

@agroce
Copy link

@agroce agroce commented Feb 22, 2020

Description

The attached contract (which does not work well just copied from here, but is shown to give an overview of what it looks like):

pragma experimental ABIEncoderV2;contract C{struct S{int56 x;}bytes32 y=sha256("             ?                                                \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");}

produces:

Internal compiler error during compilation:
/home/user/solidity/libsolidity/codegen/CompilerContext.cpp(405): Throw in function auto solidity::frontend::CompilerContext::appendInlineAssembly(const std::__cxx11::string &, const vector<std::__cxx11::string> &, const set<std::__cxx11::string> &, bool, const solidity::frontend::OptimiserSettings &)::(anonymous class)::operator()(const std::__cxx11::string &)
[invalidassembly.zip](https://github.com/ethereum/solidity/files/4239727/invalidassembly.zip)

 const
Dynamic exception type: boost::exception_detail::clone_impl<solidity::langutil::InternalCompilerError>
std::exception::what: Error parsing/analyzing inline assembly block:
Invalid assembly generated by code generator.
------------------ Input: -----------------
{
			function abi_decode_t_bytes32_fromMemory(offset, end) -> value {
				value := mload(offset)
				validator_revert_t_bytes32(value)
			}
		
			function abi_decode_tuple_t_bytes32_fromMemory(headStart, dataEnd) -> value0 {
				if slt(sub(dataEnd, headStart), 32) { revert(0, 0) }
				
				{
					let offset := 0
					value0 := abi_decode_t_bytes32_fromMemory(add(headStart, offset), dataEnd)
				}
				
			}
		
				function abi_encode_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde_to_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos) -> end {
					pos := array_storeLengthForEncoding_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos, 115)
					
						mstore(add(pos, 0), 0x202020202020202020202001002020ff7f000020202020202020202020202020)
					
						mstore(add(pos, 32), "                                ")
					
						mstore(add(pos, 64), "   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\")
					
						mstore(add(pos, 96), "\\\\\\\\\\\\\\\\\\\")
					
					end := add(pos, 115)
				}
			
			function abi_encode_tuple_packed_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde__to_t_bytes_memory_ptr__nonPadded_inplace_fromStack(pos ) -> end {
				
					pos := abi_encode_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde_to_t_bytes_memory_ptr_nonPadded_inplace_fromStack( pos)
				
				end := pos
			}
		
				function array_storeLengthForEncoding_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos, length) -> updated_pos {
					updated_pos := pos
				}
			
			function cleanup_t_bytes32(value) -> cleaned {
				cleaned := value
			}
		
			function validator_revert_t_bytes32(value) {
				if iszero(eq(value, cleanup_t_bytes32(value))) { revert(0, 0) }
			}
		}
------------------ Errors: ----------------
--CODEGEN--:24:28: Error: Literal or identifier expected.
						mstore(add(pos, 64), "   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\")
						                     ^---------------------------------^
-------------------------------------------

[solidity::util::tag_comment*] = Error parsing/analyzing inline assembly block:
Invalid assembly generated by code generator.
------------------ Input: -----------------
{
			function abi_decode_t_bytes32_fromMemory(offset, end) -> value {
				value := mload(offset)
				validator_revert_t_bytes32(value)
			}
		
			function abi_decode_tuple_t_bytes32_fromMemory(headStart, dataEnd) -> value0 {
				if slt(sub(dataEnd, headStart), 32) { revert(0, 0) }
				
				{
					let offset := 0
					value0 := abi_decode_t_bytes32_fromMemory(add(headStart, offset), dataEnd)
				}
				
			}
		
				function abi_encode_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde_to_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos) -> end {
					pos := array_storeLengthForEncoding_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos, 115)
					
						mstore(add(pos, 0), 0x202020202020202020202001002020ff7f000020202020202020202020202020)
					
						mstore(add(pos, 32), "                                ")
					
						mstore(add(pos, 64), "   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\")
					
						mstore(add(pos, 96), "\\\\\\\\\\\\\\\\\\\")
					
					end := add(pos, 115)
				}
			
			function abi_encode_tuple_packed_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde__to_t_bytes_memory_ptr__nonPadded_inplace_fromStack(pos ) -> end {
				
					pos := abi_encode_t_stringliteral_c816a9c7bea034f32c215b4d77b16e7e57af3a1d1fcc3653a2145c811f5b2fde_to_t_bytes_memory_ptr_nonPadded_inplace_fromStack( pos)
				
				end := pos
			}
		
				function array_storeLengthForEncoding_t_bytes_memory_ptr_nonPadded_inplace_fromStack(pos, length) -> updated_pos {
					updated_pos := pos
				}
			
			function cleanup_t_bytes32(value) -> cleaned {
				cleaned := value
			}
		
			function validator_revert_t_bytes32(value) {
				if iszero(eq(value, cleanup_t_bytes32(value))) { revert(0, 0) }
			}
		}
------------------ Errors: ----------------
--CODEGEN--:24:28: Error: Literal or identifier expected.
						mstore(add(pos, 64), "   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\")
						                     ^---------------------------------^
-------------------------------------------


when compiled with solc (optimization not needed)

On master, using AFL fuzzing. Another discovery using https://github.com/agroce/afl-compiler-fuzzer, again with more mutation operators

Environment

  • Compiler version: 0.6.3-develop.2020.2.10+commit.e8eb1f2d.Linux.clang
  • Target EVM version (as per compiler settings): N/A
  • Framework/IDE (e.g. Truffle or Remix): N/A
  • EVM execution environment / backend / blockchain client: N/A
  • Operating system: Ubuntu 18.04 in docker

Steps to Reproduce

Above shows pretty clearly, I think.

@chriseth chriseth added the bug 🐛 label Feb 24, 2020
@Marenz Marenz changed the title ICE in solidity::frontend::CompilerContext::appendInlineAssembly(const std::__cxx11::string &, const vector<std::__cxx11::string> &, const set<std::__cxx11::string> &, bool, const solidity::frontend::OptimiserSettings &)::(anonymous class)::operator()(const std::__cxx11::string &) [Invalid assembly generated by code generator] ICE in CompilerContext::appendInlineAssembly()::(anonymous class)::operator()(const std::__cxx11::string &) [Invalid assembly generated by code generator] May 7, 2020
@Marenz
Copy link
Contributor

@Marenz Marenz commented May 7, 2020

I was unable to reproduce this with the given compiler version and contract. Do I need to use any specific flags when compiling?

@agroce
Copy link
Author

@agroce agroce commented May 7, 2020

Hmm. Try adding --optimize, or solfuzzer?

@chriseth
Copy link
Contributor

@chriseth chriseth commented May 7, 2020

It looks like the backslashes are not properly escaped and I would say this is still the case.

@agroce
Copy link
Author

@agroce agroce commented May 7, 2020

I can reproduce on a more recent solc:

$ ~/solidity/build/solc/solc --version
solc, the solidity compiler commandline interface
Version: 0.6.7-develop.2020.4.20+commit.41ef1312.Linux.clang

Use the file https://github.com/agroce/afl-compiler-fuzzer/blob/master/example.sol

$ ~/solidity/build/solc/solc example.sol

...

Internal compiler error during compilation:
/home/user/solidity/libsolidity/codegen/CompilerContext.cpp(439): Throw in function auto solidity::frontend::CompilerContext::appendInlineAssembly(const std::__cxx11::string &, const vector<std::__cxx11::string> &, const set<std::__cxx11::string> &, bool, const solidity::frontend::OptimiserSettings &)::(anonymous class)::operator()(const std::__cxx11::string &) const
Dynamic exception type: boost::exception_detail::clone_impl<solidity::langutil::InternalCompilerError>
std::exception::what: Error parsing/analyzing inline assembly block:
Invalid assembly generated by code generator.
@Marenz
Copy link
Contributor

@Marenz Marenz commented May 7, 2020

Using your provided file I can reproduce it as well now. Thanks!

@bshastry
Copy link
Contributor

@bshastry bshastry commented May 11, 2020

Another test case for this issue if that helps

pragma experimental ABIEncoderV2;
contract C{function i()public{abi.encode(("\\"));}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.