From 7a27621b833083b102a2cf88a18721d1cbfedf4e Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Fri, 12 Apr 2024 15:46:17 -0500 Subject: [PATCH 01/11] add bridging interface to COA --- fvm/evm/stdlib/contract.cdc | 110 ++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index c3b7fb3a52f..2e453f89d24 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -1,4 +1,6 @@ import Crypto +import "NonFungibleToken" +import "FungibleToken" import "FlowToken" access(all) @@ -288,6 +290,59 @@ contract EVM { value: value.attoflow ) as! Result } + + /// Bridges the given NFT to the EVM environment, requiring a Provider from which to withdraw a fee to fulfill + /// the bridge request + access(all) + fun depositNFT( + nft: @{NonFungibleToken.NFT}, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ) { + EVM.borrowBridgeAccessor().depositNFT(nft: <-nft, to: self.address(), feeProvider: feeProvider) + } + + /// Bridges the given NFT from the EVM environment, requiring a Provider from which to withdraw a fee to fulfill + /// the bridge request. Note: the caller should own the requested NFT in EVM + access(Owner | Bridge) + fun withdrawNFT( + type: Type, + id: UInt256, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ): @{NonFungibleToken.NFT} { + return <- EVM.borrowBridgeAccessor().withdrawNFT( + caller: &self as auth(Call) &CadenceOwnedAccount, + type: type, + id: id, + feeProvider: feeProvider + ) + } + + /// Bridges the given Vault to the EVM environment, requiring a Provider from which to withdraw a fee to fulfill + /// the bridge request + access(all) + fun depositTokens( + vault: @{FungibleToken.Vault}, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ) { + EVM.borrowBridgeAccessor().depositTokens(vault: <-vault, to: self.address(), feeProvider: feeProvider) + } + + /// Bridges the given fungible tokens from the EVM environment, requiring a Provider from which to withdraw a + /// fee to fulfill the bridge request. Note: the caller should own the requested tokens & sufficient balance of + /// requested tokens in EVM + access(Owner | Bridge) + fun withdrawTokens( + type: Type, + amount: UInt256, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ): @{FungibleToken.Vault} { + return <- EVM.borrowBridgeAccessor().withdrawTokens( + caller: &self as auth(Call) &CadenceOwnedAccount, + type: type, + amount: amount, + feeProvider: feeProvider + ) + } } /// Creates a new cadence owned account @@ -488,4 +543,59 @@ contract EVM { fun getLatestBlock(): EVMBlock { return InternalEVM.getLatestBlock() as! EVMBlock } + + /// Interface for a resource which acts as an entrypoint to the VM bridge + access(all) + resource interface BridgeAccessor { + + /// Endpoint enabling the bridging of an NFT to EVM + access(Bridge) + fun depositNFT( + nft: @{NonFungibleToken.NFT}, + to: EVMAddress, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ) + + /// Endpoint enabling the bridging of an NFT from EVM + access(Bridge) + fun withdrawNFT( + caller: auth(Call) &CadenceOwnedAccount, + type: Type, + id: UInt256, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ): @{NonFungibleToken.NFT} + + /// Endpoint enabling the bridging of a fungible token vault to EVM + access(Bridge) + fun depositTokens( + vault: @{FungibleToken.Vault}, + to: EVMAddress, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ) + + /// Endpoint enabling the bridging of fungible tokens from EVM + access(Bridge) + fun withdrawTokens( + caller: auth(Call) &CadenceOwnedAccount, + type: Type, + amount: UInt256, + feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + ): @{FungibleToken.Vault} + } + + /// Interface which captures a Capability to the bridge Accessor, saving it within the BridgeRouter resource + access(all) + resource interface BridgeRouter { + + /// Returns a reference to the BridgeAccessor designated for internal bridge requests + access(Bridge) view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor} + } + + /// Returns a reference to the BridgeAccessor designated for internal bridge requests + access(self) + view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor} { + return self.account.storage.borrow(from: /storage/evmBridgeRouter) + ?.borrowBridgeAccessor() + ?? panic("Could not borrow reference to the EVM bridge") + } } From b8d0d830c92fcb218db37df989a06bf464907375 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:59:33 -0500 Subject: [PATCH 02/11] fix updated EVM dependency aliasing --- fvm/bootstrap.go | 4 ++-- fvm/evm/stdlib/contract.go | 19 +++++++++++++++---- fvm/evm/stdlib/contract_test.go | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/fvm/bootstrap.go b/fvm/bootstrap.go index 7ce37e0828b..fbf875b8827 100644 --- a/fvm/bootstrap.go +++ b/fvm/bootstrap.go @@ -806,7 +806,7 @@ func (b *bootstrapExecutor) setStakingAllowlist( panicOnMetaInvokeErrf("failed to set staking allow-list: %s", txError, err) } -func (b *bootstrapExecutor) setupEVM(serviceAddress, fungibleTokenAddress, flowTokenAddress flow.Address) { +func (b *bootstrapExecutor) setupEVM(serviceAddress, nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress flow.Address) { if b.setupEVMEnabled { // account for storage // we dont need to deploy anything to this account, but it needs to exist @@ -817,7 +817,7 @@ func (b *bootstrapExecutor) setupEVM(serviceAddress, fungibleTokenAddress, flowT // deploy the EVM contract to the service account tx := blueprints.DeployContractTransaction( serviceAddress, - stdlib.ContractCode(flowTokenAddress), + stdlib.ContractCode(nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress), stdlib.ContractName, ) // WithEVMEnabled should only be used after we create an account for storage diff --git a/fvm/evm/stdlib/contract.go b/fvm/evm/stdlib/contract.go index c9e62317a8b..7178d3ecc2f 100644 --- a/fvm/evm/stdlib/contract.go +++ b/fvm/evm/stdlib/contract.go @@ -27,13 +27,24 @@ import ( //go:embed contract.cdc var contractCode string -var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"\n`) +var nftImportPattern = regexp.MustCompile(`(?m)^import "NonFungibleToken"`) +var fungibleTokenImportPattern = regexp.MustCompile(`(?m)^import "FungibleToken"`) +var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"`) -func ContractCode(flowTokenAddress flow.Address) []byte { - return []byte(flowTokenImportPattern.ReplaceAllString( +func ContractCode(nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress flow.Address) []byte { + contractCode = nftImportPattern.ReplaceAllString( + contractCode, + fmt.Sprintf("import NonFungibleToken from %s", nonFungibleTokenAddress.HexWithPrefix()), + ) + contractCode = fungibleTokenImportPattern.ReplaceAllString( + contractCode, + fmt.Sprintf("import FungibleToken from %s", fungibleTokenAddress.HexWithPrefix()), + ) + contractCode = flowTokenImportPattern.ReplaceAllString( contractCode, fmt.Sprintf("import FlowToken from %s", flowTokenAddress.HexWithPrefix()), - )) + ) + return []byte(contractCode) } const ContractName = "EVM" diff --git a/fvm/evm/stdlib/contract_test.go b/fvm/evm/stdlib/contract_test.go index f92cb52ab68..2af947436f2 100644 --- a/fvm/evm/stdlib/contract_test.go +++ b/fvm/evm/stdlib/contract_test.go @@ -223,7 +223,7 @@ func deployContracts( }, { name: stdlib.ContractName, - code: stdlib.ContractCode(contractsAddress), + code: stdlib.ContractCode(contractsAddress, contractsAddress, contractsAddress), }, } From 45038251418c340baa9a4267ce7b4a646eedee60 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Mon, 15 Apr 2024 18:18:56 -0500 Subject: [PATCH 03/11] update EVM bridging interfaces for Cadence 0.42 --- fvm/evm/stdlib/contract.cdc | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index 2e453f89d24..c264fe1b85d 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -296,7 +296,7 @@ contract EVM { access(all) fun depositNFT( nft: @{NonFungibleToken.NFT}, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ) { EVM.borrowBridgeAccessor().depositNFT(nft: <-nft, to: self.address(), feeProvider: feeProvider) } @@ -307,10 +307,10 @@ contract EVM { fun withdrawNFT( type: Type, id: UInt256, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ): @{NonFungibleToken.NFT} { return <- EVM.borrowBridgeAccessor().withdrawNFT( - caller: &self as auth(Call) &CadenceOwnedAccount, + caller: &self, type: type, id: id, feeProvider: feeProvider @@ -322,7 +322,7 @@ contract EVM { access(all) fun depositTokens( vault: @{FungibleToken.Vault}, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ) { EVM.borrowBridgeAccessor().depositTokens(vault: <-vault, to: self.address(), feeProvider: feeProvider) } @@ -334,10 +334,10 @@ contract EVM { fun withdrawTokens( type: Type, amount: UInt256, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ): @{FungibleToken.Vault} { return <- EVM.borrowBridgeAccessor().withdrawTokens( - caller: &self as auth(Call) &CadenceOwnedAccount, + caller: &self, type: type, amount: amount, feeProvider: feeProvider @@ -549,37 +549,37 @@ contract EVM { resource interface BridgeAccessor { /// Endpoint enabling the bridging of an NFT to EVM - access(Bridge) + access(all) fun depositNFT( nft: @{NonFungibleToken.NFT}, to: EVMAddress, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ) /// Endpoint enabling the bridging of an NFT from EVM - access(Bridge) + access(all) fun withdrawNFT( - caller: auth(Call) &CadenceOwnedAccount, + caller: &CadenceOwnedAccount, type: Type, id: UInt256, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ): @{NonFungibleToken.NFT} /// Endpoint enabling the bridging of a fungible token vault to EVM - access(Bridge) + access(all) fun depositTokens( vault: @{FungibleToken.Vault}, to: EVMAddress, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ) /// Endpoint enabling the bridging of fungible tokens from EVM - access(Bridge) + access(all) fun withdrawTokens( - caller: auth(Call) &CadenceOwnedAccount, + caller: &CadenceOwnedAccount, type: Type, amount: UInt256, - feeProvider: auth(FungibleToken.Withdraw) &{FungibleToken.Provider} + feeProvider: &{FungibleToken.Provider} ): @{FungibleToken.Vault} } @@ -588,13 +588,13 @@ contract EVM { resource interface BridgeRouter { /// Returns a reference to the BridgeAccessor designated for internal bridge requests - access(Bridge) view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor} + access(all) view fun borrowBridgeAccessor(): &{BridgeAccessor} } /// Returns a reference to the BridgeAccessor designated for internal bridge requests access(self) - view fun borrowBridgeAccessor(): auth(Bridge) &{BridgeAccessor} { - return self.account.storage.borrow(from: /storage/evmBridgeRouter) + view fun borrowBridgeAccessor(): &{BridgeAccessor} { + return self.account.borrow<&{BridgeRouter}>(from: /storage/evmBridgeRouter) ?.borrowBridgeAccessor() ?? panic("Could not borrow reference to the EVM bridge") } From 0a99512b1ecf3299f000b33e963877134fa63ac2 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Mon, 15 Apr 2024 19:01:26 -0500 Subject: [PATCH 04/11] remove entitlement from EVM & fix bootstrap --- fvm/bootstrap.go | 2 +- fvm/evm/stdlib/contract.cdc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fvm/bootstrap.go b/fvm/bootstrap.go index fbf875b8827..858fea9d9b6 100644 --- a/fvm/bootstrap.go +++ b/fvm/bootstrap.go @@ -392,7 +392,7 @@ func (b *bootstrapExecutor) Execute() error { b.setStakingAllowlist(service, b.identities.NodeIDs()) // sets up the EVM environment - b.setupEVM(service, fungibleToken, flowToken) + b.setupEVM(service, nonFungibleToken, fungibleToken, flowToken) return nil } diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index c264fe1b85d..ce15d5a417e 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -303,7 +303,7 @@ contract EVM { /// Bridges the given NFT from the EVM environment, requiring a Provider from which to withdraw a fee to fulfill /// the bridge request. Note: the caller should own the requested NFT in EVM - access(Owner | Bridge) + access(all) fun withdrawNFT( type: Type, id: UInt256, @@ -330,7 +330,7 @@ contract EVM { /// Bridges the given fungible tokens from the EVM environment, requiring a Provider from which to withdraw a /// fee to fulfill the bridge request. Note: the caller should own the requested tokens & sufficient balance of /// requested tokens in EVM - access(Owner | Bridge) + access(all) fun withdrawTokens( type: Type, amount: UInt256, From 9ce40e2fb7510d8e42a9939f7025d7d44bffebde Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:18:43 -0500 Subject: [PATCH 05/11] fix casting statement in EVM contract --- fvm/evm/stdlib/contract.cdc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index ce15d5a417e..45a9dca6042 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -310,7 +310,7 @@ contract EVM { feeProvider: &{FungibleToken.Provider} ): @{NonFungibleToken.NFT} { return <- EVM.borrowBridgeAccessor().withdrawNFT( - caller: &self, + caller: &self as &CadenceOwnedAccount, type: type, id: id, feeProvider: feeProvider @@ -337,7 +337,7 @@ contract EVM { feeProvider: &{FungibleToken.Provider} ): @{FungibleToken.Vault} { return <- EVM.borrowBridgeAccessor().withdrawTokens( - caller: &self, + caller: &self as &CadenceOwnedAccount, type: type, amount: amount, feeProvider: feeProvider From ccc99ec43c5b17dc0d8018aa8b0006077d569126 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:28:44 -0500 Subject: [PATCH 06/11] fix accepted NFT & Vault conformance types in EVM contract --- fvm/evm/stdlib/contract.cdc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index 45a9dca6042..b70f5f90d3a 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -295,7 +295,7 @@ contract EVM { /// the bridge request access(all) fun depositNFT( - nft: @{NonFungibleToken.NFT}, + nft: @NonFungibleToken.NFT, feeProvider: &{FungibleToken.Provider} ) { EVM.borrowBridgeAccessor().depositNFT(nft: <-nft, to: self.address(), feeProvider: feeProvider) @@ -308,7 +308,7 @@ contract EVM { type: Type, id: UInt256, feeProvider: &{FungibleToken.Provider} - ): @{NonFungibleToken.NFT} { + ): @NonFungibleToken.NFT { return <- EVM.borrowBridgeAccessor().withdrawNFT( caller: &self as &CadenceOwnedAccount, type: type, @@ -321,7 +321,7 @@ contract EVM { /// the bridge request access(all) fun depositTokens( - vault: @{FungibleToken.Vault}, + vault: @FungibleToken.Vault, feeProvider: &{FungibleToken.Provider} ) { EVM.borrowBridgeAccessor().depositTokens(vault: <-vault, to: self.address(), feeProvider: feeProvider) @@ -335,7 +335,7 @@ contract EVM { type: Type, amount: UInt256, feeProvider: &{FungibleToken.Provider} - ): @{FungibleToken.Vault} { + ): @FungibleToken.Vault { return <- EVM.borrowBridgeAccessor().withdrawTokens( caller: &self as &CadenceOwnedAccount, type: type, @@ -551,7 +551,7 @@ contract EVM { /// Endpoint enabling the bridging of an NFT to EVM access(all) fun depositNFT( - nft: @{NonFungibleToken.NFT}, + nft: @NonFungibleToken.NFT, to: EVMAddress, feeProvider: &{FungibleToken.Provider} ) @@ -563,12 +563,12 @@ contract EVM { type: Type, id: UInt256, feeProvider: &{FungibleToken.Provider} - ): @{NonFungibleToken.NFT} + ): @NonFungibleToken.NFT /// Endpoint enabling the bridging of a fungible token vault to EVM access(all) fun depositTokens( - vault: @{FungibleToken.Vault}, + vault: @FungibleToken.Vault, to: EVMAddress, feeProvider: &{FungibleToken.Provider} ) @@ -580,7 +580,7 @@ contract EVM { type: Type, amount: UInt256, feeProvider: &{FungibleToken.Provider} - ): @{FungibleToken.Vault} + ): @FungibleToken.Vault } /// Interface which captures a Capability to the bridge Accessor, saving it within the BridgeRouter resource From 809c541f85c3f97a7eef0395caedc79f9f2b7e6c Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:53:54 -0500 Subject: [PATCH 07/11] fix change_contract_code_migration --- .../ledger/migrations/change_contract_code_migration.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/util/ledger/migrations/change_contract_code_migration.go b/cmd/util/ledger/migrations/change_contract_code_migration.go index c2715bdc8d0..f21f3b43c4f 100644 --- a/cmd/util/ledger/migrations/change_contract_code_migration.go +++ b/cmd/util/ledger/migrations/change_contract_code_migration.go @@ -326,7 +326,11 @@ func SystemContractChanges(chainID flow.ChainID) []SystemContractChange { // EVM related contracts NewSystemContractChange( systemContracts.EVMContract, - evm.ContractCode(systemContracts.FlowToken.Address), + evm.ContractCode( + systemContracts.NonFungibleToken.Address, + systemContracts.FungibleToken.Address, + systemContracts.FlowToken.Address, + ), ), } } From cb42dc5656f9e28ea71945c21d80841f30218cb0 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:32:34 -0500 Subject: [PATCH 08/11] commit fvm_test.go patch thanks to @m-peter --- fvm/fvm_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fvm/fvm_test.go b/fvm/fvm_test.go index 900a9f7a56f..fa8c52306c8 100644 --- a/fvm/fvm_test.go +++ b/fvm/fvm_test.go @@ -3065,6 +3065,7 @@ func TestEVM(t *testing.T) { withBootstrapProcedureOptions(fvm.WithSetupEVMEnabled(true)). withContextOptions( fvm.WithEVMEnabled(true), + fvm.WithChain(flow.Emulator.Chain()), fvm.WithCadenceLogging(true), ). run(func( @@ -3226,6 +3227,7 @@ func TestEVM(t *testing.T) { // so we have to use emulator here so that the EVM storage contract is deployed // to the 5th address fvm.WithChain(flow.Emulator.Chain()), + fvm.WithEVMEnabled(true), ). run(func( t *testing.T, From ade69c99594aba3e258542f42a7b01ec1f949856 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:31:40 -0500 Subject: [PATCH 09/11] fix stdlib.ContractCode var mutation scope pointed out by @m-peter --- fvm/evm/stdlib/contract.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fvm/evm/stdlib/contract.go b/fvm/evm/stdlib/contract.go index 7178d3ecc2f..95478c2f8bd 100644 --- a/fvm/evm/stdlib/contract.go +++ b/fvm/evm/stdlib/contract.go @@ -32,19 +32,19 @@ var fungibleTokenImportPattern = regexp.MustCompile(`(?m)^import "FungibleToken" var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"`) func ContractCode(nonFungibleTokenAddress, fungibleTokenAddress, flowTokenAddress flow.Address) []byte { - contractCode = nftImportPattern.ReplaceAllString( + evmContract := nftImportPattern.ReplaceAllString( contractCode, fmt.Sprintf("import NonFungibleToken from %s", nonFungibleTokenAddress.HexWithPrefix()), ) - contractCode = fungibleTokenImportPattern.ReplaceAllString( - contractCode, + evmContract = fungibleTokenImportPattern.ReplaceAllString( + evmContract, fmt.Sprintf("import FungibleToken from %s", fungibleTokenAddress.HexWithPrefix()), ) - contractCode = flowTokenImportPattern.ReplaceAllString( - contractCode, + evmContract = flowTokenImportPattern.ReplaceAllString( + evmContract, fmt.Sprintf("import FlowToken from %s", flowTokenAddress.HexWithPrefix()), ) - return []byte(contractCode) + return []byte(evmContract) } const ContractName = "EVM" From 78efce223123bca30ae3b1d8ccaa37f64898dbba Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:39:43 -0500 Subject: [PATCH 10/11] add BridgeAccessorUpdated event & BridgeAccessor setter to EVM contract --- fvm/evm/stdlib/contract.cdc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index b70f5f90d3a..e8f4b63c291 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -21,6 +21,19 @@ contract EVM { access(all) event FLOWTokensWithdrawn(addressBytes: [UInt8; 20], amount: UFix64) + /// BridgeAccessorUpdated is emitted when the BridgeAccessor Capability + /// is updated in the stored BridgeRouter along with identifying + /// information about both. + access(all) + event BridgeAccessorUpdated( + routerType: Type, + routerUUID: UInt64, + routerAddress: Address, + accessorType: Type, + accessorUUID: UInt64, + accessorAddress: Address + ) + /// EVMAddress is an EVM-compatible address access(all) struct EVMAddress { @@ -589,6 +602,13 @@ contract EVM { /// Returns a reference to the BridgeAccessor designated for internal bridge requests access(all) view fun borrowBridgeAccessor(): &{BridgeAccessor} + + /// Sets the BridgeAccessor Capability in the BridgeRouter + access(all) fun setBridgeAccessor(_ accessor: Capability<&{BridgeAccessor}>) { + pre { + accessor.check(): "Invalid BridgeAccessor Capability provided" + } + } } /// Returns a reference to the BridgeAccessor designated for internal bridge requests From 5aad29ee391c0b4b519f8196aac8b077bd87d166 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Wed, 17 Apr 2024 16:39:01 -0500 Subject: [PATCH 11/11] fix failing fvm tests --- fvm/fvm_test.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fvm/fvm_test.go b/fvm/fvm_test.go index 6812f0c9bfe..4cc9059cbdf 100644 --- a/fvm/fvm_test.go +++ b/fvm/fvm_test.go @@ -3071,6 +3071,9 @@ func TestEVM(t *testing.T) { ).Return(block1.Header, nil) ctxOpts := []fvm.Option{ + // default is testnet, but testnet has a special EVM storage contract location + // so we have to use emulator here so that the EVM storage contract is deployed + // to the 5th address fvm.WithChain(flow.Emulator.Chain()), fvm.WithEVMEnabled(true), fvm.WithBlocks(blocks), @@ -3226,15 +3229,8 @@ func TestEVM(t *testing.T) { ) t.Run("deploy contract code", newVMTest(). - withBootstrapProcedureOptions( - fvm.WithSetupEVMEnabled(true), - ). - withContextOptions( - // default is testnet, but testnet has a special EVM storage contract location - // so we have to use emulator here so that the EVM storage contract is deployed - // to the 5th address - fvm.WithChain(flow.Emulator.Chain()), - ). + withBootstrapProcedureOptions(fvm.WithSetupEVMEnabled(true)). + withContextOptions(ctxOpts...). run(func( t *testing.T, vm fvm.VM,