From 953d18c6cb1a9eef4814945cd1d647895fe05b83 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 17 Nov 2020 13:13:51 +0000 Subject: [PATCH] Output runtime object in IR --- libsolidity/interface/CompilerStack.cpp | 28 +++++++++++++++---- scripts/error_codes.py | 2 +- .../standard_viair_requested/output.json | 4 +-- test/cmdlineTests/viair_subobjects/output | 4 +-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 245579a0a..4a0fbbd09 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -1226,7 +1226,7 @@ void CompilerStack::compileContract( } // Throw a warning if EIP-170 limits are exceeded: - // If contract creation initialization returns data with length of more than 0x6000 (214 + 213) bytes, + // If contract creation returns data with length greater than 0x6000 (214 + 213) bytes, // contract creation fails with an out of gas error. if ( m_evmVersion >= langutil::EVMVersion::spuriousDragon() && @@ -1299,12 +1299,30 @@ void CompilerStack::generateEVMFromIR(ContractDefinition const& _contract) //cout << yul::AsmPrinter{}(*stack.parserResult()->code) << endl; // TODO: support passing metadata - auto result = stack.assemble(yul::AssemblyStack::Machine::EVM); - compiledContract.object = std::move(*result.bytecode); - // TODO: support runtimeObject - // TODO: add EIP-170 size check for runtimeObject + // TODO: use stack.assemble here! + yul::MachineAssemblyObject init; + yul::MachineAssemblyObject runtime; + std::tie(init, runtime) = stack.assembleAndGuessRuntime(); + compiledContract.object = std::move(*init.bytecode); + compiledContract.runtimeObject = std::move(*runtime.bytecode); // TODO: refactor assemblyItems, runtimeAssemblyItems, generatedSources, // assemblyString, assemblyJSON, and functionEntryPoints to work with this code path + + // Throw a warning if EIP-170 limits are exceeded: + // If contract creation returns data with length greater than 0x6000 (214 + 213) bytes, + // contract creation fails with an out of gas error. + if ( + m_evmVersion >= langutil::EVMVersion::spuriousDragon() && + compiledContract.runtimeObject.bytecode.size() > 0x6000 + ) + m_errorReporter.warning( + 9609_error, + _contract.location(), + "Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). " + "This contract may not be deployable on mainnet. " + "Consider enabling the optimizer (with a low \"runs\" value!), " + "turning off revert strings, or using libraries." + ); } void CompilerStack::generateEwasm(ContractDefinition const& _contract) diff --git a/scripts/error_codes.py b/scripts/error_codes.py index bf4079b32..db85eece9 100755 --- a/scripts/error_codes.py +++ b/scripts/error_codes.py @@ -225,7 +225,7 @@ def examine_id_coverage(top_dir, source_id_to_file_names, new_ids_only=False): "3893", "3996", "4010", "4802", "5073", "5272", "5622", "7128", "7589", "7593", "7653", "8065", "8084", "8140", - "8312", "8592", "9085", "9390" + "8312", "8592", "9085", "9390", "9609", } new_source_only_ids = source_only_ids - old_source_only_ids diff --git a/test/cmdlineTests/standard_viair_requested/output.json b/test/cmdlineTests/standard_viair_requested/output.json index 45479dad0..e46332a28 100644 --- a/test/cmdlineTests/standard_viair_requested/output.json +++ b/test/cmdlineTests/standard_viair_requested/output.json @@ -1,4 +1,4 @@ -{"contracts":{"A":{"C":{"evm":{"bytecode":{"generatedSources":[],"object":""},"deployedBytecode":{"object":""}},"ir":"/******************************************************* +{"contracts":{"A":{"C":{"evm":{"bytecode":{"generatedSources":[],"object":""},"deployedBytecode":{"object":""}},"ir":"/******************************************************* * WARNING * * Solidity to Yul compilation is still EXPERIMENTAL * * It can result in LOSS OF FUNDS or worse * @@ -49,7 +49,7 @@ object \"C_3\" { } -"},"D":{"evm":{"bytecode":{"generatedSources":[],"object":""},"deployedBytecode":{"object":""}},"ir":"/******************************************************* +"},"D":{"evm":{"bytecode":{"generatedSources":[],"object":""},"deployedBytecode":{"object":""}},"ir":"/******************************************************* * WARNING * * Solidity to Yul compilation is still EXPERIMENTAL * * It can result in LOSS OF FUNDS or worse * diff --git a/test/cmdlineTests/viair_subobjects/output b/test/cmdlineTests/viair_subobjects/output index 25c3acdb8..d1bea373f 100644 --- a/test/cmdlineTests/viair_subobjects/output +++ b/test/cmdlineTests/viair_subobjects/output @@ -3,7 +3,7 @@ Binary: 60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd Binary of the runtime part: - +608060405260006000fd Optimized IR: /******************************************************* * WARNING * @@ -37,7 +37,7 @@ object "C_3" { Binary: 608060405234156100105760006000fd5b61010680610021600039806000f350fe6080604052600436101515610088576000803560e01c6326121ff0141561008657341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005e5761005d6100c4565b5b50806100de60803980608083f01515610079573d82833e3d82fd5b508061008482610092565bf35b505b60006000fd6100dc565b6000604051905081810181811067ffffffffffffffff821117156100b9576100b86100c4565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd Binary of the runtime part: - +6080604052600436101515610088576000803560e01c6326121ff0141561008657341561002a578081fd5b806003193601121561003a578081fd5b6028806080016080811067ffffffffffffffff8211171561005e5761005d6100c4565b5b50806100de60803980608083f01515610079573d82833e3d82fd5b508061008482610092565bf35b505b60006000fd6100dc565b6000604051905081810181811067ffffffffffffffff821117156100b9576100b86100c4565b5b80604052505b919050565b634e487b7160e01b600052604160045260246000fd5b565bfe60806040523415600f5760006000fd5b600a80601e600039806000f350fe608060405260006000fd Optimized IR: /******************************************************* * WARNING *