Remove opcodes from CodeCompiler

Really old versions of solidity compiler, e.g. v0.1.3, have different
output schemas. This data was never used by our application, so instead
of having to deal with different outputs, we just don't try to get this
item anymore.
wsa-jason-decode-error
William Sanches 6 years ago
parent c1e582e85c
commit 2b48235898
No known key found for this signature in database
GPG Key ID: 27250E49FB133014
  1. 16
      apps/explorer/lib/explorer/smart_contract/solidity/code_compiler.ex
  2. 3
      apps/explorer/priv/compile_solc.js
  3. 18
      apps/explorer/test/explorer/smart_contract/solidity/code_compiler_test.exs

@ -53,9 +53,8 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
"type" => "function"
}
],
"bytecode" => "6080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a72305820235fceab083d33bf112b473c85551306a29f32dcdc7e95b4dfdd697c1db188ec0029",
"name" => "SimpleStorage",
"opcodes" => "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH2 0x10 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0xDF DUP1 PUSH2 0x1F PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH1 0x49 JUMPI PUSH1 0x0 CALLDATALOAD PUSH29 0x100000000000000000000000000000000000000000000000000000000 SWAP1 DIV PUSH4 0xFFFFFFFF AND DUP1 PUSH4 0x60FE47B1 EQ PUSH1 0x4E JUMPI DUP1 PUSH4 0x6D4CE63C EQ PUSH1 0x78 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE DUP1 ISZERO PUSH1 0x59 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x76 PUSH1 0x4 DUP1 CALLDATASIZE SUB DUP2 ADD SWAP1 DUP1 DUP1 CALLDATALOAD SWAP1 PUSH1 0x20 ADD SWAP1 SWAP3 SWAP2 SWAP1 POP POP POP PUSH1 0xA0 JUMP JUMPDEST STOP JUMPDEST CALLVALUE DUP1 ISZERO PUSH1 0x83 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x8A PUSH1 0xAA JUMP JUMPDEST PUSH1 0x40 MLOAD DUP1 DUP3 DUP2 MSTORE PUSH1 0x20 ADD SWAP2 POP POP PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST DUP1 PUSH1 0x0 DUP2 SWAP1 SSTORE POP POP JUMP JUMPDEST PUSH1 0x0 DUP1 SLOAD SWAP1 POP SWAP1 JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 0x23 0x5f 0xce 0xab ADDMOD RETURNDATASIZE CALLER 0xbf GT 0x2b 0x47 EXTCODECOPY DUP6 SSTORE SGT MOD LOG2 SWAP16 ORIGIN 0xdc 0xdc PUSH31 0x95B4DFDD697C1DB188EC002900000000000000000000000000000000000000 "
"bytecode" => "6080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a72305820834bdab406d80509618957aa1a5ad1a4b77f4f1149078675940494ebe5b4147b0029",
"name" => "SimpleStorage"
}
}
"""
@ -71,11 +70,14 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
]
)
with contracts <- Jason.decode!(response),
%{"abi" => abi, "evm" => %{"deployedBytecode" => %{"object" => bytecode, "opcodes" => opcodes}}} <-
with {:ok, contracts} <- Jason.decode(response),
%{"abi" => abi, "evm" => %{"deployedBytecode" => %{"object" => bytecode}}} <-
get_contract_info(contracts, name) do
{:ok, %{"abi" => abi, "bytecode" => bytecode, "name" => name, "opcodes" => opcodes}}
{:ok, %{"abi" => abi, "bytecode" => bytecode, "name" => name}}
else
{:error, %Jason.DecodeError{}} ->
{:error, :compilation}
error ->
parse_error(error)
end
@ -98,9 +100,9 @@ defmodule Explorer.SmartContract.Solidity.CodeCompiler do
end
end
def parse_error({:error, :name} = error), do: error
def parse_error(%{"error" => error}), do: {:error, [error]}
def parse_error(%{"errors" => errors}), do: {:error, errors}
def parse_error({:error, _} = error), do: error
defp optimize_value(false), do: "0"
defp optimize_value("false"), do: "0"

@ -32,7 +32,8 @@ var compiled_code = solc.loadRemoteVersion(version, function (err, solcSnapshot)
}
const output = JSON.parse(solcSnapshot.compile(JSON.stringify(input)))
const response = output.contracts['New.sol']
/** Older solc-bin versions don't use filename as contract key */
const response = output.contracts['New.sol'] || output.contracts['']
console.log(JSON.stringify(response));
}
});

@ -24,8 +24,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
%{
"abi" => _,
"bytecode" => _,
"name" => _,
"opcodes" => _
"name" => _
}} = response
end
@ -44,8 +43,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
%{
"abi" => _,
"bytecode" => _,
"name" => _,
"opcodes" => _
"name" => _
}} = response
end
@ -75,12 +73,11 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
%{
"abi" => _,
"bytecode" => _,
"name" => _,
"opcodes" => _
"name" => _
}} = response
end
test "returns a list of errors the compilation isn't possible", %{
test "returns compilation error when compilation isn't possible", %{
contract_code_info: contract_code_info
} do
wrong_code = "pragma solidity ^0.4.24; cont SimpleStorage { "
@ -93,8 +90,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
contract_code_info.optimized
)
assert {:error, errors} = response
assert is_list(errors)
assert {:error, :compilation} = response
end
end
@ -117,7 +113,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
end
test "the contract info is returned when the name matches" do
contract_inner_info = %{"abi" => %{}, "bytecode" => "", "opcodes" => ""}
contract_inner_info = %{"abi" => %{}, "bytecode" => ""}
name = "Name"
contract_info = %{name => contract_inner_info}
@ -129,7 +125,7 @@ defmodule Explorer.SmartContract.Solidity.CodeCompilerTest do
test "the contract info is returned when the name matches with a `:` suffix" do
name = "Name"
name_with_suffix = ":Name"
contract_inner_info = %{"abi" => %{}, "bytecode" => "", "opcodes" => ""}
contract_inner_info = %{"abi" => %{}, "bytecode" => ""}
contract_info = %{name_with_suffix => contract_inner_info}
response = CodeCompiler.get_contract_info(contract_info, name)

Loading…
Cancel
Save