Skip to content

Commit abc9bcc

Browse files
authored
Merge pull request #1557 from CosmWasm/clippy-1.66.0
Bump clippy to 1.66.0 and fix some new warnings
2 parents 2bd030a + e348516 commit abc9bcc

File tree

10 files changed

+59
-26
lines changed

10 files changed

+59
-26
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ workflows:
7171
matrix:
7272
parameters:
7373
# Run with MSRV and some modern stable Rust
74-
rust-version: ["1.60.0", "1.65.0"]
74+
rust-version: ["1.60.0", "1.66.0"]
7575
- benchmarking:
7676
requires:
7777
- package_vm

contracts/crypto-verify/src/ethereum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn verify_transaction(
1919
) -> StdResult<bool> {
2020
let sign_bytes =
2121
serialize_unsigned_transaction(to, nonce, gas, gas_price, value, data, chain_id);
22-
let hash = Keccak256::digest(&sign_bytes);
22+
let hash = Keccak256::digest(sign_bytes);
2323
let mut rs: Vec<u8> = Vec::with_capacity(64);
2424
rs.resize(32 - r.len(), 0); // Left pad r to 32 bytes
2525
rs.extend_from_slice(r);

packages/crypto/benches/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn bench_crypto(c: &mut Criterion) {
7878

7979
group.bench_function("secp256k1_verify", |b| {
8080
let message = hex::decode(COSMOS_SECP256K1_MSG_HEX).unwrap();
81-
let message_hash = Sha256::digest(&message);
81+
let message_hash = Sha256::digest(message);
8282
let signature = hex::decode(COSMOS_SECP256K1_SIGNATURE_HEX).unwrap();
8383
let public_key = base64::decode(COSMOS_SECP256K1_PUBKEY_BASE64).unwrap();
8484
b.iter(|| {

packages/crypto/src/secp256k1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tests {
253253
let signature = hex::decode(sig).unwrap();
254254

255255
// Explicit hash
256-
let message_hash = Sha256::digest(&message);
256+
let message_hash = Sha256::digest(message);
257257

258258
// secp256k1_verify works
259259
assert!(
@@ -290,7 +290,7 @@ mod tests {
290290
let message = hex::decode(&encoded.message).unwrap();
291291

292292
let hash = hex::decode(&encoded.message_hash).unwrap();
293-
let message_hash = Sha256::digest(&message);
293+
let message_hash = Sha256::digest(message);
294294
assert_eq!(hash.as_slice(), message_hash.as_slice());
295295

296296
let signature = hex::decode(&encoded.signature).unwrap();

packages/vm/src/cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn save_wasm_to_disk(dir: impl Into<PathBuf>, wasm: &[u8]) -> VmResult<Checksum>
336336
// calculate filename
337337
let checksum = Checksum::generate(wasm);
338338
let filename = checksum.to_hex();
339-
let filepath = dir.into().join(&filename);
339+
let filepath = dir.into().join(filename);
340340

341341
// write data to file
342342
// Since the same filename (a collision resistent hash) cannot be generated from two different byte codes
@@ -561,7 +561,7 @@ mod tests {
561561
.path()
562562
.join(STATE_DIR)
563563
.join(WASM_DIR)
564-
.join(&checksum.to_hex());
564+
.join(checksum.to_hex());
565565
let mut file = OpenOptions::new().write(true).open(filepath).unwrap();
566566
file.write_all(b"broken data").unwrap();
567567

packages/vm/src/imports.rs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ pub fn do_addr_humanize<A: BackendApi, S: Storage, Q: Querier>(
212212
}
213213
}
214214

215+
/// Return code (error code) for a valid signature
216+
const SECP256K1_VERIFY_CODE_VALID: u32 = 0;
217+
218+
/// Return code (error code) for an invalid signature
219+
const SECP256K1_VERIFY_CODE_INVALID: u32 = 1;
220+
215221
pub fn do_secp256k1_verify<A: BackendApi, S: Storage, Q: Querier>(
216222
env: &Environment<A, S, Q>,
217223
hash_ptr: u32,
@@ -225,8 +231,15 @@ pub fn do_secp256k1_verify<A: BackendApi, S: Storage, Q: Querier>(
225231
let gas_info = GasInfo::with_cost(env.gas_config.secp256k1_verify_cost);
226232
process_gas_info::<A, S, Q>(env, gas_info)?;
227233
let result = secp256k1_verify(&hash, &signature, &pubkey);
228-
Ok(result.map_or_else(
229-
|err| match err {
234+
let code = match result {
235+
Ok(valid) => {
236+
if valid {
237+
SECP256K1_VERIFY_CODE_VALID
238+
} else {
239+
SECP256K1_VERIFY_CODE_INVALID
240+
}
241+
}
242+
Err(err) => match err {
230243
CryptoError::InvalidHashFormat { .. }
231244
| CryptoError::InvalidPubkeyFormat { .. }
232245
| CryptoError::InvalidSignatureFormat { .. }
@@ -235,8 +248,8 @@ pub fn do_secp256k1_verify<A: BackendApi, S: Storage, Q: Querier>(
235248
panic!("Error must not happen for this call")
236249
}
237250
},
238-
|valid| if valid { 0 } else { 1 },
239-
))
251+
};
252+
Ok(code)
240253
}
241254

242255
pub fn do_secp256k1_recover_pubkey<A: BackendApi, S: Storage, Q: Querier>(
@@ -272,6 +285,12 @@ pub fn do_secp256k1_recover_pubkey<A: BackendApi, S: Storage, Q: Querier>(
272285
}
273286
}
274287

288+
/// Return code (error code) for a valid signature
289+
const ED25519_VERIFY_CODE_VALID: u32 = 0;
290+
291+
/// Return code (error code) for an invalid signature
292+
const ED25519_VERIFY_CODE_INVALID: u32 = 1;
293+
275294
pub fn do_ed25519_verify<A: BackendApi, S: Storage, Q: Querier>(
276295
env: &Environment<A, S, Q>,
277296
message_ptr: u32,
@@ -285,8 +304,15 @@ pub fn do_ed25519_verify<A: BackendApi, S: Storage, Q: Querier>(
285304
let gas_info = GasInfo::with_cost(env.gas_config.ed25519_verify_cost);
286305
process_gas_info::<A, S, Q>(env, gas_info)?;
287306
let result = ed25519_verify(&message, &signature, &pubkey);
288-
Ok(result.map_or_else(
289-
|err| match err {
307+
let code = match result {
308+
Ok(valid) => {
309+
if valid {
310+
ED25519_VERIFY_CODE_VALID
311+
} else {
312+
ED25519_VERIFY_CODE_INVALID
313+
}
314+
}
315+
Err(err) => match err {
290316
CryptoError::InvalidPubkeyFormat { .. }
291317
| CryptoError::InvalidSignatureFormat { .. }
292318
| CryptoError::GenericErr { .. } => err.code(),
@@ -296,8 +322,8 @@ pub fn do_ed25519_verify<A: BackendApi, S: Storage, Q: Querier>(
296322
panic!("Error must not happen for this call")
297323
}
298324
},
299-
|valid| if valid { 0 } else { 1 },
300-
))
325+
};
326+
Ok(code)
301327
}
302328

303329
pub fn do_ed25519_batch_verify<A: BackendApi, S: Storage, Q: Querier>(
@@ -334,8 +360,15 @@ pub fn do_ed25519_batch_verify<A: BackendApi, S: Storage, Q: Querier>(
334360
let gas_info = GasInfo::with_cost(max(gas_cost, env.gas_config.ed25519_verify_cost));
335361
process_gas_info::<A, S, Q>(env, gas_info)?;
336362
let result = ed25519_batch_verify(&messages, &signatures, &public_keys);
337-
Ok(result.map_or_else(
338-
|err| match err {
363+
let code = match result {
364+
Ok(valid) => {
365+
if valid {
366+
ED25519_VERIFY_CODE_VALID
367+
} else {
368+
ED25519_VERIFY_CODE_INVALID
369+
}
370+
}
371+
Err(err) => match err {
339372
CryptoError::BatchErr { .. }
340373
| CryptoError::InvalidPubkeyFormat { .. }
341374
| CryptoError::InvalidSignatureFormat { .. }
@@ -344,8 +377,8 @@ pub fn do_ed25519_batch_verify<A: BackendApi, S: Storage, Q: Querier>(
344377
panic!("Error must not happen for this call")
345378
}
346379
},
347-
|valid| (!valid).into(),
348-
))
380+
};
381+
Ok(code)
349382
}
350383

351384
/// Prints a debug message to console.
@@ -588,7 +621,7 @@ mod tests {
588621
let result = do_db_read(&env, key_ptr);
589622
let value_ptr = result.unwrap();
590623
assert!(value_ptr > 0);
591-
assert_eq!(force_read(&env, value_ptr as u32), VALUE1);
624+
assert_eq!(force_read(&env, value_ptr), VALUE1);
592625
}
593626

594627
#[test]

packages/vm/src/modules/file_system_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl FileSystemCache {
106106
let filename = checksum.to_hex();
107107
let file_path = self.latest_modules_path().join(filename);
108108

109-
let result = unsafe { Module::deserialize_from_file(store, &file_path) };
109+
let result = unsafe { Module::deserialize_from_file(store, file_path) };
110110
match result {
111111
Ok(module) => Ok(Some(module)),
112112
Err(DeserializeError::Io(err)) => match err.kind() {

packages/vm/src/modules/pinned_memory_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl PinnedMemoryCache {
5252
/// This is based on the values provided with `store`. No actual
5353
/// memory size is measured here.
5454
pub fn size(&self) -> usize {
55-
self.modules.iter().map(|(_, module)| module.size).sum()
55+
self.modules.values().map(|module| module.size).sum()
5656
}
5757
}
5858

packages/vm/src/wasm_backend/gatekeeper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ mod tests {
711711
let mut compiler_config = Cranelift::default();
712712
compiler_config.push_middleware(deterministic);
713713
let store = Store::new(&Universal::new(compiler_config).engine());
714-
let result = Module::new(&store, &wasm);
714+
let result = Module::new(&store, wasm);
715715
assert!(result.is_ok());
716716
}
717717

@@ -732,7 +732,7 @@ mod tests {
732732
let mut compiler_config = Cranelift::default();
733733
compiler_config.push_middleware(deterministic);
734734
let store = Store::new(&Universal::new(compiler_config).engine());
735-
let result = Module::new(&store, &wasm);
735+
let result = Module::new(&store, wasm);
736736
assert!(result
737737
.unwrap_err()
738738
.to_string()
@@ -759,7 +759,7 @@ mod tests {
759759
let mut compiler_config = Cranelift::default();
760760
compiler_config.push_middleware(deterministic);
761761
let store = Store::new(&Universal::new(compiler_config).engine());
762-
let result = Module::new(&store, &wasm);
762+
let result = Module::new(&store, wasm);
763763
assert!(result
764764
.unwrap_err()
765765
.to_string()

packages/vm/src/wasm_backend/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod tests {
171171
let serialized = {
172172
let wasm = wat::parse_str(EXPORTED_MEMORY_WAT).unwrap();
173173
let store = make_compile_time_store(None, &[]);
174-
let module = Module::new(&store, &wasm).unwrap();
174+
let module = Module::new(&store, wasm).unwrap();
175175
module.serialize().unwrap()
176176
};
177177

0 commit comments

Comments
 (0)