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
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/hackatom/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ fn do_user_errors_in_api_calls(api: &dyn Api) -> Result<Response, HackError> {
}
}

let invalid_bech32 = "bn93hg934hg08q340g8u4jcau3";
let invalid_bech32 =
"bn9hhssomeltvhzgvuqkwjkpwxojfuigltwedayzxljucefikuieillowaticksoistqoynmgcnj219a";
match api.addr_canonicalize(invalid_bech32).unwrap_err() {
StdError::GenericErr { .. } => {}
err => {
Expand Down
2 changes: 1 addition & 1 deletion packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
};

/// An upper bound for typical canonical address lengths (e.g. 20 in Cosmos SDK/Ethereum or 32 in Nano/Substrate)
const CANONICAL_ADDRESS_BUFFER_LENGTH: usize = 32;
const CANONICAL_ADDRESS_BUFFER_LENGTH: usize = 54;
webmaster128 marked this conversation as resolved.
Show resolved Hide resolved
/// An upper bound for typical human readable address formats (e.g. 42 for Ethereum hex addresses or 90 for bech32)
const HUMAN_ADDRESS_BUFFER_LENGTH: usize = 90;

Expand Down
5 changes: 3 additions & 2 deletions packages/std/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type MockStorage = MemoryStorage;
/// Length of canonical addresses created with this API. Contracts should not make any assumtions
/// what this value is.
/// The value here must be restorable with `SHUFFLES_ENCODE` + `SHUFFLES_DECODE` in-shuffles.
const CANONICAL_LENGTH: usize = 24;
const CANONICAL_LENGTH: usize = 54;

const SHUFFLES_ENCODE: usize = 18;
const SHUFFLES_DECODE: usize = 2;
Expand Down Expand Up @@ -633,7 +633,8 @@ mod tests {
#[should_panic(expected = "address too long")]
fn addr_canonicalize_max_input_length() {
let api = MockApi::default();
let human = String::from("some-extremely-long-address-not-supported-by-this-api");
let human =
String::from("some-extremely-long-address-not-supported-by-this-api-longer-than-54");
let _ = api.addr_canonicalize(&human).unwrap();
}

Expand Down
22 changes: 11 additions & 11 deletions packages/vm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const MAX_LENGTH_DB_KEY: usize = 64 * KI;
/// Max key length for db_write (i.e. when VM reads from Wasm memory)
const MAX_LENGTH_DB_VALUE: usize = 128 * KI;
/// Typically 20 (Cosmos SDK, Ethereum) or 32 (Nano, Substrate)
lukerhoads marked this conversation as resolved.
Show resolved Hide resolved
const MAX_LENGTH_CANONICAL_ADDRESS: usize = 32;
const MAX_LENGTH_CANONICAL_ADDRESS: usize = 64;
/// The maximum allowed size for bech32 (https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32)
const MAX_LENGTH_HUMAN_ADDRESS: usize = 90;
const MAX_LENGTH_QUERY_CHAIN_REQUEST: usize = 64 * KI;
Expand Down Expand Up @@ -948,7 +948,7 @@ mod tests {

let source_ptr1 = write_data(&env, b"fo\x80o"); // invalid UTF-8 (fo�o)
let source_ptr2 = write_data(&env, b""); // empty
let source_ptr3 = write_data(&env, b"addressexceedingaddressspace"); // too long
let source_ptr3 = write_data(&env, b"addressexceedingaddressspacesuperlongreallylongiamensuringthatitislongerthaneverything"); // too long

leave_default_data(&env);

Expand Down Expand Up @@ -1039,8 +1039,8 @@ mod tests {

let source_ptr1 = write_data(&env, b"fo\x80o"); // invalid UTF-8 (fo�o)
let source_ptr2 = write_data(&env, b""); // empty
let source_ptr3 = write_data(&env, b"addressexceedingaddressspace"); // too long
let dest_ptr = create_empty(&mut instance, 8);
let source_ptr3 = write_data(&env, b"addressexceedingaddressspacesuperlongreallylongiamensuringthatitislongerthaneverything"); // too long
let dest_ptr = create_empty(&mut instance, 70);

leave_default_data(&env);

Expand Down Expand Up @@ -1139,7 +1139,7 @@ mod tests {

let source_data = vec![0x22; api.canonical_length()];
let source_ptr = write_data(&env, &source_data);
let dest_ptr = create_empty(&mut instance, 50);
let dest_ptr = create_empty(&mut instance, 70);

leave_default_data(&env);

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

let source_ptr = write_data(&env, b"foo"); // too short
let dest_ptr = create_empty(&mut instance, 50);
let dest_ptr = create_empty(&mut instance, 70);

leave_default_data(&env);

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

let source_ptr = write_data(&env, b"foo\0\0\0\0\0");
let dest_ptr = create_empty(&mut instance, 50);
let dest_ptr = create_empty(&mut instance, 70);

leave_default_data(&env);

Expand All @@ -1189,8 +1189,8 @@ mod tests {
let api = MockApi::default();
let (env, mut instance) = make_instance(api);

let source_ptr = write_data(&env, &[61; 33]);
let dest_ptr = create_empty(&mut instance, 50);
let source_ptr = write_data(&env, &[61; 65]);
let dest_ptr = create_empty(&mut instance, 70);

leave_default_data(&env);

Expand All @@ -1203,8 +1203,8 @@ mod tests {
},
..
} => {
assert_eq!(length, 33);
assert_eq!(max_length, 32);
assert_eq!(length, 65);
assert_eq!(max_length, 64);
}
err => panic!("Incorrect error returned: {:?}", err),
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/src/testing/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn mock_backend_with_balances(
/// Length of canonical addresses created with this API. Contracts should not make any assumtions
/// what this value is.
/// The value here must be restorable with `SHUFFLES_ENCODE` + `SHUFFLES_DECODE` in-shuffles.
const CANONICAL_LENGTH: usize = 24;
const CANONICAL_LENGTH: usize = 54;

const SHUFFLES_ENCODE: usize = 18;
const SHUFFLES_DECODE: usize = 2;
Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {
#[test]
fn canonical_address_max_input_length() {
let api = MockApi::default();
let human = "longer-than-the-address-length-supported-by-this-api";
let human = "longer-than-the-address-length-supported-by-this-api-longer-than-54";
match api.canonical_address(human).0.unwrap_err() {
BackendError::UserErr { .. } => {}
err => panic!("Unexpected error: {:?}", err),
Expand Down