-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate se challenges from ALD with elixir-omg #1005
Conversation
This still needs us to update the hashes in the Metamask compatibility test. For short term solution, would you be able to, @pnowosie? You'd probably be much faster to it than myself. Also a long-term solution to test the compatibility (if we decide to keep this ofc) could be figured out. I had a brief idea to leverage this utility from Metamask maybe? Not sure if this was considered. It would require us to loop an |
2545454
to
56dfc69
Compare
As you said long-term solution is to keep the tests outside. I discused with the omisego/omg-js and we agreed to combine tests there. (omgnetwork/omg-js#130) |
OK, so I'll just 🔪 those tests out in this PR. |
8ba06a1
to
99f89d8
Compare
@@ -124,8 +124,10 @@ defmodule OMG.State.Transaction.Payment do | |||
end | |||
|
|||
defp reconstruct_outputs(outputs_rlp) do | |||
# TODO: ugly but to be cleaned up in the abstract output PR soon, so leaving as is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taking the liberty to cut a corner here. Handling this properly requires the abstract output type refactor, otherwise it's wasted effort.
@@ -47,6 +47,7 @@ defmodule OMG.TypedDataHash do | |||
@spec hash_transaction(Transaction.Payment.t()) :: Crypto.hash_t() | |||
def hash_transaction(%Transaction.Payment{} = raw_tx) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be stupid but now that we're talking about specification docs so much. could you point me to where did you figure out that a payment transaction's hash consist of these fields? is there a doc or did you read solidity code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -22,23 +22,31 @@ defmodule OMG.TypedDataHash.Config do | |||
alias OMG.TypedDataHash.Tools | |||
|
|||
# Needed for test only to have value of address when `:contract_address` is not set | |||
@fallback_ari_network_address "0x44de0ec539b8c4a4b530c78620fe8320167f2f74" | |||
@fallback_contract_addr <<1::size(20)-unit(8)>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you help me understand why this is needed? I'm sensing there might be a better way of doing this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I scratched my head a bit here too, finding a better way. So normally we want to use the address from the config. But if it's not there (e.g. in a unit test, but not in an integration test) we want just anything.
I tried to put the fallback addr into config/test.exs
but something wasn't clicking.
I can revisit this now, having all the other stuff more or less behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I think a more proper way to do it would be by a very simple Mock, which would inject the @fallback...
address when needed, and then all the unit tests that don't have the contract_addr
configured would have to explicitly name this mock.
The non-mocked behavior would go for the value in the config.
Another option is to have contract_addr
config entry default to %{plasma_framework: 0x000000...1}
(the fallback address) in test
environment, instead of nil
, and let it be overridden in the tests that require it to be properly set.
I think I'll try the second option first actually, the mock seems like a huge gun to fire here, and it would litter all those tests with mocks, while all we want is a test-specific config value.
verify(contract, tx) | ||
end | ||
|
||
test "no outputs test", context do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this all payment transaction
type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
@@ -485,8 +485,8 @@ defmodule OMG.State.CoreTest do | |||
|
|||
# precomputed fixed hash to check compliance with hashing algo | |||
assert block_hash == | |||
<<16, 139, 87, 31, 138, 148, 220, 238, 229, 44, 183, 103, 56, 33, 63, 158, 60, 71, 34, 132, 92, 211, 169, | |||
221, 234, 110, 103, 233, 122, 84, 126, 180>> | |||
<<218, 153, 13, 247, 52, 151, 31, 191, 14, 98, 96, 181, 113, 239, 1, 101, 78, 189, 159, 121, 97, 13, 89, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what made the signature change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that's a hash and it was the addition of output_type
into the RLP encoding being the hash preimage that made it change.
@@ -56,8 +56,8 @@ defmodule OMG.State.TransactionTest do | |||
|
|||
test "raw transaction hash is invariant" do | |||
assert Transaction.raw_txhash(@transaction) == | |||
<<22, 144, 106, 111, 111, 175, 135, 22, 122, 230, 103, 220, 153, 161, 147, 239, 150, 205, 18, 226, 161, | |||
163, 127, 20, 163, 205, 24, 68, 0, 213, 103, 161>> | |||
<<32, 195, 156, 58, 16, 182, 26, 126, 67, 146, 125, 172, 69, 109, 119, 124, 233, 106, 160, 244, 41, 62, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, is that because a normal payment type transaction now consist of more fields then it did before ALD?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, same reason and more specifically: addition of output_type
field in the output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another noob question but a more fundamental one. why do we need output_type
in the output hash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because a transaction referencing different output_types
might mean a different thing and should thereby be included in the signed struct hash.
99f89d8
to
1e96167
Compare
bc4423b
to
ff52cac
Compare
|
||
test "signature test - small tx", context do | ||
contract = context[:contract] | ||
tx = TestHelper.create_signed([{1, 0, 0, @alice}], [{@alice, @eth, 100}]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way around using TestHelpers? I think they're somehow becoming a bucket for everything and make tests that should be self sufficient into a tree of jumps between modules and functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps something for a separate issue? Maybe let's propose a bunch of renames and split that particular module into submodules (entities, txs and fee-stuff separately), if it's really bugging you.
Note this PR doesn't really change the approach it just makes it consistent (use create_signed
in all cases)
|
||
assert solidity_signer == elixir_signer | ||
assert solidity_hash == OMG.TypedDataHash.hash_struct(tx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these results not predictable? why do we need an external source to verify the results in what should be a unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, given the pace at which the EIP712 changes :). Also the point of this test is to test against a particular "reference" impl, vide our discussion on Merkling elsewhere (#901).
@@ -294,7 +294,7 @@ defmodule OMG.Eth.RootChain do | |||
# TODO - missing description + could this be moved to a statefull process? | |||
@spec get_root_deployment_height(binary() | nil, optional_addr_t()) :: | |||
{:ok, integer()} | Ethereumex.HttpClient.error() | |||
def get_root_deployment_height(txhash \\ nil, contract \\ nil) do | |||
def get_root_deployment_height(txhash \\ nil, contract \\ %{}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're going down the route of replacing contracts with a map %{}
, maybe a struct would be a better representation what's being expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, let's maybe tackle separately, this is the part that's not fully fleshed out yet (contract address management), but I think pieces of the puzzle are slowly falling into their places now.
@@ -479,7 +479,7 @@ defmodule OMG.Eth.RootChain do | |||
|
|||
def decode_in_flight_exit_output_finalized(log) do | |||
non_indexed_keys = [:in_flight_exit_id, :output_index] | |||
non_indexed_key_types = [{:uint, 192}, {:uint, 8}] | |||
non_indexed_key_types = [{:uint, 160}, {:uint, 8}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where in solidity did you find the change from uint 160 to 192?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I hope I got this right, since IFEs aren't really tackled yet - separate issue).
This one I actually was just aware of (was following the debate on the topic of the change 192->160). But you can also see it in the diffs, wherever exit_id
/exitId
is mentioned.
{exiting_txbytes, _} = get_bytes_sig(exiting_tx) | ||
|
||
assert {:ok, %{exiting_tx: ^exiting_txbytes, txbytes: ^txbytes}} = | ||
%ExitProcessor.Request{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single pipe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see other comment
test "returns a deposit exiting_tx as part of the challenge response", | ||
%{alice: alice, processor_empty: processor} do | ||
exiting_tx = TestHelper.create_recovered([], [{alice, @eth, 10}]) | ||
processor = processor |> start_se_from(exiting_tx, @utxo_pos_deposit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single pipe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not in this PR. Changing this just here would make it inconsistent with the rest of the file. Changing everywhere would obscure the PR with unrelated style changes, while I want this PR to only contain the changes relevant to/required by the change it's centered around.
Among other reasons behind this approach: your ability to review.
challenge = TestHelper.get_exit_challenge(first_tx_blknum, 0, 0) | ||
|
||
assert {:ok, %{"status" => "0x1"}} = | ||
OMG.Eth.RootChainHelper.challenge_exit( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single pipe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, not in this PR. This test is the same as the test removed in the previous commit, which is the point I'm trying to make here. If it wasn't removed in the prior commit, we'd see this in the diff here (you can still see this, if you search for the right diff - against pre-ALD master
).
to squash: get rid of getting creating blocks when challenging SEs
new PaymentExitCondition contract structure + libs the `token` field has been dropped from `standardExits` call return value `challengeStandardExit` doesn't require challenge_tx_type anymore need to register the spending conditions properly
following a comment from CR
ff52cac
to
a2b7afc
Compare
…ion (#1036) * refactor: dilute Transaction.Protocol.get_effects/3 in generic code OMG.Output covers for the polymorphism now * refactor: standardize the handling of inputs don't pass around zero inputs * refactor: abstract out OMG.Output protocol and its fungible token impl * refactor: clarify and streamline the input/output parsing code * refactor: leverage OMG.Output protocol some more * style: make outputs and transactions protocols look similar * refactor: abstract out input pointer type * refactor: abstract out input_pointer/5 out for OMG.Output * refactor: abstract out the non empty checking of ins/outs * refactor: change approach to filtering out unsynced-yet exiting utxos * fix: amend some missed failing tests after the refactor * refactor: unbrittle some exit processor tests wrt Transaction inputs * fix: take care of FIXMEs * fix: update after rebase on top of ALD integration (WIP, needs cleaning) * refactor: rearrange code related to unusual requests around the UTXOSet * fix: fix SE & SE challenge integration to work with abstract outputs * fix: make peace with the dialyzer * refactor: add some improvements after experimenting with erc721 * docs: add more documentation and comments after CR * test: add low-level UtxoSet tests along with specs and clarifications * fix: update after rebasing, remove hackarounds after #1005
fixes #986, builds upon #949 (which needs to merge to wherever we opt to merge it to)
Overview
The integration test for SE challenges passes now.
Changes
Testing
among the usual tests.