Merge pull request #6166 from ethereum/library-codegen-if

Use "if" instead of "switch" in codegen for the deployment time address of a library
This commit is contained in:
chriseth 2019-03-04 16:24:07 +01:00 committed by GitHub
commit fee4eb05bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)