Skip to content
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

Canonical address length bumped to 54, max bumped to 64 #995

Merged
merged 15 commits into from
Jul 13, 2021

Conversation

lukerhoads
Copy link
Contributor

No description provided.

@lukerhoads
Copy link
Contributor Author

I do not know why it is failing so many tests :((((((

@webmaster128
Copy link
Member

I do not know why it is failing so many tests :((((((

There are multiple smaller issues, one is just formatting. Start by running the following commands locally:

./devtools/check_workspace.sh
./devtools/check_contracts_medium.sh
./devtools/test_workspace.sh

That should point you to the most obvious problems.

@webmaster128
Copy link
Member

webmaster128 commented Jul 7, 2021

In packages/vm/src/imports.rs the line

let dest_ptr = create_empty(&mut instance, 50);

creates a memory region for the human address result. This is too short now. Change the 50 to 70 to make the tests pass. This is done 4x in the same file.

@lukerhoads
Copy link
Contributor Author

Ahh it is a wasm error with windows, I tried changing CONTRACT to directly reference hackatom_0.15.wasm but it says that the target windows is not yet supported so I am going to commit your suggestions as the tests will most likely pass on circleci, lets see

@webmaster128
Copy link
Member

Ah, you are on Windows. Then this is a bit tricky. We support developing smart contracts on Windows (i.e. the guest), but not developing the cosmwas-vm (i.e. the host). This is because our Wasm backend (singlepass) does not support Windows yet.

Anyways, you can run cargo fmt directly to get rid of the formatting complains. Running it in the repo root will format the workspace. For the contracts you need to run it in ./contracts/xyz.

@lukerhoads
Copy link
Contributor Author

whoops, this time i need to look directly at circleci errors. let me fix that right now

@@ -37,7 +37,7 @@ pub fn remove_schemas(schemas_dir: &path::Path) -> Result<(), io::Error> {
#[cfg(test)]
mod tests {
use super::*;
use std::ffi::OsStr;
// use std::ffi::OsStr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? Seems unrelatet and causes compile errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was a formatting thing, my bad gonna revert that.

another question... and this is a stupid rust beginner question but since im on windows does

let source_ptr = write_data(&env, &[61; 33]);

the 33 here needs to be increased, not the 61 right? Testing locally returns the windows contract error

@lukerhoads
Copy link
Contributor Author

And let invalid_bech32 = "bn93hg934hg08q340g8u4jcau3"; this is erroring because this address is successfully canonicalized (as it is in the right range) and it expects an error. so would this have to be increased in length as well?

@lukerhoads
Copy link
Contributor Author

Ok going to fix these last few errors today

@lukerhoads
Copy link
Contributor Author

This commit still does not fix the issue in the staking module, IDK why its throwing the 'VM error: RuntimeErr { msg: "Wasmer runtime error: RuntimeError: Error in guest/host communication: Region too small. Got 32, required 54" }', /root/cosmwasm/packages/vm/src/testing/calls.rs:136:49, let me try to look into it more though I guess haha

@lukerhoads
Copy link
Contributor Author

oh darn, this attempted fix actually failed more tests 😖

@lukerhoads
Copy link
Contributor Author

having issues with wsl for testing i am a trainwreck

@lukerhoads
Copy link
Contributor Author

I am struggling with these tests :///
starts I have are

const DEFAULT_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));

this memory limit applied to a mock instance is somehow not enough for the staking contract to call with the new canonical address length?

and the other failures in the package vm are somehow related to the instantiated array

let source_ptr = write_data(&env, &[61; 33]);

which should be longer? im not good enough at rust to really understand them but I feel I was close haha
could I please get some assistance @webmaster128

sorry to bother, would really appreciate it,
thanks

@@ -1190,7 +1190,7 @@ mod tests {
let (env, mut instance) = make_instance(api);

let source_ptr = write_data(&env, &[61; 33]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let source_ptr = write_data(&env, &[61; 33]);
let source_ptr = write_data(&env, &[61; 65]);

Something like [42; 5] means an array filled with five 42s, so basically [42, 42, 42, 42, 42].

Here we're testing that we get an appropriate error if there is too much data. Since you increased the limit and length 33 is now OK, you want to change it to something that should cause an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll also want to change the assertions below (lines 1206-1207) to match the new length and max length.

@@ -994,7 +994,7 @@ mod tests {
let api = MockApi::default();
let (env, _instance) = make_instance(api);

let source_ptr = write_data(&env, &[61; 100]);
let source_ptr = write_data(&env, &[61; 33]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed? This test seemed perfectly OK before.

@@ -1087,7 +1087,7 @@ mod tests {
let api = MockApi::default();
let (env, mut instance) = make_instance(api);

let source_ptr = write_data(&env, &[61; 100]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for do_addr_validate_fails_for_large_inputs - I don't think this is what you wanted to do?

@uint
Copy link
Contributor

uint commented Jul 12, 2021

Let's figure this out! Regarding the vm, I submitted suggestions that should help fix this up.

const DEFAULT_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));

this memory limit applied to a mock instance is somehow not enough for the staking contract to call with the new canonical address length?

I don't think that's the line you want. That's the overall limit for the total size of an instance of a contract, and it should be plenty.

I think this is what you want to update:
https://github.com/CosmWasm/cosmwasm/blob/main/packages/std/src/imports.rs#L21

Looks like this is how much space will be allocated to store the canonical address, and with your changes it's too small.

@lukerhoads
Copy link
Contributor Author

Thanks so much for the patience and suggestions. I really appreciate it, probably wouldve taken me another year to figure this out.
Seeing all of the tests pass brings tear to my eyes 😂

packages/std/src/imports.rs Outdated Show resolved Hide resolved
Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, thanks. Could you just add those CHANGELOG entries to the ### Changed section of ## [Unreleased]:

- cosmwasm-std/cosmwasm-vm: Increase canonical address lengths up to 64 bytes.
- cosmwasm-std/cosmwasm-vm: In `MockApi`, increase max length of supported human
  addresses from 24 bytes to 54 bytes by using a longer canonical
  representation. This allows you to insert typical bech32 addresses in tests.
  ([#995])

[#995]: https://github.com/CosmWasm/cosmwasm/pull/995

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you!

@uint anything to add?

@uint
Copy link
Contributor

uint commented Jul 12, 2021

Looks good to me. Thank you!

@uint anything to add?

Nope, looks good! Thanks for contributing, @lukerhoads!

@webmaster128 webmaster128 merged commit bf68ab6 into CosmWasm:main Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants