From 639da9fdd4154782c945089549e38bf325b120d2 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 9 Jul 2024 12:46:30 -0600 Subject: [PATCH] add type assertions when bridging assets to ensure accurate execution --- cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc | 6 ++++++ .../bridge/nft/bridge_nft_to_any_cadence_address.cdc | 6 ++++++ .../bridge/nft/bridge_nft_to_any_evm_address.cdc | 6 ++++++ cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc | 6 ++++++ .../transactions/bridge/tokens/bridge_tokens_from_evm.cdc | 2 ++ .../bridge/tokens/bridge_tokens_to_any_cadence_address.cdc | 2 ++ .../bridge/tokens/bridge_tokens_to_any_evm_address.cdc | 3 +++ cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc | 6 ++++++ 8 files changed, 37 insertions(+) diff --git a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc index 01bf3157..3e813a43 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc @@ -92,6 +92,12 @@ transaction(nftIdentifier: String, id: UInt256) { id: id, feeProvider: &self.scopedProvider as auth(FungibleToken.Withdraw) &{FungibleToken.Provider} ) + // Ensure the bridged nft is the correct type + assert( + nft.getType() == self.nftType, + message: "Bridged nft type mismatch - requeswted: ".concat(self.nftType.identifier) + .concat(", received: ").concat(nft.getType().identifier) + ) // Deposit the bridged NFT into the signer's collection self.collection.deposit(token: <-nft) // Destroy the ScopedFTProvider diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc index 63bb9669..2c3f3aa3 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_cadence_address.cdc @@ -95,6 +95,12 @@ transaction(nftIdentifier: String, id: UInt256, recipient: Address) { id: id, feeProvider: &self.scopedProvider as auth(FungibleToken.Withdraw) &{FungibleToken.Provider} ) + // Ensure the bridged nft is the correct type + assert( + nft.getType() == self.nftType, + message: "Bridged nft type mismatch - requeswted: ".concat(self.nftType.identifier) + .concat(", received: ").concat(nft.getType().identifier) + ) // Deposit the bridged NFT into the signer's collection self.receiver.deposit(token: <-nft) // Destroy the ScopedFTProvider diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc index 858fc713..2a33a33e 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_any_evm_address.cdc @@ -86,6 +86,12 @@ transaction(nftIdentifier: String, id: UInt64, recipient: String) { ) } + pre { + self.nft.getType().identifier == nftIdentifier: + "Attempting to send invalid nft type - requested: ".concat(nftIdentifier) + .concat(", sending: ").concat(self.nft.getType().identifier) + } + execute { if self.requiresOnboarding { // Onboard the NFT to the bridge diff --git a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc index 2a18426a..82986f80 100644 --- a/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc +++ b/cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc @@ -93,6 +93,12 @@ transaction(nftIdentifier: String, id: UInt64) { ) } + pre { + self.nft.getType().identifier == nftIdentifier: + "Attempting to send invalid nft type - requested: ".concat(nftIdentifier) + .concat(", sending: ").concat(self.nft.getType().identifier) + } + execute { if self.requiresOnboarding { // Onboard the NFT to the bridge diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc index 33e099c1..738205f4 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc @@ -102,6 +102,8 @@ transaction(vaultIdentifier: String, amount: UInt256) { amount: amount, feeProvider: &self.scopedProvider as auth(FungibleToken.Withdraw) &{FungibleToken.Provider} ) + // Ensure the bridged vault is the correct type + assert(vault.getType() == self.vaultType, message: "Bridged vault type mismatch") // Deposit the bridged token into the signer's vault self.receiver.deposit(from: <-vault) // Destroy the ScopedFTProvider diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc index 038e0094..ed576a31 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_cadence_address.cdc @@ -105,6 +105,8 @@ transaction(vaultIdentifier: String, amount: UInt256, recipient: Address) { amount: amount, feeProvider: &self.scopedProvider as auth(FungibleToken.Withdraw) &{FungibleToken.Provider} ) + // Ensure the bridged vault is the correct type + assert(vault.getType() == self.vaultType, message: "Bridged vault type mismatch") // Deposit the bridged token into the signer's vault self.receiver.deposit(from: <-vault) // Destroy the ScopedFTProvider diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc index 69c7de0c..e967e8f5 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_any_evm_address.cdc @@ -91,6 +91,9 @@ transaction(vaultIdentifier: String, amount: UFix64, recipient: String) { } pre { + self.sentVault.getType().identifier == vaultIdentifier: + "Attempting to send invalid vault type - requested: ".concat(vaultIdentifier) + .concat(", sending: ").concat(self.sentVault.getType().identifier) self.sentVault.balance == amount: "Amount to be transferred does not match the requested amount" } diff --git a/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc b/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc index 0938b341..6fc0dd6d 100644 --- a/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc +++ b/cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc @@ -94,6 +94,12 @@ transaction(vaultIdentifier: String, amount: UFix64) { ) } + pre { + self.sentVault.getType().identifier == vaultIdentifier: + "Attempting to send invalid vault type - requested: ".concat(vaultIdentifier) + .concat(", sending: ").concat(self.sentVault.getType().identifier) + } + execute { if self.requiresOnboarding { // Onboard the Vault to the bridge