Skip to content

Commit

Permalink
bump inputs/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
InoMurko committed Mar 21, 2021
1 parent cf20ff8 commit 3ecea84
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion apps/omg/lib/omg/state/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule OMG.State.Transaction do
end
end

@type input_index_t() :: 0..3
@type input_index_t() :: 0..4

def dispatching_reconstruct([raw_type | raw_tx_rlp_decoded_chunks]) when is_binary(raw_type) do
case RawData.parse_uint256(raw_type) do
Expand Down
4 changes: 2 additions & 2 deletions apps/omg/lib/omg/state/transaction/payment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ defmodule OMG.State.Transaction.Payment do

@type currency() :: Crypto.address_t()

@max_inputs 4
@max_outputs 4
@max_inputs 5
@max_outputs 5

defmacro max_inputs() do
quote do
Expand Down
4 changes: 2 additions & 2 deletions apps/omg/lib/omg/typed_data_hash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ defmodule OMG.TypedDataHash do
Computes a hash of encoded transaction as defined in EIP-712
"""
@spec hash_struct(Transaction.Payment.t(), Crypto.domain_separator_t()) :: Crypto.hash_t()
def hash_struct(%Transaction.Payment{} = raw_tx, domain_separator \\ nil) do
def hash_struct(raw_tx, domain_separator \\ nil) do
domain_separator = domain_separator || __MODULE__.Config.domain_separator_from_config()
Crypto.hash(@eip_191_prefix <> domain_separator <> hash_transaction(raw_tx))
end

@spec hash_transaction(Transaction.Payment.t()) :: Crypto.hash_t()
def hash_transaction(%Transaction.Payment{} = raw_tx) do
def hash_transaction(raw_tx) do
__MODULE__.Tools.hash_transaction(
raw_tx.tx_type,
Transaction.get_inputs(raw_tx),
Expand Down
3 changes: 1 addition & 2 deletions apps/omg/lib/omg/typed_data_hash/tools.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule OMG.TypedDataHash.Tools do
alias OMG.TypedDataHash.Types
alias OMG.Utxo

require Transaction.Payment
require Utxo

@type eip712_domain_t() :: %{
Expand Down Expand Up @@ -78,8 +79,6 @@ defmodule OMG.TypedDataHash.Tools do
Crypto.hash_t()
) :: Crypto.hash_t()
def hash_transaction(plasma_framework_tx_type, inputs, outputs, metadata, empty_input_hash, empty_output_hash) do
require Transaction.Payment

raw_encoded_tx_type = ABI.TypeEncoder.encode_raw([plasma_framework_tx_type], [{:uint, 256}])

input_hashes =
Expand Down
4 changes: 2 additions & 2 deletions apps/omg/lib/omg/typed_data_hash/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ defmodule OMG.TypedDataHash.Types do

@tx_spec Enum.concat([
[@make_spec.("txType", "uint256")],
Enum.map(0..3, fn i -> @make_spec.("input" <> Integer.to_string(i), "Input") end),
Enum.map(0..3, fn i -> @make_spec.("output" <> Integer.to_string(i), "Output") end),
Enum.map(0..4, fn i -> @make_spec.("input" <> Integer.to_string(i), "Input") end),
Enum.map(0..4, fn i -> @make_spec.("output" <> Integer.to_string(i), "Output") end),
[@make_spec.("txData", "uint256")],
[@make_spec.("metadata", "bytes32")]
])
Expand Down
2 changes: 1 addition & 1 deletion apps/omg/test/omg/state/core_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ defmodule OMG.State.CoreTest do
Logger.warn("slow test is running, use --exclude slow to skip")

maximum_block_size = 65_536
maximum_inputs_size = 4
maximum_inputs_size = 5
eth_fee_rate = Enum.at(fees[@eth], 0)
amount_for_fees = (1 + eth_fee_rate) * maximum_block_size
available_after_1st_tx = amount_for_fees - eth_fee_rate
Expand Down
4 changes: 2 additions & 2 deletions apps/omg/test/omg/state/transaction/recovered_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ defmodule OMG.State.Transaction.RecoveredTest do

assert {:error, :too_many_inputs} =
good_tx_rlp_items()
|> List.replace_at(inputs_index_in_rlp, List.duplicate(input, 5))
|> List.replace_at(inputs_index_in_rlp, List.duplicate(input, 6))
|> ExRLP.encode()
|> Transaction.Recovered.recover_from()
end
Expand Down Expand Up @@ -530,7 +530,7 @@ defmodule OMG.State.Transaction.RecoveredTest do

assert {:error, :too_many_outputs} =
good_tx_rlp_items()
|> List.replace_at(outputs_index_in_rlp, List.duplicate(output, 5))
|> List.replace_at(outputs_index_in_rlp, List.duplicate(output, 6))
|> ExRLP.encode()
|> Transaction.Recovered.recover_from()
end
Expand Down
4 changes: 2 additions & 2 deletions apps/omg/test/omg/typed_data_hash_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ defmodule OMG.TypedDataHashTest do

assert "Transaction(" <>
"uint256 txType," <>
"Input input0,Input input1,Input input2,Input input3," <>
"Output output0,Output output1,Output output2,Output output3," <>
"Input input0,Input input1,Input input2,Input input3,Input input4," <>
"Output output0,Output output1,Output output2,Output output3,Output output4," <>
"uint256 txData,bytes32 metadata)" ==
TypedDataHash.Types.encode_type(:Transaction)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ defmodule OMG.Conformance.SignatureTest do
@moduletag :integration
@moduletag :common

@good_metadata <<1::size(32)-unit(8)>>

describe "elixir vs solidity conformance test" do
test "no inputs test", %{contract: contract} do
tx = Transaction.Payment.new([], [{@alice, @eth, 100}])
Expand All @@ -43,19 +41,21 @@ defmodule OMG.Conformance.SignatureTest do
test "signature test - full tx", %{contract: contract} do
tx =
Transaction.Payment.new(
[{1, 0, 0}, {1000, 555, 3}, {2000, 333, 1}, {15_015, 0, 0}],
[{@alice, @eth, 100}, {@alice, @token, 50}, {@bob, @token, 75}, {@bob, @eth, 25}]
[{1, 0, 0}, {1000, 555, 3}, {2000, 333, 1}, {15_015, 0, 0}, {15_016, 0, 0}],
[{@alice, @eth, 100}, {@alice, @token, 50}, {@bob, @token, 75}, {@bob, @eth, 25}, {@bob, @eth, 26}]
)

verify(tx, contract)
end

test "signature test transaction with metadata", %{contract: contract} do
good_metadata = <<1::size(32)-unit(8)>>

tx =
Transaction.Payment.new(
[{1, 0, 0}, {1000, 555, 3}, {2000, 333, 1}, {15_015, 0, 0}],
[{@alice, @eth, 100}, {@alice, @eth, 50}, {@bob, @eth, 75}, {@bob, @eth, 25}],
@good_metadata
good_metadata
)

verify(tx, contract)
Expand Down
14 changes: 11 additions & 3 deletions apps/omg_conformance/test/support/conformance/signatures_hashes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ defmodule Support.Conformance.SignaturesHashes do
# revert, when using `:geth` Ethereum node. If an assertion fails with such a result, it indicates the contract
# rejected some transaction to signhash unexpectedly.
defp solidity_hash(encoded_tx, contract) when is_binary(encoded_tx) do
call_contract(contract, "hashTx(address,bytes)", [contract, encoded_tx], [{:bytes, 32}])
IO.inspect(call_contract(contract, "hashTx(address,bytes)", [contract, encoded_tx], [{:bytes, 32}]),
label: "solidity_hash"
)
end

defp elixir_hash(%{} = tx), do: OMG.TypedDataHash.hash_struct(tx)
defp elixir_hash(encoded_tx), do: encoded_tx |> Transaction.decode!() |> elixir_hash()
defp elixir_hash(%{} = tx) do
IO.inspect("yoasdf")
OMG.TypedDataHash.hash_struct(tx)
end

defp elixir_hash(encoded_tx) do
encoded_tx |> Transaction.decode!() |> elixir_hash()
end

defp assert_contract_reverted({:error, %{"message" => "execution reverted: " <> _other}}) do
:ok
Expand Down
8 changes: 4 additions & 4 deletions apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do

@type input_challenge_data :: %{
in_flight_txbytes: Transaction.tx_bytes(),
in_flight_input_index: 0..3,
in_flight_input_index: 0..4,
spending_txbytes: Transaction.tx_bytes(),
spending_input_index: 0..3,
spending_input_index: 0..4,
spending_sig: <<_::520>>,
input_tx: Transaction.tx_bytes(),
input_utxo_pos: Utxo.Position.t()
Expand All @@ -61,9 +61,9 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do
@type output_challenge_data :: %{
in_flight_txbytes: Transaction.tx_bytes(),
in_flight_output_pos: pos_integer(),
in_flight_input_index: 4..7,
in_flight_input_index: 4..8,
spending_txbytes: Transaction.tx_bytes(),
spending_input_index: 0..3,
spending_input_index: 0..4,
spending_sig: <<_::520>>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do
describe "sanity checks" do
test "throwing when unknown piggyback events arrive", %{processor_filled: processor, ife_tx_hashes: [ife_id | _]} do
non_existent_exit_id = <<0>>
index_beyond_bound = 4
index_beyond_bound = 5
catch_error(piggyback_ife_from(processor, non_existent_exit_id, 0, :input))
catch_error(piggyback_ife_from(processor, ife_id, index_beyond_bound, :output))
# cannot piggyback twice the same output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ defmodule OMG.WatcherInfo.TransactionTest do
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)

utxos_per_token = DB.TxOutput.get_sorted_grouped_utxos(@alice, :desc)

Expand Down Expand Up @@ -117,7 +119,7 @@ defmodule OMG.WatcherInfo.TransactionTest do
end

@tag fixtures: [:phoenix_ecto_sandbox]
test "returns {:ok, transactions} when 0 < inputs <= 4 and 0 < outputs <= 4" do
test "returns {:ok, transactions} when 0 < inputs <= 5 and 0 < outputs <= 5" do
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
_ = insert(:txoutput, amount: 10, currency: @eth, owner: @alice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ defmodule OMG.WatcherInfo.UtxoSelectionTest do
describe "add_utxos_for_stealth_merge/2" do
@tag fixtures: [:phoenix_ecto_sandbox]
test "returns selected UTXOs with no additions if the maximum has already been selected" do
for _i <- 1..5 do
for _i <- 1..6 do
_ = insert(:txoutput, owner: @alice)
end

Expand Down Expand Up @@ -198,7 +198,7 @@ defmodule OMG.WatcherInfo.UtxoSelectionTest do

@tag fixtures: [:phoenix_ecto_sandbox]
test "adds UTXOs until the limit is reached in the case of one currency" do
for _i <- 1..5 do
for _i <- 1..6 do
_ = insert(:txoutput, owner: @alice)
end

Expand Down
6 changes: 2 additions & 4 deletions apps/omg_watcher_rpc/lib/web/validators/typed_data_signed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ defmodule OMG.WatcherRPC.Web.Validator.TypedDataSigned do
alias OMG.Utils.HttpRPC.Validator.Base
import OMG.Utils.HttpRPC.Validator.Base

require Transaction.Payment

@doc """
Parses and validates request body for /transaction.submit_typed`
"""
Expand Down Expand Up @@ -81,8 +83,6 @@ defmodule OMG.WatcherRPC.Web.Validator.TypedDataSigned do

@spec parse_inputs(map()) :: [{integer(), integer(), integer()}] | {:error, any()}
defp parse_inputs(message) do
require Transaction.Payment

0..(Transaction.Payment.max_inputs() - 1)
|> Enum.map(fn i -> expect(message, "input#{i}", map: &parse_input/1) end)
|> Enum.reject(&empty_input?/1)
Expand All @@ -100,8 +100,6 @@ defmodule OMG.WatcherRPC.Web.Validator.TypedDataSigned do

@spec parse_outputs(map()) :: [{OMG.Crypto.address_t(), OMG.Crypto.address_t(), integer()}] | {:error, any()}
defp parse_outputs(message) do
require Transaction.Payment

0..(Transaction.Payment.max_outputs() - 1)
|> Enum.map(fn i -> expect(message, "output#{i}", map: &parse_output/1) end)
|> Enum.reject(&empty_output?/1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule OMG.WatcherRPC.Web.Validators.TypedDataSignedTest do
"name" => network,
"version" => "1",
"salt" => Encoding.to_hex(<<0::256>>),
"verifyingContract" => @ari_network_address |> Encoding.to_hex()
"verifyingContract" => Encoding.to_hex(@ari_network_address)
}
end

Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ config :omg,

config :omg, :eip_712_domain,
name: "OMG Network",
version: "1",
version: "2",
salt: "0xfad5c7f626d80f9256ef01929f3beb96e058b8b4b0e3fe52d84f054c0e2a7a83"

# Configures the endpoint
Expand Down

0 comments on commit 3ecea84

Please sign in to comment.