From cf4411a4c2ba16816bcf4c81f0187a24c0647696 Mon Sep 17 00:00:00 2001 From: Honza <115138297+Supremesource@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:17:39 -0300 Subject: [PATCH] fix: suggestions --- node/src/service/decrypter.rs | 13 ++++----- pallets/offworker/src/dispatches/mod.rs | 37 +++++++------------------ pallets/offworker/src/lib.rs | 14 ---------- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/node/src/service/decrypter.rs b/node/src/service/decrypter.rs index f2187226d..edc73b188 100644 --- a/node/src/service/decrypter.rs +++ b/node/src/service/decrypter.rs @@ -48,19 +48,16 @@ impl ow_extensions::OffworkerExtension for Decrypter { let vec = encrypted .chunks(key.size()) - .map(|chunk| match key.decrypt(Pkcs1v15Encrypt, chunk) { - Ok(decrypted) => Some(decrypted), - Err(_) => None, - }) - .collect::>>>()?; + .map(|chunk| key.decrypt(Pkcs1v15Encrypt, chunk)) + .collect::>, _>>() + .ok()?; let decrypted = vec.into_iter().flatten().collect::>(); - let mut res = Vec::new(); - let mut cursor = Cursor::new(&decrypted); - let length = read_u32(&mut cursor)?; + + let mut res = Vec::with_capacity(length as usize); for _ in 0..length { let uid = read_u16(&mut cursor)?; let weight = read_u16(&mut cursor)?; diff --git a/pallets/offworker/src/dispatches/mod.rs b/pallets/offworker/src/dispatches/mod.rs index c4b99ccea..2146fbf3e 100644 --- a/pallets/offworker/src/dispatches/mod.rs +++ b/pallets/offworker/src/dispatches/mod.rs @@ -4,20 +4,6 @@ use frame_support::pallet_macros::pallet_section; pub mod dispatches { #[pallet::call] impl Pallet { - // TODO: step 3 v2 of DEW will involve offworker sending potential zk proofs of encryption - // correctness (proof that he can not decrypt certain weights) - - // # References - // - [CS03] Practical Verifiable Encryption and Decryption of Discrete Logarithms - // Jan Camenisch and Victor Shoup, CRYPTO 2003 - // https://link.springer.com/content/pdf/10.1007/978-3-540-45146-4_8.pdf - - // - [BBBPWM] Bulletproofs: Short Proofs for Confidential Transactions and More - // Benedikt Bünz, Jonathan Bootle, Dan Boneh, Andrew Poelstra, Pieter Wuille and Greg Maxwell, IEEE - // https://eprint.iacr.org/2017/1066.pdf - - // # Implementation - // S&P 2018 validaity https://github.com/ZenGo-X/dlog-verifiable-enc #[pallet::call_index(0)] #[pallet::weight((Weight::zero(), DispatchClass::Normal, Pays::No))] pub fn send_decrypted_weights( @@ -55,19 +41,16 @@ pub mod dispatches { ); // If this was a forced rotation send, clear the rotating_from field - match forced_send_by_rotation { - true => { - ensure!( - matches!(decryption_data.rotating_from, Some(ref rotating_from) if acc_id == *rotating_from), - Error::::InvalidDecryptionKey - ); - } - false => { - ensure!( - decryption_data.node_id == acc_id, - Error::::InvalidDecryptionKey - ); - } + if forced_send_by_rotation { + ensure!( + matches!(decryption_data.rotating_from, Some(ref rotating_from) if acc_id == *rotating_from), + Error::::InvalidDecryptionKey + ); + } else { + ensure!( + decryption_data.node_id == acc_id, + Error::::InvalidDecryptionKey + ); } log::info!( diff --git a/pallets/offworker/src/lib.rs b/pallets/offworker/src/lib.rs index 5990cb9bd..ae24a69d0 100644 --- a/pallets/offworker/src/lib.rs +++ b/pallets/offworker/src/lib.rs @@ -53,22 +53,8 @@ mod profitability; pub mod types; mod util; -/// Defines application identifier for crypto keys of this module. -/// -/// Every module that deals with signatures needs to declare its unique identifier for -/// its crypto keys. -/// When offchain worker is signing transactions it's going to request keys of type -/// `KeyTypeId` from the keystore and use the ones it finds to sign the transaction. -/// The keys can be inserted manually via RPC (see `author_insertKey`). pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"wcs!"); -/// Cryptography configuration for pallet. -/// -/// Based on the above `KeyTypeId` we need to generate a -/// pallet-specific crypto type wrappers. -/// We can use from supported crypto kinds -/// (`sr25519`, `ed25519` and `ecdsa`) and augment -/// the types with this pallet-specific identifier. pub mod crypto { use super::KEY_TYPE; use alloc::string::String;