diff --git a/.circleci/config.yml b/.circleci/config.yml index 748a59aa33..c76f6b3053 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,6 +80,19 @@ commands: steps: # otherwise docker compose down errors with ERROR: Couldn't find env file - run: touch localchain_contract_addresses.env + - restore_cache: + key: v2-asdf-install + - run: + name: Install Erlang and Elixir + command: | + [ -d ~/.asdf-vm ] || git clone https://github.com/asdf-vm/asdf.git ~/.asdf-vm --branch v0.8.0 + echo 'source ~/.asdf-vm/asdf.sh' >> $BASH_ENV + source $BASH_ENV + asdf plugin-add erlang || asdf plugin-update erlang + asdf plugin-add elixir || asdf plugin-update elixir + asdf install + no_output_timeout: 2400 + - run: make install-hex-rebar - run: docker-compose down - run: sudo rm -rf data/ - run: @@ -605,6 +618,7 @@ jobs: parallelism: 4 steps: - checkout + - install_elixir - run: name: "Pull Submodules" command: | @@ -620,14 +634,13 @@ jobs: name: Start daemon services command: | make init_test - cp ./localchain_contract_addresses.env ./priv/cabbage/apps/itest/localchain_contract_addresses.env + cp ./localchain_contract_addresses.env ./priv/cabbage/localchain_contract_addresses.env docker-compose -f docker-compose.yml -f docker-compose.feefeed.yml -f docker-compose.specs.yml up -d || (START_RESULT=$?; docker-compose logs; exit $START_RESULT;) - run: name: Log daemon services command: make cabbage-logs background: true - check_docker_status - - install_elixir - run: sh .circleci/status.sh - run: name: Run specs @@ -650,6 +663,7 @@ jobs: STATIX_TAG: "env:perf_circleci" steps: - checkout + - install_elixir - run: name: Setup data dir command: | @@ -659,7 +673,6 @@ jobs: - run: name: Build perf docker image command: make docker-perf IMAGE_NAME=$PERF_IMAGE_NAME - - install_elixir - run: name: Start daemon services command: | @@ -717,6 +730,7 @@ jobs: REORG: true steps: - checkout + - install_elixir - run: name: "Pull Submodules" command: | @@ -734,14 +748,13 @@ jobs: name: Start daemon services command: | make init_test_reorg - cp ./localchain_contract_addresses.env ./priv/cabbage/apps/itest/localchain_contract_addresses.env + cp ./localchain_contract_addresses.env ./priv/cabbage/localchain_contract_addresses.env docker-compose -f docker-compose.yml -f docker-compose.feefeed.yml -f docker-compose.reorg.yml -f docker-compose.specs.yml up -d || (START_RESULT=$?; docker-compose logs; exit $START_RESULT;) - run: name: Log daemon services command: make cabbage-logs-reorg background: true - check_docker_status - - install_elixir - run: sh .circleci/status.sh - run: name: Print watcher logs @@ -780,6 +793,7 @@ jobs: TERM: xterm-256color steps: - checkout + - install_elixir - run: name: "Pull Submodules" command: | @@ -792,7 +806,6 @@ jobs: command: make start-services background: true - run: echo 'export PATH=~/.cargo/bin:$PATH' >> $BASH_ENV - - install_elixir - install_deps - run: make install-hex-rebar - restore_cache: diff --git a/Makefile b/Makefile index 425cb6aa93..6d558ba133 100644 --- a/Makefile +++ b/Makefile @@ -190,19 +190,22 @@ init-contracts: clean-contracts cd data && \ tar --strip-components 1 -zxvf snapshot.tar.gz data/geth && \ tar --exclude=data/* -xvzf snapshot.tar.gz && \ - AUTHORITY_ADDRESS=$$(cat plasma-contracts/build/authority_address) && \ - ETH_VAULT=$$(cat plasma-contracts/build/eth_vault) && \ - ERC20_VAULT=$$(cat plasma-contracts/build/erc20_vault) && \ - PAYMENT_EXIT_GAME=$$(cat plasma-contracts/build/payment_exit_game) && \ - PLASMA_FRAMEWORK_TX_HASH=$$(cat plasma-contracts/build/plasma_framework_tx_hash) && \ - PLASMA_FRAMEWORK=$$(cat plasma-contracts/build/plasma_framework) && \ - PAYMENT_EIP712_LIBMOCK=$$(cat plasma-contracts/build/paymentEip712LibMock) && \ - MERKLE_WRAPPER=$$(cat plasma-contracts/build/merkleWrapper) && \ - ERC20_MINTABLE=$$(cat plasma-contracts/build/erc20Mintable) && \ - sh ../bin/generate-localchain-env AUTHORITY_ADDRESS=$$AUTHORITY_ADDRESS ETH_VAULT=$$ETH_VAULT \ + AUTHORITY_ADDRESS=$$(cat plasma-contracts/build/authority_address) \ + ETH_VAULT=$$(cat plasma-contracts/build/eth_vault) \ + ERC20_VAULT=$$(cat plasma-contracts/build/erc20_vault) \ + PAYMENT_EXIT_GAME=$$(cat plasma-contracts/build/payment_exit_game) \ + PLASMA_FRAMEWORK_TX_HASH=$$(cat plasma-contracts/build/plasma_framework_tx_hash) \ + PLASMA_FRAMEWORK=$$(cat plasma-contracts/build/plasma_framework) \ + PAYMENT_EIP712_LIBMOCK=$$(cat plasma-contracts/build/paymentEip712LibMock) \ + MERKLE_WRAPPER=$$(cat plasma-contracts/build/merkleWrapper) \ + ERC20_MINTABLE=$$(cat plasma-contracts/build/erc20Mintable) \ ERC20_VAULT=$$ERC20_VAULT PAYMENT_EXIT_GAME=$$PAYMENT_EXIT_GAME \ PLASMA_FRAMEWORK_TX_HASH=$$PLASMA_FRAMEWORK_TX_HASH PLASMA_FRAMEWORK=$$PLASMA_FRAMEWORK \ - PAYMENT_EIP712_LIBMOCK=$$PAYMENT_EIP712_LIBMOCK MERKLE_WRAPPER=$$MERKLE_WRAPPER ERC20_MINTABLE=$$ERC20_MINTABLE + PAYMENT_EIP712_LIBMOCK=$$PAYMENT_EIP712_LIBMOCK MERKLE_WRAPPER=$$MERKLE_WRAPPER ERC20_MINTABLE=$$ERC20_MINTABLE \ + sh ../bin/generate-localchain-env && \ + cd ../bin/eip55_normalizer && \ + mix deps.get && mix run -e "Eip55Normalizer.run()" ../../localchain_contract_addresses.env + init-contracts-reorg: clean-contracts mkdir data1/ || true && \ diff --git a/apps/omg/lib/omg/state/core.ex b/apps/omg/lib/omg/state/core.ex index ad6d169add..48fca22358 100644 --- a/apps/omg/lib/omg/state/core.ex +++ b/apps/omg/lib/omg/state/core.ex @@ -291,20 +291,16 @@ defmodule OMG.State.Core do def extract_exiting_utxo_positions([%{utxo_pos: _} | _] = utxo_position_events, state), do: utxo_position_events |> Enum.map(& &1.utxo_pos) |> extract_exiting_utxo_positions(state) - # list of full exit events (from ethereum listeners) - def extract_exiting_utxo_positions([%{call_data: %{utxo_pos: _}} | _] = utxo_position_events, state), - do: utxo_position_events |> Enum.map(& &1.call_data) |> extract_exiting_utxo_positions(state) - # list of utxo positions (encoded) def extract_exiting_utxo_positions([encoded_utxo_pos | _] = encoded_utxo_positions, %Core{}) when is_integer(encoded_utxo_pos), do: Enum.map(encoded_utxo_positions, &Utxo.Position.decode!/1) # list of IFE input/output piggybacked events - def extract_exiting_utxo_positions([%{call_data: %{in_flight_tx: _}} | _] = start_ife_events, %Core{}) do + def extract_exiting_utxo_positions([%{in_flight_tx: _} | _] = start_ife_events, %Core{}) do _ = Logger.info("Recognized exits from IFE starts #{inspect(start_ife_events)}") - Enum.flat_map(start_ife_events, fn %{call_data: %{in_flight_tx: tx_bytes}} -> + Enum.flat_map(start_ife_events, fn %{in_flight_tx: tx_bytes} -> {:ok, tx} = Transaction.decode(tx_bytes) Transaction.get_inputs(tx) end) diff --git a/apps/omg/lib/omg/typed_data_hash/config.ex b/apps/omg/lib/omg/typed_data_hash/config.ex index 80da07a661..bc3037dfdc 100644 --- a/apps/omg/lib/omg/typed_data_hash/config.ex +++ b/apps/omg/lib/omg/typed_data_hash/config.ex @@ -29,7 +29,9 @@ defmodule OMG.TypedDataHash.Config do @spec domain_data_from_config() :: Tools.eip712_domain_t() def domain_data_from_config() do verifying_contract_addr = - Application.get_env(:omg_eth, :contract_addr) |> Access.get(:plasma_framework) |> Encoding.from_hex() + Application.get_env(:omg_eth, :contract_addr) + |> Access.get(:plasma_framework) + |> Encoding.from_hex(:mixed) Application.fetch_env!(:omg, :eip_712_domain) |> Map.new() diff --git a/apps/omg/mix.exs b/apps/omg/mix.exs index 8848c43224..744ab8b203 100644 --- a/apps/omg/mix.exs +++ b/apps/omg/mix.exs @@ -36,6 +36,7 @@ defmodule OMG.MixProject do {:ex_rlp, "~> 0.5.3"}, {:merkle_tree, "~> 2.0.0"}, {:telemetry, "~> 0.4.1"}, + {:eip_55, "~> 0.1"}, # UMBRELLA {:omg_bus, in_umbrella: true}, {:omg_db, in_umbrella: true}, diff --git a/apps/omg/test/omg/state/core_test.exs b/apps/omg/test/omg/state/core_test.exs index a3ba5cecb4..68bc83077a 100644 --- a/apps/omg/test/omg/state/core_test.exs +++ b/apps/omg/test/omg/state/core_test.exs @@ -615,7 +615,7 @@ defmodule OMG.State.CoreTest do assert utxo_pos_exits == utxo_pos_exits - |> Enum.map(&%{call_data: %{utxo_pos: Utxo.Position.encode(&1)}}) + |> Enum.map(&%{utxo_pos: Utxo.Position.encode(&1)}) |> Core.extract_exiting_utxo_positions(state_empty) assert utxo_pos_exits == @@ -695,7 +695,7 @@ defmodule OMG.State.CoreTest do state = state |> Core.exec(tx, @fee) |> success? - utxo_pos_exits_in_flight = [%{call_data: %{in_flight_tx: Transaction.raw_txbytes(tx)}}] + utxo_pos_exits_in_flight = [%{in_flight_tx: Transaction.raw_txbytes(tx)}] utxo_pos_exits_piggyback = [ %{tx_hash: Transaction.raw_txhash(tx), output_index: 0, omg_data: %{piggyback_type: :output}} @@ -731,7 +731,7 @@ defmodule OMG.State.CoreTest do tx = create_recovered([{@blknum1, 0, 0, alice}], @eth, [{alice, 2}, {alice, 3}]) - utxo_pos_exits_in_flight = [%{call_data: %{in_flight_tx: Transaction.raw_txbytes(tx)}}] + utxo_pos_exits_in_flight = [%{in_flight_tx: Transaction.raw_txbytes(tx)}] expected_position = Utxo.position(@blknum1, 0, 0) exiting_utxos = Core.extract_exiting_utxo_positions(utxo_pos_exits_in_flight, state) diff --git a/apps/omg/test/omg/state/transaction/fee_test.exs b/apps/omg/test/omg/state/transaction/fee_test.exs index cfea93720e..41754b1cfc 100644 --- a/apps/omg/test/omg/state/transaction/fee_test.exs +++ b/apps/omg/test/omg/state/transaction/fee_test.exs @@ -18,7 +18,6 @@ defmodule OMG.State.Transaction.FeeTest do use ExUnitFixtures use ExUnit.Case, async: true - alias OMG.Output alias OMG.State.Transaction @eth OMG.Eth.zero_address() diff --git a/apps/omg/test/support/integration/deposit_helper.ex b/apps/omg/test/support/integration/deposit_helper.ex index 3b362d835a..26d31f34f4 100644 --- a/apps/omg/test/support/integration/deposit_helper.ex +++ b/apps/omg/test/support/integration/deposit_helper.ex @@ -39,7 +39,7 @@ defmodule Support.Integration.DepositHelper do end def deposit_to_child_chain(to, value, token_addr) when is_binary(token_addr) and byte_size(token_addr) == 20 do - contract_addr = Encoding.from_hex(Configuration.contracts().erc20_vault) + contract_addr = Encoding.from_hex(Configuration.contracts().erc20_vault, :mixed) {:ok, _} = Eth.Token.approve(to, contract_addr, value, token_addr) |> DevHelper.transact_sync!() diff --git a/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_property_test.exs b/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_property_test.exs index 5585671389..fee51e32cf 100644 --- a/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_property_test.exs +++ b/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_property_test.exs @@ -38,7 +38,7 @@ defmodule OMG.Conformance.MerkleProofPropertyTest do on_exit(exit_fn) - [contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex)] + [contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex, :mixed)] end property "any root hash and proof created by the Elixir implementation validates in the contract, for all leaves", diff --git a/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_test.exs b/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_test.exs index d6e2433f8f..74992dd778 100644 --- a/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_test.exs +++ b/apps/omg_conformance/test/omg_conformance/conformance/merkle_proof_test.exs @@ -39,7 +39,7 @@ defmodule OMG.Conformance.MerkleProofTest do on_exit(exit_fn) - [contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex)] + [contract: OMG.Eth.Encoding.from_hex(merkle_wrapper_address_hex, :mixed)] end test "a simple, 3-leaf merkle proof validates fine", %{contract: contract} do diff --git a/apps/omg_conformance/test/support/conformance/signatures_hashes_case.ex b/apps/omg_conformance/test/support/conformance/signatures_hashes_case.ex index 104a86c1df..548a9ee999 100644 --- a/apps/omg_conformance/test/support/conformance/signatures_hashes_case.ex +++ b/apps/omg_conformance/test/support/conformance/signatures_hashes_case.ex @@ -44,6 +44,6 @@ defmodule Support.Conformance.SignaturesHashesCase do exit_fn.() end) - [contract: OMG.Eth.Encoding.from_hex(signtest_addr_hex)] + [contract: OMG.Eth.Encoding.from_hex(signtest_addr_hex, :mixed)] end end diff --git a/apps/omg_eth/lib/eth.ex b/apps/omg_eth/lib/eth.ex index 2c9e87f006..d754fb0110 100644 --- a/apps/omg_eth/lib/eth.ex +++ b/apps/omg_eth/lib/eth.ex @@ -32,7 +32,7 @@ defmodule OMG.Eth do alias OMG.Eth.RootChain.SubmitBlock require Logger - import OMG.Eth.Encoding, only: [from_hex: 1, to_hex: 1, int_from_hex: 1] + import OMG.Eth.Encoding, only: [from_hex: 2, to_hex: 1, int_from_hex: 1] @type address :: <<_::160>> @type hash :: <<_::256>> @@ -58,8 +58,8 @@ defmodule OMG.Eth do @spec submit_block(binary(), pos_integer(), pos_integer()) :: {:error, binary() | atom() | map()} | {:ok, <<_::256>>} def submit_block(hash, nonce, gas_price) do - contract = from_hex(Configuration.contracts().plasma_framework) - from = from_hex(Configuration.authority_address()) + contract = from_hex(Configuration.contracts().plasma_framework, :mixed) + from = from_hex(Configuration.authority_address(), :mixed) backend = Configuration.eth_node() SubmitBlock.submit(backend, hash, nonce, gas_price, from, contract) end diff --git a/apps/omg_eth/lib/omg_eth/encoding.ex b/apps/omg_eth/lib/omg_eth/encoding.ex index 5a07c2ebcd..71b34d1e1a 100644 --- a/apps/omg_eth/lib/omg_eth/encoding.ex +++ b/apps/omg_eth/lib/omg_eth/encoding.ex @@ -39,8 +39,8 @@ defmodule OMG.Eth.Encoding do """ # because https://github.com/rrrene/credo/issues/583, we need to: # credo:disable-for-next-line Credo.Check.Consistency.SpaceAroundOperators - @spec from_hex(<<_::16, _::_*8>>) :: binary - def from_hex("0x" <> encoded), do: Base.decode16!(encoded, case: :lower) + @spec from_hex(<<_::16, _::_*8>>, atom()) :: binary + def from_hex("0x" <> encoded, format \\ :lower), do: Base.decode16!(encoded, case: format) @doc """ Decodes to an integer, see `to_hex` diff --git a/apps/omg_eth/lib/omg_eth/release_tasks/set_contract.ex b/apps/omg_eth/lib/omg_eth/release_tasks/set_contract.ex index 62d497f0f5..6ec2d380bb 100644 --- a/apps/omg_eth/lib/omg_eth/release_tasks/set_contract.ex +++ b/apps/omg_eth/lib/omg_eth/release_tasks/set_contract.ex @@ -120,12 +120,18 @@ defmodule OMG.Eth.ReleaseTasks.SetContract do when is_binary(txhash_contract) and is_binary(authority_address) and is_map(contract_addresses) and is_integer(min_exit_period_seconds) and is_binary(contract_semver) and is_binary(network) do - contract_addresses = Enum.into(contract_addresses, %{}, fn {name, addr} -> {name, String.downcase(addr)} end) + contract_addresses = + Enum.into(contract_addresses, %{}, fn {name, addr} -> + value = encode_eip55(addr) + {name, value} + end) + + authority_address_formatted = encode_eip55(authority_address) Config.Reader.merge(config, omg_eth: [ - txhash_contract: String.downcase(txhash_contract), - authority_address: String.downcase(authority_address), + txhash_contract: txhash_contract, + authority_address: authority_address_formatted, contract_addr: contract_addresses, min_exit_period_seconds: min_exit_period_seconds, contract_semver: contract_semver, @@ -210,4 +216,15 @@ defmodule OMG.Eth.ReleaseTasks.SetContract do {:ok, _} = Application.ensure_all_started(:logger) {:ok, _} = Application.ensure_all_started(:ethereumex) end + + defp encode_eip55(value) do + case value do + "" -> + "" + + other -> + {:ok, address} = EIP55.encode(other) + address + end + end end diff --git a/apps/omg_eth/lib/omg_eth/root_chain.ex b/apps/omg_eth/lib/omg_eth/root_chain.ex index f47928da75..af3297b59b 100644 --- a/apps/omg_eth/lib/omg_eth/root_chain.ex +++ b/apps/omg_eth/lib/omg_eth/root_chain.ex @@ -22,7 +22,7 @@ defmodule OMG.Eth.RootChain do """ require Logger - import OMG.Eth.Encoding, only: [from_hex: 1, int_from_hex: 1] + import OMG.Eth.Encoding, only: [from_hex: 2, int_from_hex: 1] alias OMG.Eth alias OMG.Eth.Configuration @@ -56,7 +56,7 @@ defmodule OMG.Eth.RootChain do Returns lists of block submissions from Ethereum logs """ def get_block_submitted_events(from_height, to_height) do - contract = from_hex(Configuration.contracts().plasma_framework) + contract = from_hex(Configuration.contracts().plasma_framework, :mixed) signature = "BlockSubmitted(uint256)" {:ok, logs} = Rpc.get_ethereum_events(from_height, to_height, signature, contract) @@ -98,7 +98,7 @@ defmodule OMG.Eth.RootChain do @spec get_root_deployment_height() :: {:ok, integer()} | Ethereumex.HttpClient.error() def get_root_deployment_height() do - plasma_framework = Configuration.contracts().plasma_framework + plasma_framework = String.downcase(Configuration.contracts().plasma_framework) txhash = Configuration.txhash_contract() case Ethereumex.HttpClient.eth_get_transaction_receipt(txhash) do diff --git a/apps/omg_eth/test/fixtures.exs b/apps/omg_eth/test/fixtures.exs index ed0019f39b..3a52862a5d 100644 --- a/apps/omg_eth/test/fixtures.exs +++ b/apps/omg_eth/test/fixtures.exs @@ -72,7 +72,7 @@ defmodule OMG.Eth.Fixtures do defp has_exit_queue(vault_id, token) do plasma_framework = Configuration.contracts().plasma_framework - token = Encoding.from_hex(token) + token = Encoding.from_hex(token, :mixed) call_contract(plasma_framework, "hasExitQueue(uint256,address)", [vault_id, token], [:bool]) end diff --git a/apps/omg_eth/test/omg_eth/eth_test.exs b/apps/omg_eth/test/omg_eth/eth_test.exs index 4d19b3efa9..f1fbc1da2a 100644 --- a/apps/omg_eth/test/omg_eth/eth_test.exs +++ b/apps/omg_eth/test/omg_eth/eth_test.exs @@ -43,7 +43,7 @@ defmodule OMG.EthTest do end test "submit_block/1 submits a block to the contract" do - response = Eth.submit_block(<<234::256>>, 1, 20_000_000_000) + response = Eth.submit_block(<<234::256>>, 0, 20_000_000_000) assert {:ok, _} = DevHelper.transact_sync!(response) end diff --git a/apps/omg_eth/test/omg_eth/release_tasks/set_contract_test.exs b/apps/omg_eth/test/omg_eth/release_tasks/set_contract_test.exs index 9919d7f260..1e728d3232 100644 --- a/apps/omg_eth/test/omg_eth/release_tasks/set_contract_test.exs +++ b/apps/omg_eth/test/omg_eth/release_tasks/set_contract_test.exs @@ -52,7 +52,7 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do :ok = System.put_env("ETHEREUM_NETWORK", "RINKEBY") config = SetContract.load([], rpc_api: __MODULE__.Rpc) authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) - assert authority_address == "authority_address_value" + assert authority_address == "0x4e3Aeff70F022A6d4CC5947423887E7152826Cf9" plasma_framework = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:contract_addr) |> Map.get(:plasma_framework) assert plasma_framework == contract_addresses_value.plasma_framework @@ -86,13 +86,15 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do plasma_framework: plasma_framework, contract_addresses_value: contract_addresses_value } do + authority_address = "0x4e3aeff70f022a6d4cc5947423887e7152826cf7" :ok = System.put_env("ETHEREUM_NETWORK", "rinkeby") :ok = System.put_env("TXHASH_CONTRACT", "txhash_contract_value") - :ok = System.put_env("AUTHORITY_ADDRESS", "authority_address_value") + :ok = System.put_env("AUTHORITY_ADDRESS", authority_address) :ok = System.put_env("CONTRACT_ADDRESS_PLASMA_FRAMEWORK", plasma_framework) config = SetContract.load([], rpc_api: __MODULE__.Rpc) - authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) - assert authority_address == "authority_address_value" + found_authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) + {:ok, eip55_address} = EIP55.encode(authority_address) + assert found_authority_address == eip55_address plasma_framework = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:contract_addr) |> Map.get(:plasma_framework) assert plasma_framework == contract_addresses_value.plasma_framework @@ -105,34 +107,38 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do plasma_framework: plasma_framework, contract_addresses_value: contract_addresses_value } do + authority_address = "0x4e3aeff70f022a6d4cc5947423887e7152826cf8" :ok = System.put_env("ETHEREUM_NETWORK", "rinkeby") :ok = System.put_env("TXHASH_CONTRACT", "Txhash_contract_value") - :ok = System.put_env("AUTHORITY_ADDRESS", "Authority_address_value") + :ok = System.put_env("AUTHORITY_ADDRESS", authority_address) :ok = System.put_env("CONTRACT_ADDRESS_PLASMA_FRAMEWORK", plasma_framework) config = SetContract.load([], rpc_api: __MODULE__.Rpc) - authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) - assert authority_address == "authority_address_value" + found_authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) + {:ok, eip55_address} = EIP55.encode(authority_address) + assert found_authority_address == eip55_address plasma_framework = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:contract_addr) |> Map.get(:plasma_framework) assert plasma_framework == contract_addresses_value.plasma_framework txhash_contract_value = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:txhash_contract) - assert txhash_contract_value == "txhash_contract_value" + assert txhash_contract_value == "Txhash_contract_value" end test "contract details from env for localchain", %{ plasma_framework: plasma_framework, contract_addresses_value: contract_addresses_value } do + authority_address = "0x4e3aeff70f022a6d4cc5947423887e7152826cf9" :ok = System.put_env("ETHEREUM_NETWORK", "localchain") :ok = System.put_env("TXHASH_CONTRACT", "txhash_contract_value") - :ok = System.put_env("AUTHORITY_ADDRESS", "authority_address_value") + :ok = System.put_env("AUTHORITY_ADDRESS", authority_address) :ok = System.put_env("CONTRACT_ADDRESS_PLASMA_FRAMEWORK", plasma_framework) config = SetContract.load([], rpc_api: __MODULE__.Rpc) - authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) - assert authority_address == "authority_address_value" + found_authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) + {:ok, eip55_address} = EIP55.encode(authority_address) + assert found_authority_address == eip55_address plasma_framework = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:contract_addr) |> Map.get(:plasma_framework) assert plasma_framework == contract_addresses_value.plasma_framework @@ -146,7 +152,7 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do } do :ok = System.put_env("ETHEREUM_NETWORK", "rinkeby") :ok = System.put_env("TXHASH_CONTRACT", "txhash_contract_value") - :ok = System.put_env("AUTHORITY_ADDRESS", "authority_address_value") + :ok = System.put_env("AUTHORITY_ADDRESS", "0x4e3aeff70f022a6d4cc5947423887e7152826cf1") :ok = System.put_env("CONTRACT_ADDRESS_PLASMA_FRAMEWORK", plasma_framework) config = SetContract.load([], rpc_api: __MODULE__.Rpc) @@ -158,17 +164,19 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do plasma_framework: plasma_framework, contract_addresses_value: contract_addresses_value } do + authority_address = "0x4e3aeff70f022a6d4cc5947423887e7152826cf5" :ok = System.put_env("ETHEREUM_NETWORK", "rinkeby") :ok = System.put_env("TXHASH_CONTRACT", "txhash_contract_value") - :ok = System.put_env("AUTHORITY_ADDRESS", "authority_address_value") + :ok = System.put_env("AUTHORITY_ADDRESS", authority_address) :ok = System.put_env("CONTRACT_ADDRESS_PLASMA_FRAMEWORK", plasma_framework) config = SetContract.load([], rpc_api: __MODULE__.Rpc) min_exit_period_seconds = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:min_exit_period_seconds) assert min_exit_period_seconds == 20 - authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) - assert authority_address == "authority_address_value" + found_authority_address = config |> Keyword.fetch!(:omg_eth) |> Keyword.fetch!(:authority_address) + {:ok, eip55_address} = EIP55.encode(authority_address) + assert found_authority_address == eip55_address plasma_framework = config |> Keyword.get(:omg_eth) |> Keyword.fetch!(:contract_addr) |> Map.get(:plasma_framework) assert plasma_framework == contract_addresses_value.plasma_framework @@ -222,10 +230,12 @@ defmodule OMG.Eth.ReleaseTasks.SetContractTest do defp handle(conn) do plasma_framework = Support.SnapshotContracts.parse_contracts()["CONTRACT_ADDRESS_PLASMA_FRAMEWORK"] + {:ok, authority_address} = EIP55.encode("0x4e3aeff70f022a6d4cc5947423887e7152826cf9") + exchanger_body = %{ plasma_framework_tx_hash: "txhash_contract_value", plasma_framework: nil, - authority_address: "authority_address_value" + authority_address: authority_address } body = exchanger_body |> Map.put(:plasma_framework, plasma_framework) |> Jason.encode!() diff --git a/apps/omg_eth/test/omg_eth/root_chain/event_test.exs b/apps/omg_eth/test/omg_eth/root_chain/event_test.exs index 295426408b..04897191af 100644 --- a/apps/omg_eth/test/omg_eth/root_chain/event_test.exs +++ b/apps/omg_eth/test/omg_eth/root_chain/event_test.exs @@ -23,7 +23,7 @@ defmodule OMG.RootChain.EventTest do assert Event.get_events([:deposit_created, :in_flight_exit_challenged, :in_flight_exit_started]) == [ "DepositCreated(address,uint256,address,uint256)", "InFlightExitChallenged(address,bytes32,uint256)", - "InFlightExitStarted(address,bytes32)" + "InFlightExitStarted(address,bytes32,bytes,uint256[],bytes[])" ] end end diff --git a/apps/omg_eth/test/omg_eth/root_chain_test.exs b/apps/omg_eth/test/omg_eth/root_chain_test.exs index 63f94a4fc8..6d8910d772 100644 --- a/apps/omg_eth/test/omg_eth/root_chain_test.exs +++ b/apps/omg_eth/test/omg_eth/root_chain_test.exs @@ -62,7 +62,7 @@ defmodule OMG.Eth.RootChainTest do end defp deposit_then_start_exit(owner, amount, currency) do - owner = Encoding.from_hex(owner) + owner = Encoding.from_hex(owner, :mixed) {:ok, deposit} = ExPlasma.Transaction.Deposit.new(owner: owner, currency: currency, amount: amount) rlp = ExPlasma.Transaction.encode(deposit) diff --git a/apps/omg_eth/test/support/root_chain_helper.ex b/apps/omg_eth/test/support/root_chain_helper.ex index a9e3a1a0ab..d7c3d8417c 100644 --- a/apps/omg_eth/test/support/root_chain_helper.ex +++ b/apps/omg_eth/test/support/root_chain_helper.ex @@ -16,7 +16,7 @@ defmodule Support.RootChainHelper do @moduledoc """ Helper functions for RootChain. """ - import OMG.Eth.Encoding, only: [to_hex: 1, from_hex: 1] + import OMG.Eth.Encoding, only: [to_hex: 1, from_hex: 2] alias OMG.Eth.Blockchain.BitHelper alias OMG.Eth.Configuration @@ -50,7 +50,7 @@ defmodule Support.RootChainHelper do |> Keyword.put(:gas, @gas_start_exit) |> Keyword.put(:value, @standard_exit_bond) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) backend = :geth TransactionHelper.contract_transact( @@ -69,7 +69,7 @@ defmodule Support.RootChainHelper do |> Keyword.put(:gas, @gas_piggyback) |> Keyword.put(:value, @piggyback_bond) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "piggybackInFlightExitOnInput((bytes,uint16))" args = [{in_flight_tx, input_index}] backend = Configuration.eth_node() @@ -83,7 +83,7 @@ defmodule Support.RootChainHelper do |> Keyword.put(:gas, @gas_piggyback) |> Keyword.put(:value, @piggyback_bond) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "piggybackInFlightExitOnOutput((bytes,uint16))" args = [{in_flight_tx, output_index}] @@ -100,14 +100,14 @@ defmodule Support.RootChainHelper do |> Keyword.merge(opts) |> Keyword.put(:value, value) - contract = from_hex(Configuration.contracts().eth_vault) + contract = from_hex(Configuration.contracts().eth_vault, :mixed) backend = Configuration.eth_node() TransactionHelper.contract_transact(backend, from, contract, "deposit(bytes)", [tx_bytes], opts) end def deposit_from(tx, from) do opts = Keyword.put(@tx_defaults, :gas, @gas_deposit_from) - contract = from_hex(Configuration.contracts().erc20_vault) + contract = from_hex(Configuration.contracts().erc20_vault, :mixed) backend = Configuration.eth_node() TransactionHelper.contract_transact(backend, from, contract, "deposit(bytes)", [tx], opts) end @@ -115,14 +115,14 @@ defmodule Support.RootChainHelper do def add_exit_queue(vault_id, token) do opts = Keyword.put(@tx_defaults, :gas, @gas_add_exit_queue) - contract = from_hex(Configuration.contracts().plasma_framework) - token = from_hex(token) + contract = from_hex(Configuration.contracts().plasma_framework, :mixed) + token = from_hex(token, :mixed) {:ok, [from | _]} = Ethereumex.HttpClient.eth_accounts() backend = Configuration.eth_node() TransactionHelper.contract_transact( backend, - from_hex(from), + from_hex(from, :mixed), contract, "addExitQueue(uint256, address)", [vault_id, token], @@ -134,7 +134,7 @@ defmodule Support.RootChainHelper do opts = Keyword.put(@tx_defaults, :gas, @gas_challenge_exit) sender_data = BitHelper.kec(from) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "challengeStandardExit((uint168,bytes,bytes,uint16,bytes,bytes32))" args = [{exit_id, exiting_tx, challenge_tx, input_index, challenge_tx_sig, sender_data}] @@ -145,7 +145,7 @@ defmodule Support.RootChainHelper do def activate_child_chain(from \\ nil) do opts = Keyword.put(@tx_defaults, :gas, @gas_init) contract = Configuration.contracts().plasma_framework - from = from || from_hex(Configuration.authority_address()) + from = from || from_hex(Configuration.authority_address(), :mixed) backend = Configuration.eth_node() TransactionHelper.contract_transact(backend, from, contract, "activateChildChain()", [], opts) @@ -164,7 +164,7 @@ defmodule Support.RootChainHelper do |> Keyword.put(:value, @ife_bond) |> Keyword.put(:gas, @gas_start_in_flight_exit) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "startInFlightExit((bytes,bytes[],uint256[],bytes[],bytes[]))" args = [{in_flight_tx, input_txs, input_utxos_pos, input_txs_inclusion_proofs, in_flight_tx_sigs}] @@ -176,8 +176,8 @@ defmodule Support.RootChainHelper do def process_exits(vault_id, token, top_exit_id, exits_to_process, from) do opts = @tx_defaults - token = from_hex(token) - contract = from_hex(Configuration.contracts().plasma_framework) + token = from_hex(token, :mixed) + contract = from_hex(Configuration.contracts().plasma_framework, :mixed) signature = "processExits(uint256,address,uint168,uint256)" args = [vault_id, token, top_exit_id, exits_to_process] backend = Configuration.eth_node() @@ -200,7 +200,7 @@ defmodule Support.RootChainHelper do ) do opts = Keyword.put(@tx_defaults, :gas, @gas_challenge_in_flight_exit_not_canonical) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "challengeInFlightExitNotCanonical((bytes,uint256,bytes,uint16,bytes,uint16,uint256,bytes,bytes))" @@ -222,7 +222,7 @@ defmodule Support.RootChainHelper do ) do opts = Keyword.put(@tx_defaults, :gas, @gas_respond_to_non_canonical_challenge) - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "respondToNonCanonicalChallenge(bytes,uint256,bytes)" args = [in_flight_tx, in_flight_tx_pos, in_flight_tx_inclusion_proof] @@ -244,7 +244,7 @@ defmodule Support.RootChainHelper do ) do opts = @tx_defaults - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "challengeInFlightExitInputSpent((bytes,uint16,bytes,uint16,bytes,bytes,uint256))" args = [ @@ -268,7 +268,7 @@ defmodule Support.RootChainHelper do from ) do opts = @tx_defaults - contract = from_hex(Configuration.contracts().payment_exit_game) + contract = from_hex(Configuration.contracts().payment_exit_game, :mixed) signature = "challengeInFlightExitOutputSpent((bytes,bytes,uint256,bytes,uint16,bytes))" args = [ diff --git a/apps/omg_utils/lib/omg_utils/http_rpc/encoding.ex b/apps/omg_utils/lib/omg_utils/http_rpc/encoding.ex index f973e986f7..27c490d02d 100644 --- a/apps/omg_utils/lib/omg_utils/http_rpc/encoding.ex +++ b/apps/omg_utils/lib/omg_utils/http_rpc/encoding.ex @@ -37,5 +37,5 @@ defmodule OMG.Utils.HttpRPC.Encoding do # credo:disable-for-next-line Credo.Check.Consistency.SpaceAroundOperators @spec from_hex!(<<_::16, _::_*8>>) :: binary - def from_hex!("0x" <> encoded), do: Base.decode16!(encoded, case: :lower) + def from_hex!("0x" <> encoded), do: Base.decode16!(encoded, case: :mixed) end diff --git a/apps/omg_watcher/lib/omg_watcher/ethereum_event_aggregator.ex b/apps/omg_watcher/lib/omg_watcher/ethereum_event_aggregator.ex index 8dbf846e65..fe42446b33 100644 --- a/apps/omg_watcher/lib/omg_watcher/ethereum_event_aggregator.ex +++ b/apps/omg_watcher/lib/omg_watcher/ethereum_event_aggregator.ex @@ -345,5 +345,5 @@ defmodule OMG.Watcher.EthereumEventAggregator do end end - defp from_hex("0x" <> encoded), do: Base.decode16!(encoded, case: :lower) + defp from_hex("0x" <> encoded), do: Base.decode16!(encoded, case: :mixed) end diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/tools.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/tools.ex index 2f1694b355..ee8a589061 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/tools.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/tools.ex @@ -144,10 +144,11 @@ defmodule OMG.Watcher.ExitProcessor.Tools do # If transaction was included in plasma block, output is created and could be spend by this event [ %{ - call_data: %{txhash: txhash, oindex: oindex}, root_chain_txhash: root_chain_txhash, log_index: log_index, - eth_height: eth_height + eth_height: eth_height, + txhash: txhash, + oindex: oindex } | bus_events ] diff --git a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex index 9397d20297..3d415b7567 100644 --- a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex +++ b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex @@ -110,10 +110,10 @@ defmodule OMG.Watcher.SyncSupervisor do ets_bucket: events_bucket(), events: [ [name: :deposit_created, enrich: false], - [name: :exit_started, enrich: true], + [name: :exit_started, enrich: false], [name: :exit_finalized, enrich: false], [name: :exit_challenged, enrich: false], - [name: :in_flight_exit_started, enrich: true], + [name: :in_flight_exit_started, enrich: false], [name: :in_flight_exit_deleted, enrich: false], [name: :in_flight_exit_input_piggybacked, enrich: false], [name: :in_flight_exit_output_piggybacked, enrich: false], diff --git a/apps/omg_watcher/test/omg_watcher/ethereum_event_aggregator_test.exs b/apps/omg_watcher/test/omg_watcher/ethereum_event_aggregator_test.exs index eedbdf7a6e..b2f8fb9212 100644 --- a/apps/omg_watcher/test/omg_watcher/ethereum_event_aggregator_test.exs +++ b/apps/omg_watcher/test/omg_watcher/ethereum_event_aggregator_test.exs @@ -28,10 +28,10 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do ets_bucket: table, events: [ [name: :deposit_created, enrich: false], - [name: :exit_started, enrich: true], + [name: :exit_started, enrich: false], [name: :in_flight_exit_input_piggybacked, enrich: false], [name: :in_flight_exit_output_piggybacked, enrich: false], - [name: :in_flight_exit_started, enrich: true], + [name: :in_flight_exit_started, enrich: false], [name: :in_flight_exit_deleted, enrich: false] ]} ) @@ -77,9 +77,9 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do enrich: false ], [ - signature: "InFlightExitStarted(address,bytes32)", + signature: "InFlightExitStarted(address,bytes32,bytes,uint256[],bytes[])", name: :in_flight_exit_started, - enrich: true + enrich: false ], [ signature: "InFlightExitOutputPiggybacked(address,bytes32,uint16)", @@ -92,9 +92,9 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do enrich: false ], [ - signature: "ExitStarted(address,uint168)", + signature: "ExitStarted(address,uint168,uint256)", name: :exit_started, - enrich: true + enrich: false ], [ signature: "DepositCreated(address,uint256,address,uint256)", @@ -109,12 +109,12 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do } do assert event_fetcher_name |> :sys.get_state() |> Map.get(:event_signatures) |> Enum.sort() == Enum.sort([ - "InFlightExitStarted(address,bytes32)", - "InFlightExitOutputPiggybacked(address,bytes32,uint16)", + "DepositCreated(address,uint256,address,uint256)", + "ExitStarted(address,uint168,uint256)", + "InFlightExitDeleted(uint160)", "InFlightExitInputPiggybacked(address,bytes32,uint16)", - "ExitStarted(address,uint168)", - "InFlightExitDeleted(uint168)", - "DepositCreated(address,uint256,address,uint256)" + "InFlightExitOutputPiggybacked(address,bytes32,uint16)", + "InFlightExitStarted(address,bytes32,bytes,uint256[],bytes[])" ]) end end @@ -259,7 +259,6 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do to_block |> exit_started_log() |> Abi.decode_log() - |> Map.put(:call_data, start_standard_exit_log() |> from_hex |> Abi.decode_function()) in_flight_exit_output_piggybacked_log = from_block |> in_flight_exit_output_piggybacked_log() |> Abi.decode_log() in_flight_exit_input_piggybacked_log = to_block |> in_flight_exit_input_piggybacked_log() |> Abi.decode_log() @@ -339,7 +338,6 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do to_block |> exit_started_log() |> Abi.decode_log() - |> Map.put(:call_data, start_standard_exit_log() |> from_hex |> Abi.decode_function()) assert EthereumEventAggregator.exit_started(event_fetcher_name, from_block, to_block) == {:ok, [exit_started_log]} @@ -492,15 +490,16 @@ defmodule OMG.Watcher.EthereumEventAggregatorTest do def exit_started_log(block_number) do %{ - :event_signature => "ExitStarted(address,uint168)", + :event_signature => "ExitStarted(address,uint168,uint256)", "address" => "0x92ce4d7773c57d96210c46a07b89acf725057f21", "blockHash" => "0x1bee6f75c74ceeb4817dc160e2fb56dd1337a9fc2980a2b013252cf1e620f246", "blockNumber" => "0x" <> Integer.to_string(block_number, 16), - "data" => "0x000000000000000000000037a26a7116a84365892bb31bea5819301a2ba85b34", + "data" => + "0x000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b", "logIndex" => "0x1", "removed" => false, "topics" => [ - "0x570921d6b65091f346909e31e89c2dfb6e742cc37e36d747be92c170d29e383e", + "0xe0ffc2e7d623cb04e12318e11dd2c9df46dbfba8ac0c429dd49885f35785cf63", "0x00000000000000000000000008858124b3b880c68b360fd319cc61da27545e9a" ], "transactionHash" => "0x4a8248b88a17b2be4c6086a1984622de1a60dda3c9dd9ece1ef97ed18efa028c", diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/tools_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/tools_test.exs index 04b9a8066b..77e50e1d31 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/tools_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/tools_test.exs @@ -126,8 +126,8 @@ defmodule OMG.Watcher.ExitProcessor.ToolsTest do # Note: Piggyback to input in log_index: 2 is ignored assert [ - %{log_index: 3, root_chain_txhash: <<13::256>>, call_data: %{txhash: ^txhash, oindex: 3}}, - %{log_index: 1, root_chain_txhash: <<11::256>>, call_data: %{txhash: ^txhash, oindex: 1}} + %{log_index: 3, root_chain_txhash: <<13::256>>, txhash: ^txhash, oindex: 3}, + %{log_index: 1, root_chain_txhash: <<11::256>>, txhash: ^txhash, oindex: 1} ] = Tools.to_bus_events_data(piggyback_events) end end diff --git a/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs b/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs index e14b4bab47..d8d1f5de89 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs @@ -63,7 +63,7 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do # checking if both machines and humans learn about the byzantine condition assert WatcherHelper.capture_log(fn -> - {:ok, _txhash} = Eth.submit_block(different_hash, 1, 20_000_000_000) + {:ok, _txhash} = Eth.submit_block(different_hash, 0, 20_000_000_000) IntegrationTest.wait_for_byzantine_events([%Event.InvalidBlock{}.name], @timeout) end) =~ inspect({:error, :incorrect_hash}) end @@ -94,7 +94,7 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do # checking if both machines and humans learn about the byzantine condition assert WatcherHelper.capture_log(fn -> - {:ok, _txhash} = Eth.submit_block(invalid_block_hash, 1, 20_000_000_000) + {:ok, _txhash} = Eth.submit_block(invalid_block_hash, 0, 20_000_000_000) IntegrationTest.wait_for_byzantine_events([%Event.InvalidBlock{}.name], @timeout) end) =~ inspect(:tx_execution) end diff --git a/apps/omg_watcher/test/support/exit_processor/test_helper.ex b/apps/omg_watcher/test/support/exit_processor/test_helper.ex index 9e3d5ad496..67c2c63185 100644 --- a/apps/omg_watcher/test/support/exit_processor/test_helper.ex +++ b/apps/omg_watcher/test/support/exit_processor/test_helper.ex @@ -41,16 +41,18 @@ defmodule OMG.Watcher.ExitProcessor.TestHelper do owner = tx |> Transaction.get_outputs() |> Enum.at(oindex) |> Map.get(:owner) eth_height = Keyword.get(opts, :eth_height, 2) exit_id = Keyword.get(opts, :exit_id, @exit_id) - call_data = %{utxo_pos: enc_pos, output_tx: txbytes} root_chain_txhash = <<1::256>> block_timestamp = :os.system_time(:second) scheduled_finalization_time = block_timestamp + 100 event = %{ + call_data: %{ + utxo_pos: enc_pos, + output_tx: txbytes + }, owner: owner, eth_height: eth_height, exit_id: exit_id, - call_data: call_data, root_chain_txhash: root_chain_txhash, block_timestamp: block_timestamp, scheduled_finalization_time: scheduled_finalization_time diff --git a/apps/omg_watcher/test/support/integration/fixtures.exs b/apps/omg_watcher/test/support/integration/fixtures.exs index 3d6dbaf853..efa5abcc31 100644 --- a/apps/omg_watcher/test/support/integration/fixtures.exs +++ b/apps/omg_watcher/test/support/integration/fixtures.exs @@ -35,7 +35,7 @@ defmodule OMG.Watcher.Integration.Fixtures do {:ok, _} = DevHelper.import_unlock_fund(alice) deposit_blknum = DepositHelper.deposit_to_child_chain(alice.addr, some_value) - token_addr = Encoding.from_hex(token_addr) + token_addr = Encoding.from_hex(token_addr, :mixed) {:ok, _} = Eth.Token.mint(alice.addr, some_value, token_addr) |> DevHelper.transact_sync!() token_deposit_blknum = DepositHelper.deposit_to_child_chain(alice.addr, some_value, token_addr) diff --git a/apps/omg_watcher_info/lib/omg_watcher_info/db/eth_event.ex b/apps/omg_watcher_info/lib/omg_watcher_info/db/eth_event.ex index 51930e1a23..7e92bd1833 100644 --- a/apps/omg_watcher_info/lib/omg_watcher_info/db/eth_event.ex +++ b/apps/omg_watcher_info/lib/omg_watcher_info/db/eth_event.ex @@ -32,7 +32,6 @@ defmodule OMG.WatcherInfo.DB.EthEvent do require Utxo @typep available_event_type_t() :: :standard_exit | :in_flight_exit - @typep output_pointer_t() :: %{utxo_pos: pos_integer()} | %{txhash: Crypto.hash_t(), oindex: non_neg_integer()} @primary_key false schema "ethevents" do @@ -170,28 +169,38 @@ defmodule OMG.WatcherInfo.DB.EthEvent do |> Paginator.set_data(paginator) end - @spec utxo_exit_from_exit_event(%{ - call_data: output_pointer_t(), - root_chain_txhash: charlist(), - log_index: non_neg_integer(), - eth_height: pos_integer() - }) :: + @spec utxo_exit_from_exit_event( + %{ + utxo_pos: non_neg_integer(), + root_chain_txhash: charlist(), + log_index: non_neg_integer(), + eth_height: pos_integer() + } + | %{ + oindex: non_neg_integer(), + txhash: binary(), + root_chain_txhash: charlist(), + log_index: non_neg_integer(), + eth_height: pos_integer() + } + ) :: %{ root_chain_txhash: binary(), log_index: non_neg_integer(), eth_height: pos_integer(), output_pointer: tuple() } - defp utxo_exit_from_exit_event(%{ - call_data: output_pointer, - root_chain_txhash: root_chain_txhash, - log_index: log_index, - eth_height: eth_height - }) do + defp utxo_exit_from_exit_event( + %{ + root_chain_txhash: root_chain_txhash, + log_index: log_index, + eth_height: eth_height + } = event + ) do %{ root_chain_txhash: root_chain_txhash, log_index: log_index, - output_pointer: transform_output_pointer(output_pointer), + output_pointer: transform_output_pointer(event), eth_height: eth_height } end diff --git a/apps/omg_watcher_info/test/omg_watcher_info/db/eth_event_test.exs b/apps/omg_watcher_info/test/omg_watcher_info/db/eth_event_test.exs index e5f29b2844..4a4e39b22d 100644 --- a/apps/omg_watcher_info/test/omg_watcher_info/db/eth_event_test.exs +++ b/apps/omg_watcher_info/test/omg_watcher_info/db/eth_event_test.exs @@ -258,7 +258,7 @@ defmodule OMG.WatcherInfo.DB.EthEventTest do DB.EthEvent.insert_exits!( [ %{ - call_data: %{utxo_pos: expected_utxo_encoded_position}, + utxo_pos: expected_utxo_encoded_position, root_chain_txhash: expected_exit_root_chain_txhash, log_index: expected_log_index, eth_height: expected_exit_eth_height @@ -291,13 +291,13 @@ defmodule OMG.WatcherInfo.DB.EthEventTest do %{ root_chain_txhash: Crypto.hash(<<1000::256>>), log_index: 1, - call_data: %{utxo_pos: Utxo.Position.encode(Utxo.position(1, 0, 0))}, + utxo_pos: Utxo.Position.encode(Utxo.position(1, 0, 0)), eth_height: 2 }, %{ root_chain_txhash: Crypto.hash(<<1000::256>>), log_index: 1, - call_data: %{utxo_pos: Utxo.Position.encode(Utxo.position(1, 0, 0))}, + utxo_pos: Utxo.Position.encode(Utxo.position(1, 0, 0)), eth_height: 2 } ] @@ -327,13 +327,13 @@ defmodule OMG.WatcherInfo.DB.EthEventTest do root_chain_txhash: expected_eth_txhash, log_index: expected_log_index, eth_height: expected_eth_height, - call_data: %{utxo_pos: Utxo.Position.encode(utxo_pos1)} + utxo_pos: Utxo.Position.encode(utxo_pos1) }, %{ root_chain_txhash: expected_eth_txhash, log_index: expected_log_index, eth_height: expected_eth_height, - call_data: %{utxo_pos: Utxo.Position.encode(utxo_pos2)} + utxo_pos: Utxo.Position.encode(utxo_pos2) } ] @@ -387,13 +387,15 @@ defmodule OMG.WatcherInfo.DB.EthEventTest do root_chain_txhash: expected_eth_txhash1, log_index: expected_log_index1, eth_height: expected_eth_height1, - call_data: %{txhash: txhash1, oindex: oindex1} + txhash: txhash1, + oindex: oindex1 }, %{ root_chain_txhash: expected_eth_txhash2, log_index: expected_log_index2, eth_height: expected_eth_height2, - call_data: %{txhash: txhash2, oindex: oindex2} + txhash: txhash2, + oindex: oindex2 } ] diff --git a/apps/omg_watcher_info/test/omg_watcher_info/exit_consumer_test.exs b/apps/omg_watcher_info/test/omg_watcher_info/exit_consumer_test.exs index 6cbc9baad5..58cf22efe1 100644 --- a/apps/omg_watcher_info/test/omg_watcher_info/exit_consumer_test.exs +++ b/apps/omg_watcher_info/test/omg_watcher_info/exit_consumer_test.exs @@ -52,8 +52,8 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do txhash = Crypto.hash(<>) event_data = [ - %{log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, call_data: %{utxo_pos: pos_1}}, - %{log_index: 1, eth_height: 1, root_chain_txhash: @root_chain_txhash1, call_data: %{txhash: txhash, oindex: 1}} + %{log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, utxo_pos: pos_1}, + %{log_index: 1, eth_height: 1, root_chain_txhash: @root_chain_txhash1, txhash: txhash, oindex: 1} ] send_events_and_wait_until_processed(event_data) @@ -68,8 +68,8 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do # Note: event data is the same for InFlightExitStarted and InFlightExitOutputWithdrawn events event_data = [ - %{log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, call_data: %{utxo_pos: pos_2}}, - %{log_index: 1, eth_height: 1, root_chain_txhash: @root_chain_txhash1, call_data: %{utxo_pos: pos_1}} + %{log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, utxo_pos: pos_2}, + %{log_index: 1, eth_height: 1, root_chain_txhash: @root_chain_txhash1, utxo_pos: pos_1} ] send_events_and_wait_until_processed(event_data) @@ -87,7 +87,8 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, - call_data: %{txhash: txhash, oindex: oindex} + txhash: txhash, + oindex: oindex } ] @@ -106,7 +107,8 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do log_index: 2, eth_height: 2, root_chain_txhash: @root_chain_txhash2, - call_data: %{txhash: txhash, oindex: oindex} + txhash: txhash, + oindex: oindex } ] @@ -130,7 +132,8 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do log_index: expected_log_index, eth_height: expected_eth_height, root_chain_txhash: expected_root_hash, - call_data: %{txhash: txhash, oindex: oindex} + txhash: txhash, + oindex: oindex } ]) @@ -149,7 +152,7 @@ defmodule OMG.WatcherInfo.ExitConsumerTest do log_index: 2, root_chain_txhash: @root_chain_txhash2, eth_height: expected_eth_height, - call_data: %{utxo_pos: Position.encode(txo_pos)} + utxo_pos: Position.encode(txo_pos) } ] diff --git a/bin/eip55_normalizer/.formatter.exs b/bin/eip55_normalizer/.formatter.exs new file mode 100644 index 0000000000..d2cda26edd --- /dev/null +++ b/bin/eip55_normalizer/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/bin/eip55_normalizer/.gitignore b/bin/eip55_normalizer/.gitignore new file mode 100644 index 0000000000..37df38b00e --- /dev/null +++ b/bin/eip55_normalizer/.gitignore @@ -0,0 +1,24 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +eip55_normalizer-*.tar + diff --git a/bin/eip55_normalizer/lib/eip55_normalizer.ex b/bin/eip55_normalizer/lib/eip55_normalizer.ex new file mode 100644 index 0000000000..6fefe77801 --- /dev/null +++ b/bin/eip55_normalizer/lib/eip55_normalizer.ex @@ -0,0 +1,68 @@ +# Copyright 2019-2020 OmiseGO Pte Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +defmodule Eip55Normalizer do + @moduledoc """ + Normalizes contract addresses. + """ + + @spec run() :: :ok | no_return + def run() do + path = + case System.argv() do + [path] -> path + _ -> raise("wrong path format") + end + + path + |> parse_env_file() + |> write_file(path) + end + + defp parse_env_file(path) do + path + |> File.read!() + |> String.split("\n", trim: true) + |> List.flatten() + |> Enum.reduce(%{}, fn line, acc -> + [key, value] = String.split(line, "=") + + new_value = + case {key, value} do + {"TXHASH_CONTRACT", value} -> + value + + {_, ""} -> + "" + + _ -> + {:ok, eip55_value} = EIP55.encode(value) + eip55_value + end + + Map.put(acc, key, new_value) + end) + end + + defp write_file(map, path) do + new_env = + map + |> Enum.map(fn {key, value} -> + key <> "=" <> value + end) + |> Enum.join("\n") + + File.write!(path, new_env) + end +end diff --git a/bin/eip55_normalizer/mix.exs b/bin/eip55_normalizer/mix.exs new file mode 100644 index 0000000000..7c6158dd29 --- /dev/null +++ b/bin/eip55_normalizer/mix.exs @@ -0,0 +1,27 @@ +defmodule Eip55Normalizer.MixProject do + use Mix.Project + + def project do + [ + app: :eip55_normalizer, + version: "0.1.0", + elixir: "~> 1.10", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + {:eip_55, "~> 0.1"} + ] + end +end diff --git a/bin/eip55_normalizer/mix.lock b/bin/eip55_normalizer/mix.lock new file mode 100644 index 0000000000..81b12e53d3 --- /dev/null +++ b/bin/eip55_normalizer/mix.lock @@ -0,0 +1,4 @@ +%{ + "eip_55": {:hex, :eip_55, "0.1.0", "ca0b4bb4276ab58787144a2f5d9d62abc58708be78b58ff51d8a9b9165088a74", [:mix], [{:ex_sha3, "~> 0.1", [hex: :ex_sha3, repo: "hexpm", optional: false]}], "hexpm", "6613ba20070ecec70e42c525151b8ac7645b0e83ea42fa47231d3b4de772d916"}, + "ex_sha3": {:hex, :ex_sha3, "0.1.1", "8972638de7ded220cb885d6a8889c0df9da0d581d25c3b1b94a85a226b6fe874", [:mix], [], "hexpm", "3c0da4d7ca4c31dd1c7c4077b394f1fe113fbcdd8ae597683896570dcdb06841"}, +} diff --git a/mix.lock b/mix.lock index 5ec3446207..2a0211326e 100644 --- a/mix.lock +++ b/mix.lock @@ -17,6 +17,7 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, "ecto": {:hex, :ecto, "3.5.5", "48219a991bb86daba6e38a1e64f8cea540cded58950ff38fbc8163e062281a07", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98dd0e5e1de7f45beca6130d13116eae675db59adfa055fb79612406acf6f6f1"}, "ecto_sql": {:hex, :ecto_sql, "3.5.3", "1964df0305538364b97cc4661a2bd2b6c89d803e66e5655e4e55ff1571943efd", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d2f53592432ce17d3978feb8f43e8dc0705e288b0890caf06d449785f018061c"}, + "eip_55": {:hex, :eip_55, "0.1.0", "ca0b4bb4276ab58787144a2f5d9d62abc58708be78b58ff51d8a9b9165088a74", [:mix], [{:ex_sha3, "~> 0.1", [hex: :ex_sha3, repo: "hexpm", optional: false]}], "hexpm", "6613ba20070ecec70e42c525151b8ac7645b0e83ea42fa47231d3b4de772d916"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "erlexec": {:hex, :erlexec, "1.17.6", "467b5f883d32438644f155800c57d09b7cfa4ac4f4c485035915a5fa63d815de", [:rebar3], [], "hexpm", "7b8f0e37079c0c97ddf909ba43153afbb44b390f96893b1f94fe69e03939e13b"}, "ethereumex": {:hex, :ethereumex, "0.6.4", "58e998acb13b45a2b76b954b1d503f2f5f0e8118c0a14769c59264ef3ee4c301", [:mix], [{:httpoison, "~> 1.6", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "abc0bed1ba691645700f55bc843be7d08a23284e20ad889cabe6279e13debb32"}, @@ -25,6 +26,7 @@ "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"}, "ex_plasma": {:git, "https://github.com/omgnetwork/ex_plasma.git", "bd42028341d9232e11a084dbc5adac08c8bf5672", [ref: "bd42028341d9232e11a084dbc5adac08c8bf5672"]}, "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, + "ex_sha3": {:hex, :ex_sha3, "0.1.1", "8972638de7ded220cb885d6a8889c0df9da0d581d25c3b1b94a85a226b6fe874", [:mix], [], "hexpm", "3c0da4d7ca4c31dd1c7c4077b394f1fe113fbcdd8ae597683896570dcdb06841"}, "ex_unit_fixtures": {:git, "https://github.com/omisego/ex_unit_fixtures.git", "4a099c621dc70e0d65cb9619b38192e31ec5f504", [branch: "feature/require_files_not_load"]}, "excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"}, "exexec": {:hex, :exexec, "0.2.0", "a6ffc48cba3ac9420891b847e4dc7120692fb8c08c9e82220ebddc0bb8d96103", [:mix], [{:erlexec, "~> 1.10", [hex: :erlexec, repo: "hexpm", optional: false]}], "hexpm", "312cd1c9befba9e078e57f3541e4f4257eabda6eb9c348154fe899d6ac633299"}, diff --git a/priv/cabbage b/priv/cabbage index c2d4feef7a..ee6dcf38ea 160000 --- a/priv/cabbage +++ b/priv/cabbage @@ -1 +1 @@ -Subproject commit c2d4feef7adce7b08daaab76dacf69ddc5fe86f6 +Subproject commit ee6dcf38ea1a31791974b1e8cc0d97a8853f9779