-
Notifications
You must be signed in to change notification settings - Fork 353
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
mock_dependencies - creating canonical_address with long strings + alternate canonical_length #985
Comments
Hey there - I am just getting into Cosmwasm and am also new to Rust - so forgive me for the questions What do you mean by "yields different results?" And a constructor for a Terra address might be necessary |
Hey @lukerhoads no worries! By yields a different result I mean when a string, say X, is passed into addr_canonicalize it does not equal the string received when you addr_humanize the canonicalized X. You can see this in the example I posted above. The the humanized address should print “terra1qfqa2eu9wp272ha93lj4yhcenrc6ymng079nu8“ but it does not. |
Ahh wow, I can't believe I really didn't know what that meant haha. Probably got confused with the code 😩. After all, it is pretty confusing for me with all the rotating and stuff. Anyways, from what I understand, the riffle shuffle in the humanize function is causing the difference. We need to check if the canon length is the 44ish from Terra, and then perform the correct amount of riffle shuffles for both methods I think |
So looking at the riffle shuffle method, it basically splits the address and alternates appending to a new vector. So would we need to change the humanize methods riffle loop to perform it 12 times (I brute forced it, don't have the math skills yet 😇. |
Nice find. I agree it should be possible to use production-like Bech32 addresses in the testing environment. We always used very short test addresses like "alice" or "bob". I think we can avoid all the special case handling and use a |
Whoops, my b. Thanks much for clarifying. One question I still have... Is 18 riffle shuffles just a constant or would we need to change that too? Thanks |
No worries. Thise code evolved over time and had some flaws. Your request is very valid and it is a great opportunity to make everything nicer and cleaner.
The only thing that matters is that the sum of shuffles restores the original data. For 24 items (bytes) you need 20 rounds, for 44 you need 14 rounds (or 28 or any other The split 20 = 18 + 2 is arbitrary. You could as well use 17 + 3 or 10 + 10. If I recall correctly I used 18 to destroy as much structure as possible in the encoding to make the bytes look random. For the 64 bytes we can use 6 = 5 + 1 rounds. |
Sounds good, last thing though, I am probably overlooking something, but in my PR (#989) the |
And last thing haha: after unwrapping it is still not a string. This is probably where my beginner rust experience shines :/ |
Turns out the numbers on the table linked above are for out-shuffles, not in-shuffles. How the two relate is described in https://towardsdatascience.com/the-perfect-shuffle-aa388ad1ffd1. The values are plotted here: https://miro.medium.com/max/1400/1*fUwSh8bZGQd_S0KD9QGgbg.png.
So what should work is: |
Damn, this topic is deep (for me at least). Going to have to explore it sometime just for self satisfaction... When I do 10 and 2 so many errors are thrown. Probably beyond me to know why it is happening. Specifically a bunch of wasm backend and cache errors |
In #991 I prepare this change by ensuring the canonical length and the number of shuffles always work well together. |
With #991 being merged it should be easy to bump |
On it |
#995 but failing so many tests |
Done in #995 |
Hey Cosmwasm squad!
I was recently testing some stuff on 0.14 where I ran into a bug in mock_dependencies and after discussing with @orkunkl am creating an issue for it.
If you create mock_dependencies as normal create a CanonicalAddress from a string of regular Terra address length (44ish) you get a
GenericErr { msg: "Invalid input: human address too long" }'
.Example:
This could be because in MockApi addr_canonicalize contains this check:
where canonical_length is set to 24 by default.
Although frowned upon if you want to create a MockApi with an alternate canonical length instead of the default 24, canonicalizing a string and then humanizing yields different results.
Example:
The text was updated successfully, but these errors were encountered: