Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NFT bridge interface #19

Merged
merged 6 commits into from
Apr 3, 2024
Merged

Add NFT bridge interface #19

merged 6 commits into from
Apr 3, 2024

Conversation

sisyphusSmiling
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling commented Mar 15, 2024

Description

Introduces a Bridge interface (IFlowEVMNFTBridge) which is implemented in the main bridging contract (FlowEVMBridge). This enables central bridging events from any implementing contract identifying the asset bridged, the bridge address, and the recipient/requestor of the bridge request. This interface is then leveraged in EVMBridgeRouter which direct calls from EVM.CadenceOwnedAccounts to the named bridge contract.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@sisyphusSmiling sisyphusSmiling changed the title Add bridge interface Add NFT bridge interface Mar 15, 2024
@sisyphusSmiling sisyphusSmiling force-pushed the add-bridge-interface branch 2 times, most recently from 4755a6c to 516ecc6 Compare March 18, 2024 22:21
@sisyphusSmiling sisyphusSmiling changed the base branch from refactor-evm to main March 19, 2024 20:52
@sisyphusSmiling sisyphusSmiling self-assigned this Mar 19, 2024
@sisyphusSmiling sisyphusSmiling marked this pull request as ready for review March 19, 2024 20:52
@sisyphusSmiling sisyphusSmiling requested a review from a team as a code owner March 19, 2024 20:52
Copy link
Contributor

@aishairzay aishairzay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good! Only left one small comment.

For simplicity purposes of the EVM bridge as a whole though, are we sure we want to allow other bridges to emit these exact same events?

Is there a use-case inspiring this, or is it just to allow for future similar use-cases? Are there some risks we're introducing from this, or is the guidance that consumers can just filter based on contract address and its all good?

evmContractAddress: FlowEVMBridgeUtils.getEVMAddressAsHexString(
address: self.getAssociatedEVMAddress(with: result.getType())
?? panic("Could not find EVM Contract address associated with provided NFT")
), bridgeAddress: self.account.address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have the bridgeContractName field here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity purposes of the EVM bridge as a whole though, are we sure we want to allow other bridges to emit these exact same events?

Is there a use-case inspiring this, or is it just to allow for future similar use-cases? Are there some risks we're introducing from this, or is the guidance that consumers can just filter based on contract address and its all good?

It's a good question. I don't think we'd need to worry about other contracts impersonating the central bridge since listeners could filter on bridgeAddress which the interface guarantees will be accurate. Curious if anyone can think of vulnerabilities this might introduce.

Regarding use case - I thought it would be helpful at minimum which prototyping the bridge on Previewnet. In the event we need to deploy updates to a new account, listeners could just filter on the updated address. Ideally, we'd get visibility into all assets bridging between VMs with this interface, but the reversion on evmContractAddress likely limits the usefulness of this interface to just this public infra bridge.

Should we also have the bridgeContractName field here?

I'm not sure there's a way to dynamically retrieve the contract name from within the contract at runtime 🤔 But I could see it being helpful.

Copy link
Member

@joshuahannan joshuahannan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Just a few small comments

fun bridgeNFTToEVM(
token: @{NonFungibleToken.NFT},
to: EVM.EVMAddress,
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put a pre-condition in these to make sure the Provider has sufficient balance? And it has to be a FlowToken provider, right? Maybe we can have a pre-condition to validate that also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. The difficulty is that when bridging an NFT to EVM, the NFT fee will be dynamically calculated based on the storage it consumes. Calculating that fee requires saving the NFT which is not a view method and so couldn't be added to a pre-condition

owner: EVM.EVMAddress,
type: Type,
id: UInt256,
feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments about pre-conditions here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in some of the functions when you cast to a FlowToken.Vault, if it isn't FlowToken, then you'll just get an Error that isn't helpful. Might be good to have a better error message that says that the provider is the incorrect type

cadence/contracts/bridge/FlowEVMBridge.cdc Outdated Show resolved Hide resolved
evmID: evmID,
to: FlowEVMBridgeUtils.getEVMAddressAsHexString(address: to),
evmContractAddress: FlowEVMBridgeUtils.getEVMAddressAsHexString(address:associatedAddress)
)
}

/// Public entrypoint to bridge NFTs from EVM to Cadence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have calldata listed as a parameter here, but I don't see it in the actual function definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch. I'll clean up params upstream to prevent merge conflicts in the stacked PRs.

Copy link
Member

@nvdtf nvdtf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Co-authored-by: Joshua Hannan <joshua.hannan@flowfoundation.org>
@sisyphusSmiling sisyphusSmiling merged commit 5ebf96c into main Apr 3, 2024
@sisyphusSmiling sisyphusSmiling deleted the add-bridge-interface branch April 26, 2024 16:51
@sisyphusSmiling sisyphusSmiling restored the add-bridge-interface branch April 26, 2024 16:51
@sisyphusSmiling sisyphusSmiling deleted the add-bridge-interface branch April 26, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants