Skip to content

Commit

Permalink
fix: suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
functor-flow committed Dec 2, 2024
1 parent 09444bc commit cf4411a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 49 deletions.
13 changes: 5 additions & 8 deletions node/src/service/decrypter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Option<Vec<Vec<u8>>>>()?;
.map(|chunk| key.decrypt(Pkcs1v15Encrypt, chunk))
.collect::<Result<Vec<Vec<u8>>, _>>()
.ok()?;

let decrypted = vec.into_iter().flatten().collect::<Vec<_>>();

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)?;
Expand Down
37 changes: 10 additions & 27 deletions pallets/offworker/src/dispatches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ use frame_support::pallet_macros::pallet_section;
pub mod dispatches {
#[pallet::call]
impl<T: Config> Pallet<T> {
// 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(
Expand Down Expand Up @@ -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::<T>::InvalidDecryptionKey
);
}
false => {
ensure!(
decryption_data.node_id == acc_id,
Error::<T>::InvalidDecryptionKey
);
}
if forced_send_by_rotation {
ensure!(
matches!(decryption_data.rotating_from, Some(ref rotating_from) if acc_id == *rotating_from),
Error::<T>::InvalidDecryptionKey
);
} else {
ensure!(
decryption_data.node_id == acc_id,
Error::<T>::InvalidDecryptionKey
);
}

log::info!(
Expand Down
14 changes: 0 additions & 14 deletions pallets/offworker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cf4411a

Please sign in to comment.