From bd51589f1a31c28473f7467e3179ee2da0f60d09 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 25 Feb 2019 23:59:13 +0000 Subject: [PATCH] Use "if" instead of "switch" in codegen for the deployment time address of a library --- libsolidity/codegen/ContractCompiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 8320d23d5..b10882749 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -177,6 +177,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract) solAssert(m_context.runtimeSub() != size_t(-1), "Runtime sub not registered"); m_context.pushSubroutineSize(m_context.runtimeSub()); m_context.pushSubroutineOffset(m_context.runtimeSub()); + // This code replaces the address added by appendDeployTimeAddress(). m_context.appendInlineAssembly(R"( { // If code starts at 11, an mstore(0) writes to the full PUSH20 plus data @@ -184,8 +185,7 @@ size_t ContractCompiler::deployLibrary(ContractDefinition const& _contract) let codepos := 11 codecopy(codepos, subOffset, subSize) // Check that the first opcode is a PUSH20 - switch eq(0x73, byte(0, mload(codepos))) - case 0 { invalid() } + if iszero(eq(0x73, byte(0, mload(codepos)))) { invalid() } mstore(0, address()) mstore8(codepos, 0x73) return(codepos, subSize)