Skip to content

Commit

Permalink
Merge pull request #1080 from CosmWasm/increase-MAX_LENGTH_HUMAN_ADDRESS
Browse files Browse the repository at this point in the history
Increase MAX_LENGTH_HUMAN_ADDRESS from 90 to 256
  • Loading branch information
webmaster128 authored Sep 8, 2021
2 parents ce644de + 7d6f8c2 commit c64ffdc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to

- cosmwasm-std: Make `iterator` a required feature if the `iterator` feature
flag is set (enabled by default).
- cosmwasm-vm: Increase `MAX_LENGTH_HUMAN_ADDRESS` from 90 to 256 in order to
support longer address formats than bech32.

## [0.16.2] - 2021-09-07

Expand Down
4 changes: 2 additions & 2 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl ExternalApi {
impl Api for ExternalApi {
fn addr_validate(&self, input: &str) -> StdResult<Addr> {
let input_bytes = input.as_bytes();
if input_bytes.len() > 90 {
if input_bytes.len() > 256 {
// See MAX_LENGTH_HUMAN_ADDRESS in the VM.
// In this case, the VM will refuse to read the input from the contract.
// Stop here to allow handling the error in the contract.
Expand All @@ -181,7 +181,7 @@ impl Api for ExternalApi {

fn addr_canonicalize(&self, input: &str) -> StdResult<CanonicalAddr> {
let input_bytes = input.as_bytes();
if input_bytes.len() > 90 {
if input_bytes.len() > 256 {
// See MAX_LENGTH_HUMAN_ADDRESS in the VM.
// In this case, the VM will refuse to read the input from the contract.
// Stop here to allow handling the error in the contract.
Expand Down
17 changes: 8 additions & 9 deletions packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ const MAX_LENGTH_DB_VALUE: usize = 128 * KI;
const MAX_LENGTH_CANONICAL_ADDRESS: usize = 64;
/// The max length of human address inputs (in bytes).
/// The maximum allowed size for [bech32](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32)
/// is 90 characters.
/// This value will increase with https://github.com/CosmWasm/cosmwasm/issues/1056.
const MAX_LENGTH_HUMAN_ADDRESS: usize = 90;
/// is 90 characters and we're adding some safety margin around that for other formats.
const MAX_LENGTH_HUMAN_ADDRESS: usize = 256;
const MAX_LENGTH_QUERY_CHAIN_REQUEST: usize = 64 * KI;
/// Length of a serialized Ed25519 signature
const MAX_LENGTH_ED25519_SIGNATURE: usize = 64;
Expand Down Expand Up @@ -889,7 +888,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; 333]);

leave_default_data(&env);

Expand All @@ -902,8 +901,8 @@ mod tests {
},
..
} => {
assert_eq!(length, 100);
assert_eq!(max_length, 90);
assert_eq!(length, 333);
assert_eq!(max_length, 256);
}
err => panic!("Incorrect error returned: {:?}", err),
}
Expand Down Expand Up @@ -982,7 +981,7 @@ mod tests {
let api = MockApi::default();
let (env, mut instance) = make_instance(api);

let source_ptr = write_data(&env, &[61; 100]);
let source_ptr = write_data(&env, &[61; 333]);
let dest_ptr = create_empty(&mut instance, 8);

leave_default_data(&env);
Expand All @@ -996,8 +995,8 @@ mod tests {
},
..
} => {
assert_eq!(length, 100);
assert_eq!(max_length, 90);
assert_eq!(length, 333);
assert_eq!(max_length, 256);
}
err => panic!("Incorrect error returned: {:?}", err),
}
Expand Down

0 comments on commit c64ffdc

Please sign in to comment.