Skip to content

Commit

Permalink
Merge pull request #98 from onflow/add-identifier-validation
Browse files Browse the repository at this point in the history
Add type assertions when bridging assets
  • Loading branch information
sisyphusSmiling authored Jul 9, 2024
2 parents aed9fbb + 639da9f commit c27bdfd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cadence/transactions/bridge/nft/bridge_nft_from_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions cadence/transactions/bridge/nft/bridge_nft_to_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cadence/transactions/bridge/tokens/bridge_tokens_from_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
6 changes: 6 additions & 0 deletions cadence/transactions/bridge/tokens/bridge_tokens_to_evm.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c27bdfd

Please sign in to comment.