This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explicitly note that existing
AccountIdConversion
is truncating and add fallibletry_into...
#10719Explicitly note that existing
AccountIdConversion
is truncating and add fallibletry_into...
#10719Changes from 6 commits
da8adfb
fb51483
d84fcbc
d5f4708
bcba8e3
e8b3f01
8a48514
7c21284
a7b57c1
8342927
4c714f8
ab6e169
0caa13e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
IMO the check above is wrong, because if you for example have an enum
max_encoded_len
returns you the length of the biggest enum variant. This is wrong here, just imagine you are decoding the shortest variant and then you would not have consumed all bytes.If you want to make it correct, you need to extend
TrailingZeroInput
to be able to check if the given input was consumed completely after having the type decoded.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.
The
AccountId
type has constant length, but in general I see that it does not work for allT
.So my proposal of adding a
const_encoded_len
could also fix this, right?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.
How do you know that the
AccountId
has a constant length?AccountId
is some generic value that could be anything (one of the reasons for this pr). Just because Polkadot usesAccountId32
, it doesn't mean that everyone uses this or is required to use 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.
Yes therefore we could add a
FixEncodedLen
trait analogous toMaxEncodedLen
that requires a type to always have the same encoding len.PS: Probably still better to make it work even for non
FixEncodedLen
types 😄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.
+1 using
MaxEncodedLen
is IMO also wrong. Ideally, you just decode, and check how many bytes where actually used for decoding.Maybe one trick here could be to decode, then re-encode, and see if we go back to the same bytes. A bit hacky and also assumes reversible encode/decode.
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 did something like what @kianenigma suggested. I check the length of the bytes used for the seed, and check that the length of bytes of the account is greater or equal to, otherwise, we know some bytes were truncated.
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.
Thanks. I also tried my luck on this but could not create a test that the function actually returns
Some()
. TheAccountId
type is u64, so an overflow is very likely anyway.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.
You can just create a mock environment where account id is 32 bytes?