diff --git a/multisigverifier/Cargo.lock b/multisigverifier/Cargo.lock index d7f66c8d..11e65e7e 100644 --- a/multisigverifier/Cargo.lock +++ b/multisigverifier/Cargo.lock @@ -226,14 +226,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chain-config" -version = "0.0.0" -dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", -] - [[package]] name = "clap" version = "4.4.18" @@ -499,38 +491,12 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "esdt-safe" -version = "0.0.0" -dependencies = [ - "bls-signature", - "fee-market", - "max-bridged-amount-module", - "multiversx-sc", - "multiversx-sc-modules", - "setup-phase", - "token-whitelist", - "transaction", - "tx-batch-module", - "utils", -] - [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" -[[package]] -name = "fee-market" -version = "0.0.0" -dependencies = [ - "bls-signature", - "multiversx-sc", - "transaction", - "utils", -] - [[package]] name = "fiat-crypto" version = "0.2.5" @@ -903,13 +869,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "max-bridged-amount-module" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "memchr" version = "2.7.1" @@ -947,12 +906,9 @@ name = "multisigverifier" version = "0.0.0" dependencies = [ "bls-signature", - "chain-config", - "esdt-safe", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", - "setup-phase", "transaction", ] @@ -1080,15 +1036,6 @@ dependencies = [ "zip", ] -[[package]] -name = "multiversx-sc-modules" -version = "0.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "multiversx-sc-scenario" version = "0.46.1" @@ -1671,13 +1618,6 @@ dependencies = [ "serde", ] -[[package]] -name = "setup-phase" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "sha2" version = "0.10.8" @@ -1824,16 +1764,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "token-whitelist" -version = "0.0.0" -dependencies = [ - "bls-signature", - "multiversx-sc", - "setup-phase", - "utils", -] - [[package]] name = "tokio" version = "1.35.1" @@ -1961,14 +1891,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tx-batch-module" -version = "0.0.0" -dependencies = [ - "multiversx-sc", - "transaction", -] - [[package]] name = "typenum" version = "1.17.0" @@ -2019,14 +1941,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "utils" -version = "0.0.0" -dependencies = [ - "bls-signature", - "multiversx-sc", -] - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/multisigverifier/Cargo.toml b/multisigverifier/Cargo.toml index 1739af4e..b9fd221d 100644 --- a/multisigverifier/Cargo.toml +++ b/multisigverifier/Cargo.toml @@ -17,15 +17,6 @@ path = '../common/bls-signature' [dependencies.transaction] path = '../common/transaction' -[dependencies.setup-phase] -path = '../common/setup-phase' - -[dependencies.esdt-safe] -path = '../esdt-safe' - -[dependencies.chain-config] -path = '../chain-config' - [dev-dependencies] num-bigint = "0.4.2" diff --git a/multisigverifier/src/lib.rs b/multisigverifier/src/lib.rs index 10efef28..c294e6ed 100644 --- a/multisigverifier/src/lib.rs +++ b/multisigverifier/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + use bls_signature::BlsSignature; use transaction::TransferData; @@ -17,27 +19,25 @@ pub trait Multisigverifier: #[endpoint(registerBridgeOps)] fn register_bridge_operations( &self, - hash_of_hashes: ManagedBuffer, - hash_of_bridge_ops: MultiValueEncoded, + bridge_operations_hash: ManagedBuffer, signature: BlsSignature, - transfers_data: MultiValueEncoded> + bridge_operations: MultiValueEncoded> ) { let caller = self.blockchain().get_caller(); - let is_bls_valid = self.verify_bls(hash_of_bridge_ops.clone(), &signature, caller); + let is_bls_valid = self.verify_bls(&signature, caller, bridge_operations.clone()); let mut serialized_transferred_data = ManagedBuffer::new(); - for transfer in transfers_data { - if let core::result::Result::Err(err) = transfer.top_encode(&mut serialized_transferred_data) { + for operation in bridge_operations { + if let core::result::Result::Err(err) = operation.top_encode(&mut serialized_transferred_data) { sc_panic!("Transfer data encode error: {}", err.message_bytes()); } - } - + } let transfers_data_sha256 = self.crypto().sha256(&serialized_transferred_data); let transfers_data_hash = transfers_data_sha256.as_managed_buffer(); require!( - hash_of_hashes.eq(transfers_data_hash), - "Hash of all operations doesn't match the hash of transfer " + bridge_operations_hash.eq(transfers_data_hash), + "Hash of all operations doesn't match the hash of transfer data" ); require!( @@ -45,20 +45,19 @@ pub trait Multisigverifier: "BLS signature is not valid" ); - for hash in hash_of_bridge_ops { - self.pending_operations_mapper().insert(hash); - } + self.pending_operations().insert(bridge_operations_hash); } fn verify_bls ( &self, - transactions: MultiValueEncoded, signature: &BlsSignature, - user: ManagedAddress + user: ManagedAddress, + bridge_operations: MultiValueEncoded>, ) -> bool { let mut serialized_signature_data = ManagedBuffer::new(); - for transaction in transactions.into_iter() { - let _ = transaction.dep_encode(&mut serialized_signature_data); + + for operation in bridge_operations.into_iter() { + let _ = operation.dep_encode(&mut serialized_signature_data); } let is_bls_valid = self.crypto().verify_bls( @@ -67,10 +66,10 @@ pub trait Multisigverifier: signature.as_managed_buffer() ); - self.calculate_validity_formula(is_bls_valid) + self.is_signature_valid_and_approved(is_bls_valid) } - fn calculate_validity_formula(&self, is_bls_valid: bool) -> bool { + fn is_signature_valid_and_approved(&self, is_bls_valid: bool) -> bool { let signatures_count = self.signatures().get(); let bls_pub_keys = self.bls_pub_keys().len() as u32; let minimum_signatures = 2 * bls_pub_keys / 3; @@ -89,5 +88,5 @@ pub trait Multisigverifier: fn signatures(&self) -> SingleValueMapper; #[storage_mapper("operations_mapper")] - fn pending_operations_mapper(&self) -> UnorderedSetMapper; + fn pending_operations(&self) -> UnorderedSetMapper; }