From f37be33a3331814022d3fd2485a62b1b81b2a9e5 Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 13:05:03 +0200 Subject: [PATCH 1/6] Fixed clippy warnings. --- packages/vm/benches/main.rs | 1 - packages/vm/examples/multi_threaded_cache.rs | 1 - packages/vm/src/environment.rs | 2 +- packages/vm/src/imports.rs | 170 +++++++++---------- packages/vm/src/instance.rs | 16 +- 5 files changed, 88 insertions(+), 102 deletions(-) diff --git a/packages/vm/benches/main.rs b/packages/vm/benches/main.rs index e0911e3804..afefe5d3cb 100644 --- a/packages/vm/benches/main.rs +++ b/packages/vm/benches/main.rs @@ -318,7 +318,6 @@ pub fn bench_instance_threads(c: &mut Criterion) { let checksum = random_checksum(); thread::spawn(move || { - let checksum = checksum; // Perform measurement internally let t = SystemTime::now(); black_box( diff --git a/packages/vm/examples/multi_threaded_cache.rs b/packages/vm/examples/multi_threaded_cache.rs index 7be56be405..fd8c145f25 100644 --- a/packages/vm/examples/multi_threaded_cache.rs +++ b/packages/vm/examples/multi_threaded_cache.rs @@ -51,7 +51,6 @@ pub fn main() { let cache = Arc::clone(&cache); threads.push(thread::spawn(move || { - let checksum = checksum; let mut instance = cache .get_instance(&checksum, mock_backend(&[]), DEFAULT_INSTANCE_OPTIONS) .unwrap(); diff --git a/packages/vm/src/environment.rs b/packages/vm/src/environment.rs index 746126f1fe..e358723372 100644 --- a/packages/vm/src/environment.rs +++ b/packages/vm/src/environment.rs @@ -368,7 +368,7 @@ impl Environment { /// Creates a MemoryView. /// This must be short living and not be used after the memory was grown. - pub fn memory<'a>(&self, store: &'a mut impl AsStoreMut) -> MemoryView<'a> { + pub fn memory<'a>(&self, store: &'a impl AsStoreMut) -> MemoryView<'a> { self.memory .as_ref() .expect("Memory is not set. This is a bug in the lifecycle.") diff --git a/packages/vm/src/imports.rs b/packages/vm/src/imports.rs index 4924c888d8..ca4db76a36 100644 --- a/packages/vm/src/imports.rs +++ b/packages/vm/src/imports.rs @@ -45,11 +45,11 @@ const MAX_LENGTH_QUERY_CHAIN_REQUEST: usize = 64 * KI; /// Length of a serialized Ed25519 signature const MAX_LENGTH_ED25519_SIGNATURE: usize = 64; /// Max length of a Ed25519 message in bytes. -/// This is an arbitrary value, for performance / memory contraints. If you need to verify larger +/// This is an arbitrary value, for performance / memory constraints. If you need to verify larger /// messages, let us know. const MAX_LENGTH_ED25519_MESSAGE: usize = 128 * 1024; /// Max number of batch Ed25519 messages / signatures / public_keys. -/// This is an arbitrary value, for performance / memory contraints. If you need to batch-verify a +/// This is an arbitrary value, for performance / memory constraints. If you need to batch-verify a /// larger number of signatures, let us know. const MAX_COUNT_ED25519_BATCH: usize = 256; @@ -73,7 +73,7 @@ pub fn do_db_read VmResult { let (data, mut store) = env.data_and_store_mut(); - let key = read_region(&data.memory(&mut store), key_ptr, MAX_LENGTH_DB_KEY)?; + let key = read_region(&data.memory(&store), key_ptr, MAX_LENGTH_DB_KEY)?; let (result, gas_info) = data.with_storage_from_context::<_, _>(|store| Ok(store.get(&key)))?; process_gas_info(data, &mut store, gas_info)?; @@ -98,8 +98,8 @@ pub fn do_db_write(|store| Ok(store.set(&key, &value)))?; @@ -119,7 +119,7 @@ pub fn do_db_remove(|store| Ok(store.remove(&key)))?; @@ -135,11 +135,7 @@ pub fn do_addr_validate VmResult { let (data, mut store) = env.data_and_store_mut(); - let source_data = read_region( - &data.memory(&mut store), - source_ptr, - MAX_LENGTH_HUMAN_ADDRESS, - )?; + let source_data = read_region(&data.memory(&store), source_ptr, MAX_LENGTH_HUMAN_ADDRESS)?; if source_data.is_empty() { return write_to_contract(data, &mut store, b"Input is empty"); } @@ -183,11 +179,7 @@ pub fn do_addr_canonicalize VmResult { let (data, mut store) = env.data_and_store_mut(); - let source_data = read_region( - &data.memory(&mut store), - source_ptr, - MAX_LENGTH_HUMAN_ADDRESS, - )?; + let source_data = read_region(&data.memory(&store), source_ptr, MAX_LENGTH_HUMAN_ADDRESS)?; if source_data.is_empty() { return write_to_contract(data, &mut store, b"Input is empty"); } @@ -201,11 +193,7 @@ pub fn do_addr_canonicalize { - write_region( - &data.memory(&mut store), - destination_ptr, - canonical.as_slice(), - )?; + write_region(&data.memory(&store), destination_ptr, canonical.as_slice())?; Ok(0) } Err(BackendError::UserErr { msg, .. }) => { @@ -223,7 +211,7 @@ pub fn do_addr_humanize { - write_region(&data.memory(&mut store), destination_ptr, human.as_bytes())?; + write_region(&data.memory(&store), destination_ptr, human.as_bytes())?; Ok(0) } Err(BackendError::UserErr { msg, .. }) => { @@ -256,9 +244,9 @@ pub fn do_secp256k1_verify VmResult { let (data, mut store) = env.data_and_store_mut(); - let hash = read_region(&data.memory(&mut store), hash_ptr, MESSAGE_HASH_MAX_LEN)?; - let signature = read_region(&data.memory(&mut store), signature_ptr, ECDSA_SIGNATURE_LEN)?; - let pubkey = read_region(&data.memory(&mut store), pubkey_ptr, ECDSA_PUBKEY_MAX_LEN)?; + let hash = read_region(&data.memory(&store), hash_ptr, MESSAGE_HASH_MAX_LEN)?; + let signature = read_region(&data.memory(&store), signature_ptr, ECDSA_SIGNATURE_LEN)?; + let pubkey = read_region(&data.memory(&store), pubkey_ptr, ECDSA_PUBKEY_MAX_LEN)?; let gas_info = GasInfo::with_cost(data.gas_config.secp256k1_verify_cost); process_gas_info(data, &mut store, gas_info)?; @@ -296,8 +284,8 @@ pub fn do_secp256k1_recover_pubkey< ) -> VmResult { let (data, mut store) = env.data_and_store_mut(); - let hash = read_region(&data.memory(&mut store), hash_ptr, MESSAGE_HASH_MAX_LEN)?; - let signature = read_region(&data.memory(&mut store), signature_ptr, ECDSA_SIGNATURE_LEN)?; + let hash = read_region(&data.memory(&store), hash_ptr, MESSAGE_HASH_MAX_LEN)?; + let signature = read_region(&data.memory(&store), signature_ptr, ECDSA_SIGNATURE_LEN)?; let recover_param: u8 = match recover_param.try_into() { Ok(rp) => rp, Err(_) => return Ok((CryptoError::invalid_recovery_param().code() as u64) << 32), @@ -338,16 +326,16 @@ pub fn do_ed25519_verify>, message_ptr: u32, ) -> VmResult<()> { - let (data, mut store) = env.data_and_store_mut(); + let (data, store) = env.data_and_store_mut(); - let message_data = read_region(&data.memory(&mut store), message_ptr, MAX_LENGTH_ABORT)?; + let message_data = read_region(&data.memory(&store), message_ptr, MAX_LENGTH_ABORT)?; let msg = String::from_utf8_lossy(&message_data); Err(VmError::aborted(msg)) } @@ -477,7 +465,7 @@ pub fn do_query_chain VmResult { let (data, mut store) = env.data_and_store_mut(); - let start = maybe_read_region(&data.memory(&mut store), start_ptr, MAX_LENGTH_DB_KEY)?; - let end = maybe_read_region(&data.memory(&mut store), end_ptr, MAX_LENGTH_DB_KEY)?; + let start = maybe_read_region(&data.memory(&store), start_ptr, MAX_LENGTH_DB_KEY)?; + let end = maybe_read_region(&data.memory(&store), end_ptr, MAX_LENGTH_DB_KEY)?; let order: Order = order .try_into() .map_err(|_| CommunicationError::invalid_order(order))?; @@ -715,7 +703,7 @@ mod tests { fn leave_default_data( fe_mut: &mut FunctionEnvMut>, ) { - let (env, mut _store) = fe_mut.data_and_store_mut(); + let (env, _store) = fe_mut.data_and_store_mut(); // create some mock data let mut storage = MockStorage::new(); @@ -736,12 +724,12 @@ mod tests { .call_function1(&mut store, "allocate", &[(data.len() as u32).into()]) .unwrap(); let region_ptr = ref_to_u32(&result).unwrap(); - write_region(&env.memory(&mut store), region_ptr, data).expect("error writing"); + write_region(&env.memory(&store), region_ptr, data).expect("error writing"); region_ptr } fn create_empty( - wasmer_instance: &mut WasmerInstance, + wasmer_instance: &WasmerInstance, fe_mut: &mut FunctionEnvMut>, capacity: u32, ) -> u32 { @@ -761,9 +749,9 @@ mod tests { fe_mut: &mut FunctionEnvMut>, region_ptr: u32, ) -> Vec { - let (env, mut store) = fe_mut.data_and_store_mut(); + let (env, store) = fe_mut.data_and_store_mut(); - read_region(&env.memory(&mut store), region_ptr, 5000).unwrap() + read_region(&env.memory(&store), region_ptr, 5000).unwrap() } #[test] @@ -1005,7 +993,7 @@ mod tests { leave_default_data(&mut fe_mut); - // Note: right now we cannot differnetiate between an existent and a non-existent key + // Note: right now we cannot differentiate between an existent and a non-existent key do_db_remove(fe_mut.as_mut(), key_ptr).unwrap(); let value = fe_mut @@ -1160,12 +1148,12 @@ mod tests { #[test] fn do_addr_canonicalize_works() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let api = MockApi::default(); let source_ptr = write_data(&mut fe_mut, b"foo"); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, api.canonical_length() as u32); + let dest_ptr = create_empty(&instance, &mut fe_mut, api.canonical_length() as u32); leave_default_data(&mut fe_mut); @@ -1179,13 +1167,13 @@ mod tests { #[test] fn do_addr_canonicalize_reports_invalid_input_back_to_contract() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr1 = write_data(&mut fe_mut, b"fo\x80o"); // invalid UTF-8 (fo�o) let source_ptr2 = write_data(&mut fe_mut, b""); // empty let source_ptr3 = write_data(&mut fe_mut, b"addressexceedingaddressspacesuperlongreallylongiamensuringthatitislongerthaneverything"); // too long - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 70); + let dest_ptr = create_empty(&instance, &mut fe_mut, 70); leave_default_data(&mut fe_mut); @@ -1211,11 +1199,11 @@ mod tests { #[test] fn do_addr_canonicalize_fails_for_broken_backend() { let api = MockApi::new_failing("Temporarily unavailable"); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, b"foo"); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 7); + let dest_ptr = create_empty(&instance, &mut fe_mut, 7); leave_default_data(&mut fe_mut); @@ -1232,11 +1220,11 @@ mod tests { #[test] fn do_addr_canonicalize_fails_for_large_inputs() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, &[61; 333]); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 8); + let dest_ptr = create_empty(&instance, &mut fe_mut, 8); leave_default_data(&mut fe_mut); @@ -1259,11 +1247,11 @@ mod tests { #[test] fn do_addr_canonicalize_fails_for_small_destination_region() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, b"foo"); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 7); + let dest_ptr = create_empty(&instance, &mut fe_mut, 7); leave_default_data(&mut fe_mut); @@ -1283,13 +1271,13 @@ mod tests { #[test] fn do_addr_humanize_works() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let api = MockApi::default(); let source_data = vec![0x22; api.canonical_length()]; let source_ptr = write_data(&mut fe_mut, &source_data); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 70); + let dest_ptr = create_empty(&instance, &mut fe_mut, 70); leave_default_data(&mut fe_mut); @@ -1301,11 +1289,11 @@ mod tests { #[test] fn do_addr_humanize_reports_invalid_input_back_to_contract() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, b"foo"); // too short - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 70); + let dest_ptr = create_empty(&instance, &mut fe_mut, 70); leave_default_data(&mut fe_mut); @@ -1318,11 +1306,11 @@ mod tests { #[test] fn do_addr_humanize_fails_for_broken_backend() { let api = MockApi::new_failing("Temporarily unavailable"); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, b"foo\0\0\0\0\0"); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 70); + let dest_ptr = create_empty(&instance, &mut fe_mut, 70); leave_default_data(&mut fe_mut); @@ -1339,11 +1327,11 @@ mod tests { #[test] fn do_addr_humanize_fails_for_input_too_long() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let source_ptr = write_data(&mut fe_mut, &[61; 65]); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 70); + let dest_ptr = create_empty(&instance, &mut fe_mut, 70); leave_default_data(&mut fe_mut); @@ -1366,13 +1354,13 @@ mod tests { #[test] fn do_addr_humanize_fails_for_destination_region_too_small() { let api = MockApi::default(); - let (fe, mut store, mut instance) = make_instance(api); + let (fe, mut store, instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let api = MockApi::default(); let source_data = vec![0x22; api.canonical_length()]; let source_ptr = write_data(&mut fe_mut, &source_data); - let dest_ptr = create_empty(&mut instance, &mut fe_mut, 2); + let dest_ptr = create_empty(&instance, &mut fe_mut, 2); leave_default_data(&mut fe_mut); @@ -1392,7 +1380,7 @@ mod tests { #[test] fn do_secp256k1_verify_works() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1411,7 +1399,7 @@ mod tests { #[test] fn do_secp256k1_verify_wrong_hash_verify_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let mut hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1432,7 +1420,7 @@ mod tests { #[test] fn do_secp256k1_verify_larger_hash_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let mut hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1457,7 +1445,7 @@ mod tests { #[test] fn do_secp256k1_verify_shorter_hash_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let mut hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1478,7 +1466,7 @@ mod tests { #[test] fn do_secp256k1_verify_wrong_sig_verify_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1499,7 +1487,7 @@ mod tests { #[test] fn do_secp256k1_verify_larger_sig_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1524,7 +1512,7 @@ mod tests { #[test] fn do_secp256k1_verify_shorter_sig_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1545,7 +1533,7 @@ mod tests { #[test] fn do_secp256k1_verify_wrong_pubkey_format_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1566,7 +1554,7 @@ mod tests { #[test] fn do_secp256k1_verify_wrong_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1587,7 +1575,7 @@ mod tests { #[test] fn do_secp256k1_verify_larger_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1612,7 +1600,7 @@ mod tests { #[test] fn do_secp256k1_verify_shorter_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1633,7 +1621,7 @@ mod tests { #[test] fn do_secp256k1_verify_empty_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = hex::decode(ECDSA_HASH_HEX).unwrap(); @@ -1652,7 +1640,7 @@ mod tests { #[test] fn do_secp256k1_verify_wrong_data_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let hash = vec![0x22; MESSAGE_HASH_MAX_LEN]; @@ -1671,7 +1659,7 @@ mod tests { #[test] fn do_secp256k1_recover_pubkey_works() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); // https://gist.github.com/webmaster128/130b628d83621a33579751846699ed15 @@ -1694,7 +1682,7 @@ mod tests { #[test] fn do_ed25519_verify_works() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1713,7 +1701,7 @@ mod tests { #[test] fn do_ed25519_verify_wrong_msg_verify_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let mut msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1734,7 +1722,7 @@ mod tests { #[test] fn do_ed25519_verify_larger_msg_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let mut msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1759,7 +1747,7 @@ mod tests { #[test] fn do_ed25519_verify_wrong_sig_verify_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1780,7 +1768,7 @@ mod tests { #[test] fn do_ed25519_verify_larger_sig_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1805,7 +1793,7 @@ mod tests { #[test] fn do_ed25519_verify_shorter_sig_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1826,7 +1814,7 @@ mod tests { #[test] fn do_ed25519_verify_wrong_pubkey_verify_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1847,7 +1835,7 @@ mod tests { #[test] fn do_ed25519_verify_larger_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1872,7 +1860,7 @@ mod tests { #[test] fn do_ed25519_verify_shorter_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1893,7 +1881,7 @@ mod tests { #[test] fn do_ed25519_verify_empty_pubkey_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = hex::decode(EDDSA_MSG_HEX).unwrap(); @@ -1912,7 +1900,7 @@ mod tests { #[test] fn do_ed25519_verify_wrong_data_fails() { let api = MockApi::default(); - let (fe, mut store, mut _instance) = make_instance(api); + let (fe, mut store, _instance) = make_instance(api); let mut fe_mut = fe.into_mut(&mut store); let msg = vec![0x22; MESSAGE_HASH_MAX_LEN]; diff --git a/packages/vm/src/instance.rs b/packages/vm/src/instance.rs index cd9efe65de..f35997e5b3 100644 --- a/packages/vm/src/instance.rs +++ b/packages/vm/src/instance.rs @@ -341,7 +341,7 @@ where /// Returns the features required by this contract. /// /// This is not needed for production because we can do static analysis - /// on the Wasm file before instatiation to obtain this information. It's + /// on the Wasm file before instantiation to obtain this information. It's /// only kept because it can be handy for integration testing. pub fn required_capabilities(&self) -> HashSet { required_capabilities_from_module(self._inner.module()) @@ -353,9 +353,9 @@ where /// (https://github.com/WebAssembly/design/issues/1300#issuecomment-573867836). pub fn memory_pages(&mut self) -> usize { let mut fe_mut = self.fe.clone().into_mut(&mut self.store); - let (env, mut store) = fe_mut.data_and_store_mut(); + let (env, store) = fe_mut.data_and_store_mut(); - env.memory(&mut store).size().0 as _ + env.memory(&store).size().0 as _ } /// Returns the currently remaining gas. @@ -440,17 +440,17 @@ where /// Copies all data described by the Region at the given pointer from Wasm to the caller. pub(crate) fn read_memory(&mut self, region_ptr: u32, max_length: usize) -> VmResult> { let mut fe_mut = self.fe.clone().into_mut(&mut self.store); - let (env, mut store) = fe_mut.data_and_store_mut(); + let (env, store) = fe_mut.data_and_store_mut(); - read_region(&env.memory(&mut store), region_ptr, max_length) + read_region(&env.memory(&store), region_ptr, max_length) } /// Copies data to the memory region that was created before using allocate. pub(crate) fn write_memory(&mut self, region_ptr: u32, data: &[u8]) -> VmResult<()> { let mut fe_mut = self.fe.clone().into_mut(&mut self.store); - let (env, mut store) = fe_mut.data_and_store_mut(); + let (env, store) = fe_mut.data_and_store_mut(); - write_region(&env.memory(&mut store), region_ptr, data)?; + write_region(&env.memory(&store), region_ptr, data)?; Ok(()) } @@ -1004,7 +1004,7 @@ mod tests { .unwrap(); } - /// This is needed for writing intagration tests in which the balance of a contract changes over time + /// This is needed for writing integration tests in which the balance of a contract changes over time. #[test] fn with_querier_allows_updating_balances() { let rich_addr = String::from("foobar"); From 0794fecb0859e5c6d9d50308f00298ad2cf6199f Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 13:19:23 +0200 Subject: [PATCH 2/6] Fixed clippy warnings. --- packages/go-gen/src/schema.rs | 1 + packages/std/src/addresses.rs | 6 +++--- packages/std/src/testing/mock.rs | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/go-gen/src/schema.rs b/packages/go-gen/src/schema.rs index 9d9a3fa866..56a22f2963 100644 --- a/packages/go-gen/src/schema.rs +++ b/packages/go-gen/src/schema.rs @@ -85,6 +85,7 @@ pub fn schema_object_type( /// Tries to extract the type of the non-null variant of an anyOf schema. /// /// Returns `Ok(None)` if the type is not nullable. +#[allow(clippy::manual_try_fold)] pub fn nullable_type(subschemas: &[Schema]) -> Result, anyhow::Error> { let (found_null, nullable_type): (bool, Option<&SchemaObject>) = subschemas .iter() diff --git a/packages/std/src/addresses.rs b/packages/std/src/addresses.rs index 39bc8bc06b..f05702e4d9 100644 --- a/packages/std/src/addresses.rs +++ b/packages/std/src/addresses.rs @@ -167,7 +167,7 @@ impl<'a> From<&'a Addr> for Cow<'a, Addr> { /// /// The safe way to obtain a valid `CanonicalAddr` is using `Api::addr_canonicalize`. In /// addition to that there are many unsafe ways to convert any binary data into an instance. -/// So the type shoud be treated as a marker to express the intended data type, not as +/// So the type should be treated as a marker to express the intended data type, not as /// a validity guarantee of any sort. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash, JsonSchema)] pub struct CanonicalAddr(pub Binary); @@ -358,7 +358,7 @@ pub fn instantiate2_address( } /// The instantiate2 address derivation implementation. This API is used for -/// testing puposes only. The `msg` field is discouraged and should not be used. +/// testing purposes only. The `msg` field is discouraged and should not be used. /// Use [`instantiate2_address`]. #[doc(hidden)] fn instantiate2_address_impl( @@ -751,7 +751,7 @@ mod tests { } #[test] - fn instantiate2_address_impl_works_for_cosmjs_testvectors() { + fn instantiate2_address_impl_works_for_cosmjs_test_vectors() { // Test data from https://github.com/cosmos/cosmjs/pull/1253 const COSMOS_ED25519_TESTS_JSON: &str = "./testdata/instantiate2_addresses.json"; diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index 305af4afb1..ebd4199028 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -106,9 +106,9 @@ const CANONICAL_LENGTH: usize = 90; // n = 45 const SHUFFLES_ENCODE: usize = 10; const SHUFFLES_DECODE: usize = 2; -// MockPrecompiles zero pads all human addresses to make them fit the canonical_length +// Mock precompiles zero pads all human addresses to make them fit the canonical_length // it trims off zeros for the reverse operation. -// not really smart, but allows us to see a difference (and consistent length for canonical adddresses) +// not really smart, but allows us to see a difference (and consistent length for canonical addresses) #[derive(Copy, Clone)] pub struct MockApi { /// Length of canonical addresses created with this API. Contracts should not make any assumptions @@ -152,7 +152,7 @@ impl Api for MockApi { )); } - // mimicks formats like hex or bech32 where different casings are valid for one address + // mimics formats like hex or bech32 where different casings are valid for one address let normalized = input.to_lowercase(); let mut out = Vec::from(normalized); From 10ae95348d26e1133f5a39a98175ea94cb931f43 Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 13:55:53 +0200 Subject: [PATCH 3/6] Spellings. --- packages/std/src/errors/system_error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/errors/system_error.rs b/packages/std/src/errors/system_error.rs index 98dc6f6707..94790295bb 100644 --- a/packages/std/src/errors/system_error.rs +++ b/packages/std/src/errors/system_error.rs @@ -7,7 +7,7 @@ use crate::Binary; /// /// This is used on return values for Querier as a nested result: Result, SystemError> /// The first wrap (SystemError) will trigger if the contract address doesn't exist, -/// the QueryRequest is malformated, etc. The second wrap will be an error message from +/// the QueryRequest is malformed, etc. The second wrap will be an error message from /// the contract itself. /// /// Such errors are only created by the VM. The error type is defined in the standard library, to ensure From 9d78a99d2453605baf8c86cc88bbde25c6a18404 Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 14:30:45 +0200 Subject: [PATCH 4/6] Applied lint suggestions. --- packages/go-gen/src/schema.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/go-gen/src/schema.rs b/packages/go-gen/src/schema.rs index 56a22f2963..496d0954c2 100644 --- a/packages/go-gen/src/schema.rs +++ b/packages/go-gen/src/schema.rs @@ -85,22 +85,21 @@ pub fn schema_object_type( /// Tries to extract the type of the non-null variant of an anyOf schema. /// /// Returns `Ok(None)` if the type is not nullable. -#[allow(clippy::manual_try_fold)] pub fn nullable_type(subschemas: &[Schema]) -> Result, anyhow::Error> { let (found_null, nullable_type): (bool, Option<&SchemaObject>) = subschemas .iter() - .fold(Ok((false, None)), |result: Result<_>, subschema| { - result.and_then(|(nullable, not_null)| { + .try_fold( + (false, None), + |(nullable, not_null), subschema| -> Result<_> { let subschema = subschema.object()?; if is_null(subschema) { Ok((true, not_null)) } else { Ok((nullable, Some(subschema))) } - }) - }) + }, + ) .context("failed to get anyOf subschemas")?; - Ok(if found_null { nullable_type } else { None }) } From ea51d4515abe44e6be3253e45f8f3ecae905cbb9 Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 14:32:44 +0200 Subject: [PATCH 5/6] Fixed Description. --- packages/std/src/testing/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index ebd4199028..400981f0f9 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -106,7 +106,7 @@ const CANONICAL_LENGTH: usize = 90; // n = 45 const SHUFFLES_ENCODE: usize = 10; const SHUFFLES_DECODE: usize = 2; -// Mock precompiles zero pads all human addresses to make them fit the canonical_length +// Mock zero pads all human addresses to make them fit the canonical_length // it trims off zeros for the reverse operation. // not really smart, but allows us to see a difference (and consistent length for canonical addresses) #[derive(Copy, Clone)] From 4a2d720b516460e98275acb312d722e41fd320bf Mon Sep 17 00:00:00 2001 From: Dariusz Depta Date: Tue, 19 Sep 2023 14:33:50 +0200 Subject: [PATCH 6/6] Fixed description. --- packages/std/src/testing/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/std/src/testing/mock.rs b/packages/std/src/testing/mock.rs index 400981f0f9..8d8d785e5e 100644 --- a/packages/std/src/testing/mock.rs +++ b/packages/std/src/testing/mock.rs @@ -106,7 +106,7 @@ const CANONICAL_LENGTH: usize = 90; // n = 45 const SHUFFLES_ENCODE: usize = 10; const SHUFFLES_DECODE: usize = 2; -// Mock zero pads all human addresses to make them fit the canonical_length +// MockApi zero pads all human addresses to make them fit the canonical_length // it trims off zeros for the reverse operation. // not really smart, but allows us to see a difference (and consistent length for canonical addresses) #[derive(Copy, Clone)]