From ba490437f49c468df60eb1710fef2f789177428b Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 14 Feb 2024 16:37:12 +0200 Subject: [PATCH] Modified verification and registration logic --- multisigverifier/src/lib.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/multisigverifier/src/lib.rs b/multisigverifier/src/lib.rs index a7896a46..410ff135 100644 --- a/multisigverifier/src/lib.rs +++ b/multisigverifier/src/lib.rs @@ -4,6 +4,7 @@ multiversx_sc::imports!(); #[multiversx_sc::contract] pub trait Multisigverifier: + bls_signature::BlsSignatureModule { #[init] fn init(&self, bls_pub_keys: MultiValueEncoded) { @@ -18,30 +19,36 @@ pub trait Multisigverifier: fn register_bridge_operations( &self, hash_of_hashes: ManagedBuffer, - hash_of_bridge_ops: ManagedBuffer, + hash_of_bridge_ops: MultiValueEncoded, signature: BlsSignature, - signature_data: &ManagedBuffer, ) { - let caller = self.blockchain().get_caller(); - let is_bls_valid = self.verify_bls_signature(signature_data, &signature, caller); + let is_bls_valid = self.verify_bls(hash_of_bridge_ops.clone(), &signature, caller); - if is_bls_valid { - self.operations_mapper().insert(hash_of_hashes.clone(), hash_of_bridge_ops); + if is_bls_valid { + for hash in hash_of_bridge_ops { + self.pending_operations_mapper().insert(hash); + } } } - fn verify_bls_signature( + fn verify_bls ( &self, - signature_data: &ManagedBuffer, + transactions: MultiValueEncoded, signature: &BlsSignature, user: ManagedAddress ) -> bool { + let mut serialized_signature_data = ManagedBuffer::new(); + for transaction in transactions.into_iter() { + let _ = transaction.dep_encode(&mut serialized_signature_data); + } + let is_bls_valid = self.crypto().verify_bls( user.as_managed_buffer(), - signature_data, + &serialized_signature_data, signature.as_managed_buffer() ); + let signatures_count = self.signatures().get(); let bls_pub_keys = self.bls_pub_keys().get_user_count() as u32; @@ -65,5 +72,5 @@ pub trait Multisigverifier: fn signatures(&self) -> SingleValueMapper; #[storage_mapper("operations_mapper")] - fn operations_mapper(&self) -> MapMapper; + fn pending_operations_mapper(&self) -> SetMapper; }