-
Notifications
You must be signed in to change notification settings - Fork 10
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
add test: check if decoding is one to one by generating collisions #24
add test: check if decoding is one to one by generating collisions #24
Conversation
71a29c9
to
bc26db8
Compare
@pdobacz PR to ExRLP - can't add you as an reviewer, unfortunately. |
test/ex_rlp/property_test.exs
Outdated
|
||
forall l <- list(gen) do | ||
mapsto = for item <- :lists.usort(l), do: ExRLP.decode(item) | ||
:lists.sort(mapsto) == :lists.usort(mapsto) |
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'm not sure what this does, can you throw in some comments/expand the description of the test/make the assertion more explicit, without the use of usort
s/make variable names more readable? (ideally some mix of these 4).
I suspect that were checking that two sets are the same, but not sure how this proves the "one to one"...
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.
Done, please see again :-)
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.
On one-to-one proof. It looks for two binaries that violate one-to-one property of decoder. It is obviously not a proof since it is not exhaustive. Also it is a mapping in one direction only and no claims about the state of encoder are made in this particular 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.
perfect, thanks for dumbing it down ;). I'm wondering; how sure are we, that https://github.com/mana-ethereum/ex_rlp/pull/24/files#diff-0dbbe73b6149be5f2b00785f37f44760R27 doesn't yield a very small testing set? I'm assuming it doesn't and probably propcheck
is smart enough to not feed us duplicates, then in such case maybe let's put a sanity precondition check there, that usort==sort
(I can do it later, if I finally get to taking this over).
On one-to-one proof
ah, sorry I used "proves" too liberally, as in "attempts to prove a point/verify a property". All is understood
@paulperegud @pdobacz good catch. Currently, we don't handle errors from https://github.com/ethereum/tests/blame/develop/RLPTests/invalidRLPTest.json It'd be great if you implement it Related issue - #26 |
041a4b1
to
c0e6914
Compare
hey @pdobacz @paulperegud are we bringing this one home or was it mitigated differently? |
I'll take a stab at this (and #26) |
c0e6914
to
b91d2a8
Compare
@paulperegud hey, I rebased this on top of the #27's Now, I also added a commit, with an alternative formulation of the generator, can you take a look if this makes sense? b91d2a8
|
Two encodings that produce identical term:
<<47>>
and<<129,47>>
. This is a violation of "choose optimal length encoding" rule in from protocol description here: https://github.com/ethereum/wiki/wiki/RLPThis PR contains test detecting the error only, no fix.