diff --git a/fvm/evm/evm_test.go b/fvm/evm/evm_test.go index 1608ac9cf42..c369d1a8c67 100644 --- a/fvm/evm/evm_test.go +++ b/fvm/evm/evm_test.go @@ -108,9 +108,9 @@ func TestEVMAddressDeposit(t *testing.T) { let vault <- minter.mintTokens(amount: 1.23) destroy minter - let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.deposit(from: <-vault) - destroy bridgedAccount + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + cadenceOwnedAccount.deposit(from: <-vault) + destroy cadenceOwnedAccount } `, sc.EVMContract.Address.HexWithPrefix(), @@ -158,14 +158,14 @@ func TestCOAWithdraw(t *testing.T) { let vault <- minter.mintTokens(amount: 2.34) destroy minter - let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.deposit(from: <-vault) + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + cadenceOwnedAccount.deposit(from: <-vault) let bal = EVM.Balance(0) bal.setFLOW(flow: 1.23) - let vault2 <- bridgedAccount.withdraw(balance: bal) + let vault2 <- cadenceOwnedAccount.withdraw(balance: bal) let balance = vault2.balance - destroy bridgedAccount + destroy cadenceOwnedAccount destroy vault2 return balance @@ -190,7 +190,7 @@ func TestCOAWithdraw(t *testing.T) { }) } -func TestBridgedAccountDeploy(t *testing.T) { +func TestCadenceOwnedAccountDeploy(t *testing.T) { t.Parallel() chain := flow.Emulator.Chain() sc := systemcontracts.SystemContractsForChain(chain.ChainID()) @@ -215,15 +215,15 @@ func TestBridgedAccountDeploy(t *testing.T) { let vault <- minter.mintTokens(amount: 2.34) destroy minter - let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.deposit(from: <-vault) + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + cadenceOwnedAccount.deposit(from: <-vault) - let address = bridgedAccount.deploy( + let address = cadenceOwnedAccount.deploy( code: [], gasLimit: 53000, value: EVM.Balance(attoflow: 1230000000000000000) ) - destroy bridgedAccount + destroy cadenceOwnedAccount return address.bytes } `, @@ -330,11 +330,11 @@ func TestCadenceArch(t *testing.T) { transaction { prepare(account: AuthAccount) { - let bridgedAccount1 <- EVM.createBridgedAccount() - account.save<@EVM.BridgedAccount>(<-bridgedAccount1, - to: /storage/bridgedAccount) - account.link<&EVM.BridgedAccount{EVM.Addressable}>(/public/bridgedAccount, - target: /storage/bridgedAccount) + let cadenceOwnedAccount1 <- EVM.createCadenceOwnedAccount() + account.save<@EVM.CadenceOwnedAccount>(<-cadenceOwnedAccount1, + to: /storage/coa) + account.link<&EVM.CadenceOwnedAccount{EVM.Addressable}>(/public/coa, + target: /storage/coa) } } `, @@ -351,7 +351,7 @@ func TestCadenceArch(t *testing.T) { require.NoError(t, output.Err) snapshot = snapshot.Append(es) - // 3rd event is the bridged account created event + // 3rd event is the cadence owned account created event coaAddress, err := types.COAAddressFromFlowEvent(sc.EVMContract.Address, output.Events[2]) require.NoError(t, err) @@ -366,7 +366,7 @@ func TestCadenceArch(t *testing.T) { proof := types.COAOwnershipProof{ KeyIndices: []uint64{0}, Address: types.FlowAddress(account), - CapabilityPath: "bridgedAccount", + CapabilityPath: "coa", Signatures: []types.Signature{types.Signature(sig)}, } diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index dbcedbeb9a9..287fb908dc4 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -4,7 +4,7 @@ import "FlowToken" access(all) contract EVM { - pub event BridgedAccountCreated(addressBytes: [UInt8; 20]) + pub event CadenceOwnedAccountCreated(addressBytes: [UInt8; 20]) /// EVMAddress is an EVM-compatible address access(all) @@ -76,7 +76,7 @@ contract EVM { } access(all) - resource BridgedAccount: Addressable { + resource CadenceOwnedAccount: Addressable { access(self) var addressBytes: [UInt8; 20] @@ -85,7 +85,7 @@ contract EVM { // address is initially set to zero // but updated through initAddress later // we have to do this since we need resource id (uuid) - // to calculate the EVM address for this bridge account + // to calculate the EVM address for this cadence owned account self.addressBytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] } @@ -99,20 +99,20 @@ contract EVM { self.addressBytes = addressBytes } - /// The EVM address of the bridged account + /// The EVM address of the cadence owned account access(all) fun address(): EVMAddress { // Always create a new EVMAddress instance return EVMAddress(bytes: self.addressBytes) } - /// Get balance of the bridged account + /// Get balance of the cadence owned account access(all) fun balance(): Balance { return self.address().balance() } - /// Deposits the given vault into the bridged account's balance + /// Deposits the given vault into the cadence owned account's balance access(all) fun deposit(from: @FlowToken.Vault) { InternalEVM.deposit( @@ -121,7 +121,7 @@ contract EVM { ) } - /// Withdraws the balance from the bridged account's balance + /// Withdraws the balance from the cadence owned account's balance /// Note that amounts smaller than 10nF (10e-8) can't be withdrawn /// given that Flow Token Vaults use UFix64s to store balances. /// If the given balance conversion to UFix64 results in @@ -171,13 +171,13 @@ contract EVM { } } - /// Creates a new bridged account + /// Creates a new cadence owned account access(all) - fun createBridgedAccount(): @BridgedAccount { - let acc <-create BridgedAccount() - let addr = InternalEVM.createBridgedAccount(uuid: acc.uuid) + fun createCadenceOwnedAccount(): @CadenceOwnedAccount { + let acc <-create CadenceOwnedAccount() + let addr = InternalEVM.createCadenceOwnedAccount(uuid: acc.uuid) acc.initAddress(addressBytes: addr) - emit BridgedAccountCreated(addressBytes: addr) + emit CadenceOwnedAccountCreated(addressBytes: addr) return <-acc } @@ -281,8 +281,8 @@ contract EVM { assert(isValid, message: "signatures not valid") let coaRef = acc.getCapability(path) - .borrow<&EVM.BridgedAccount{EVM.Addressable}>() - ?? panic("could not borrow bridge account's address") + .borrow<&EVM.CadenceOwnedAccount{EVM.Addressable}>() + ?? panic("could not borrow coa resource addressable capability") // verify evm address matching var i = 0 diff --git a/fvm/evm/stdlib/contract.go b/fvm/evm/stdlib/contract.go index 2bc2b923209..dd0d0159286 100644 --- a/fvm/evm/stdlib/contract.go +++ b/fvm/evm/stdlib/contract.go @@ -1137,9 +1137,9 @@ func newInternalEVMTypeCallFunction( ) } -const internalEVMTypeCreateBridgedAccountFunctionName = "createBridgedAccount" +const internalEVMTypeCreateCadenceOwnedAccountFunctionName = "createCadenceOwnedAccount" -var internalEVMTypeCreateBridgedAccountFunctionType = &sema.FunctionType{ +var internalEVMTypeCreateCadenceOwnedAccountFunctionType = &sema.FunctionType{ Parameters: []sema.Parameter{ { Label: "uuid", @@ -1149,13 +1149,13 @@ var internalEVMTypeCreateBridgedAccountFunctionType = &sema.FunctionType{ ReturnTypeAnnotation: sema.NewTypeAnnotation(evmAddressBytesType), } -func newInternalEVMTypeCreateBridgedAccountFunction( +func newInternalEVMTypeCreateCadenceOwnedAccountFunction( gauge common.MemoryGauge, handler types.ContractHandler, ) *interpreter.HostFunctionValue { return interpreter.NewHostFunctionValue( gauge, - internalEVMTypeCreateBridgedAccountFunctionType, + internalEVMTypeCreateCadenceOwnedAccountFunctionType, func(invocation interpreter.Invocation) interpreter.Value { inter := invocation.Interpreter uuid, ok := invocation.Arguments[0].(interpreter.UInt64Value) @@ -1532,17 +1532,17 @@ func NewInternalEVMContractValue( internalEVMContractStaticType, InternalEVMContractType.Fields, map[string]interpreter.Value{ - internalEVMTypeRunFunctionName: newInternalEVMTypeRunFunction(gauge, handler), - internalEVMTypeCreateBridgedAccountFunctionName: newInternalEVMTypeCreateBridgedAccountFunction(gauge, handler), - internalEVMTypeCallFunctionName: newInternalEVMTypeCallFunction(gauge, handler), - internalEVMTypeDepositFunctionName: newInternalEVMTypeDepositFunction(gauge, handler), - internalEVMTypeWithdrawFunctionName: newInternalEVMTypeWithdrawFunction(gauge, handler), - internalEVMTypeDeployFunctionName: newInternalEVMTypeDeployFunction(gauge, handler), - internalEVMTypeBalanceFunctionName: newInternalEVMTypeBalanceFunction(gauge, handler), - internalEVMTypeEncodeABIFunctionName: newInternalEVMTypeEncodeABIFunction(gauge, location), - internalEVMTypeDecodeABIFunctionName: newInternalEVMTypeDecodeABIFunction(gauge, location), - internalEVMTypeCastToAttoFLOWFunctionName: newInternalEVMTypeCastToAttoFLOWFunction(gauge, handler), - internalEVMTypeCastToFLOWFunctionName: newInternalEVMTypeCastToFLOWFunction(gauge, handler), + internalEVMTypeRunFunctionName: newInternalEVMTypeRunFunction(gauge, handler), + internalEVMTypeCreateCadenceOwnedAccountFunctionName: newInternalEVMTypeCreateCadenceOwnedAccountFunction(gauge, handler), + internalEVMTypeCallFunctionName: newInternalEVMTypeCallFunction(gauge, handler), + internalEVMTypeDepositFunctionName: newInternalEVMTypeDepositFunction(gauge, handler), + internalEVMTypeWithdrawFunctionName: newInternalEVMTypeWithdrawFunction(gauge, handler), + internalEVMTypeDeployFunctionName: newInternalEVMTypeDeployFunction(gauge, handler), + internalEVMTypeBalanceFunctionName: newInternalEVMTypeBalanceFunction(gauge, handler), + internalEVMTypeEncodeABIFunctionName: newInternalEVMTypeEncodeABIFunction(gauge, location), + internalEVMTypeDecodeABIFunctionName: newInternalEVMTypeDecodeABIFunction(gauge, location), + internalEVMTypeCastToAttoFLOWFunctionName: newInternalEVMTypeCastToAttoFLOWFunction(gauge, handler), + internalEVMTypeCastToFLOWFunctionName: newInternalEVMTypeCastToFLOWFunction(gauge, handler), }, nil, nil, @@ -1567,8 +1567,8 @@ var InternalEVMContractType = func() *sema.CompositeType { ), sema.NewUnmeteredPublicFunctionMember( ty, - internalEVMTypeCreateBridgedAccountFunctionName, - internalEVMTypeCreateBridgedAccountFunctionType, + internalEVMTypeCreateCadenceOwnedAccountFunctionName, + internalEVMTypeCreateCadenceOwnedAccountFunctionType, "", ), sema.NewUnmeteredPublicFunctionMember( diff --git a/fvm/evm/stdlib/contract_test.go b/fvm/evm/stdlib/contract_test.go index 507a19c790c..4ea992cbfcc 100644 --- a/fvm/evm/stdlib/contract_test.go +++ b/fvm/evm/stdlib/contract_test.go @@ -2854,7 +2854,7 @@ func TestEVMRun(t *testing.T) { assert.True(t, runCalled) } -func TestEVMCreateBridgedAccount(t *testing.T) { +func TestEVMCreateCadenceOwnedAccount(t *testing.T) { t.Parallel() @@ -2877,12 +2877,12 @@ func TestEVMCreateBridgedAccount(t *testing.T) { access(all) fun main(): [UInt8; 20] { - let bridgedAccount1 <- EVM.createBridgedAccount() - destroy bridgedAccount1 + let cadenceOwnedAccount1 <- EVM.createCadenceOwnedAccount() + destroy cadenceOwnedAccount1 - let bridgedAccount2 <- EVM.createBridgedAccount() - let bytes = bridgedAccount2.address().bytes - destroy bridgedAccount2 + let cadenceOwnedAccount2 <- EVM.createCadenceOwnedAccount() + let bytes = cadenceOwnedAccount2.address().bytes + destroy cadenceOwnedAccount2 return bytes } @@ -2966,7 +2966,7 @@ func TestEVMCreateBridgedAccount(t *testing.T) { require.Equal(t, expected, actual) } -func TestBridgedAccountCall(t *testing.T) { +func TestCadenceOwnedAccountCall(t *testing.T) { t.Parallel() @@ -3009,10 +3009,10 @@ func TestBridgedAccountCall(t *testing.T) { access(all) fun main(): [UInt8] { - let bridgedAccount <- EVM.createBridgedAccount() + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() let bal = EVM.Balance(0) bal.setFLOW(flow: 1.23) - let response = bridgedAccount.call( + let response = cadenceOwnedAccount.call( to: EVM.EVMAddress( bytes: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ), @@ -3020,7 +3020,7 @@ func TestBridgedAccountCall(t *testing.T) { gasLimit: 9999, value: bal ) - destroy bridgedAccount + destroy cadenceOwnedAccount return response } `) @@ -3137,9 +3137,9 @@ func TestEVMAddressDeposit(t *testing.T) { let vault <- minter.mintTokens(amount: 1.23) destroy minter - let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.deposit(from: <-vault) - destroy bridgedAccount + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + cadenceOwnedAccount.deposit(from: <-vault) + destroy cadenceOwnedAccount } `) @@ -3201,7 +3201,7 @@ func TestEVMAddressDeposit(t *testing.T) { require.True(t, deposited) } -func TestBridgedAccountWithdraw(t *testing.T) { +func TestCadenceOwnedAccountWithdraw(t *testing.T) { t.Parallel() @@ -3260,12 +3260,12 @@ func TestBridgedAccountWithdraw(t *testing.T) { let vault <- minter.mintTokens(amount: 2.34) destroy minter - let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.deposit(from: <-vault) + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + cadenceOwnedAccount.deposit(from: <-vault) - let vault2 <- bridgedAccount.withdraw(balance: EVM.Balance(attoflow: 1230000000000000000)) + let vault2 <- cadenceOwnedAccount.withdraw(balance: EVM.Balance(attoflow: 1230000000000000000)) let balance = vault2.balance - destroy bridgedAccount + destroy cadenceOwnedAccount destroy vault2 return balance @@ -3332,7 +3332,7 @@ func TestBridgedAccountWithdraw(t *testing.T) { assert.Equal(t, expectedWithdrawBalance, result) } -func TestBridgedAccountDeploy(t *testing.T) { +func TestCadenceOwnedAccountDeploy(t *testing.T) { t.Parallel() @@ -3374,13 +3374,13 @@ func TestBridgedAccountDeploy(t *testing.T) { access(all) fun main(): [UInt8; 20] { - let bridgedAccount <- EVM.createBridgedAccount() - let address = bridgedAccount.deploy( + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + let address = cadenceOwnedAccount.deploy( code: [4, 5, 6], gasLimit: 9999, value: EVM.Balance(flow: 1230000000000000000) ) - destroy bridgedAccount + destroy cadenceOwnedAccount return address.bytes } `) @@ -3497,9 +3497,9 @@ func TestEVMAccountBalance(t *testing.T) { access(all) fun main(): EVM.Balance { - let bridgedAccount <- EVM.createBridgedAccount() - let balance = bridgedAccount.balance() - destroy bridgedAccount + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + let balance = cadenceOwnedAccount.balance() + destroy cadenceOwnedAccount return balance } `) @@ -3597,9 +3597,9 @@ func TestEVMAccountBalanceForABIOnlyContract(t *testing.T) { access(all) fun main(): EVM.Balance { - let bridgedAccount <- EVM.createBridgedAccount() - let balance = bridgedAccount.balance() - destroy bridgedAccount + let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() + let balance = cadenceOwnedAccount.balance() + destroy cadenceOwnedAccount return balance } `) @@ -3667,7 +3667,7 @@ func TestEVMAccountBalanceForABIOnlyContract(t *testing.T) { assert.ErrorContains( t, err, - "error: value of type `EVM` has no member `createBridgedAccount`", + "error: value of type `EVM` has no member `createCadenceOwnedAccount`", ) } @@ -3680,7 +3680,7 @@ func TestEVMValidateCOAOwnershipProof(t *testing.T) { proof := &types.COAOwnershipProofInContext{ COAOwnershipProof: types.COAOwnershipProof{ Address: types.FlowAddress(contractsAddress), - CapabilityPath: "bridgedAccount", + CapabilityPath: "coa", Signatures: []types.Signature{[]byte("signature")}, KeyIndices: []uint64{0}, }, @@ -3764,11 +3764,11 @@ func TestEVMValidateCOAOwnershipProof(t *testing.T) { transaction { prepare(account: AuthAccount) { - let bridgedAccount1 <- EVM.createBridgedAccount() - account.save<@EVM.BridgedAccount>(<-bridgedAccount1, - to: /storage/bridgedAccount) - account.link<&EVM.BridgedAccount{EVM.Addressable}>(/public/bridgedAccount, - target: /storage/bridgedAccount) + let cadenceOwnedAccount1 <- EVM.createCadenceOwnedAccount() + account.save<@EVM.CadenceOwnedAccount>(<-cadenceOwnedAccount1, + to: /storage/coa) + account.link<&EVM.CadenceOwnedAccount{EVM.Addressable}>(/public/coa, + target: /storage/coa) } }`) diff --git a/fvm/evm/types/address.go b/fvm/evm/types/address.go index 78b4edd9bcb..a37b63d21e2 100644 --- a/fvm/evm/types/address.go +++ b/fvm/evm/types/address.go @@ -25,7 +25,7 @@ import ( // leaves a variable part of 8 bytes (64 bits). const FlowEVMSpecialAddressPrefixLen = 12 -const COAAddressTemplate = "A.%v.EVM.BridgedAccountCreated" +const COAAddressTemplate = "A.%v.EVM.CadenceOwnedAccountCreated" var ( // Using leading zeros for prefix helps with the storage compactness. diff --git a/fvm/evm/types/handler.go b/fvm/evm/types/handler.go index e3563a9c406..0f302a3b536 100644 --- a/fvm/evm/types/handler.go +++ b/fvm/evm/types/handler.go @@ -27,7 +27,7 @@ type ContractHandler interface { // AccountByAddress returns an account by address // if isAuthorized is set, it allows for functionality like `call`, `deploy` - // should only be set for bridged accounts only. + // should only be set for the cadence owned accounts only. AccountByAddress(address Address, isAuthorized bool) Account // LastExecutedBlock returns information about the last executed block diff --git a/fvm/fvm_test.go b/fvm/fvm_test.go index 61c4d140fa2..ceba4ed35bf 100644 --- a/fvm/fvm_test.go +++ b/fvm/fvm_test.go @@ -3034,7 +3034,7 @@ func TestEVM(t *testing.T) { log(data.length) assert(data.length == 160) - let acc <- EVM.createBridgedAccount() + let acc <- EVM.createCadenceOwnedAccount() destroy acc } } @@ -3055,7 +3055,7 @@ func TestEVM(t *testing.T) { assert.ErrorContains( t, output.Err, - "value of type `EVM` has no member `createBridgedAccount`", + "value of type `EVM` has no member `createCadenceOwnedAccount`", ) }), ) @@ -3080,7 +3080,7 @@ func TestEVM(t *testing.T) { pub fun main() { let bal = EVM.Balance(attoflow: 1000000000000000000); - let acc <- EVM.createBridgedAccount(); + let acc <- EVM.createCadenceOwnedAccount(); // withdraw insufficient balance destroy acc.withdraw(balance: bal); destroy acc; @@ -3144,7 +3144,7 @@ func TestEVM(t *testing.T) { import EVM from %s pub fun main() { - destroy <- EVM.createBridgedAccount(); + destroy <- EVM.createCadenceOwnedAccount(); } `, sc.EVMContract.Address.HexWithPrefix()))) @@ -3188,7 +3188,7 @@ func TestEVM(t *testing.T) { let vaultRef = acc.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault) ?? panic("Could not borrow reference to the owner's Vault!") - let acc <- EVM.createBridgedAccount() + let acc <- EVM.createCadenceOwnedAccount() let amount <- vaultRef.withdraw(amount: 0.0000001) as! @FlowToken.Vault acc.deposit(from: <- amount) destroy acc diff --git a/integration/benchmark/load/evm_load.go b/integration/benchmark/load/evm_load.go index 83d79960cfb..3c9dff39f19 100644 --- a/integration/benchmark/load/evm_load.go +++ b/integration/benchmark/load/evm_load.go @@ -19,6 +19,7 @@ import ( "golang.org/x/sync/errgroup" flowsdk "github.com/onflow/flow-go-sdk" + "github.com/onflow/flow-go/fvm/blueprints" "github.com/onflow/flow-go/fvm/evm/emulator" "github.com/onflow/flow-go/fvm/evm/stdlib" @@ -114,36 +115,41 @@ func (l *EVMTransferLoad) Setup(log zerolog.Logger, lc LoadContext) error { contractName := "BridgedAccountContract" contract := fmt.Sprintf(` -import EVM from %s -import FlowToken from %s - -access(all) contract BridgedAccountContract { - access(self) var acc : @EVM.BridgedAccount - - access(all) - fun address() : EVM.EVMAddress { - return self.acc.address() - } - - access(all) - fun call( - to: EVM.EVMAddress, - data: [UInt8], - gasLimit: UInt64, - value: EVM.Balance - ): [UInt8] { - return self.acc.call(to: to, data: data, gasLimit: gasLimit, value: value) - } - - access(all) - fun deposit(from: @FlowToken.Vault) { - self.acc.deposit(from: <-from) - } - - init() { - self.acc <- EVM.createBridgedAccount() - } -} + import EVM from %s + import FlowToken from %s + + access(all) contract BridgedAccountContract { + access(self) var acc: @EVM.CadenceOwnedAccount + + access(all) + fun address() : EVM.EVMAddress { + return self.acc.address() + } + + access(all) + fun call( + to: EVM.EVMAddress, + data: [UInt8], + gasLimit: UInt64, + value: EVM.Balance + ): [UInt8] { + return self.acc.call( + to: to, + data: data, + gasLimit: gasLimit, + value: value + ) + } + + access(all) + fun deposit(from: @FlowToken.Vault) { + self.acc.deposit(from: <-from) + } + + init() { + self.acc <- EVM.createCadenceOwnedAccount() + } + } `, sc.EVMContract.Address.HexWithPrefix(), sc.FlowToken.Address.HexWithPrefix()) diff --git a/integration/benchmark/load/load_type_test.go b/integration/benchmark/load/load_type_test.go index f600eab9fcb..5032717d567 100644 --- a/integration/benchmark/load/load_type_test.go +++ b/integration/benchmark/load/load_type_test.go @@ -14,6 +14,7 @@ import ( sdk "github.com/onflow/flow-go-sdk" "github.com/onflow/flow-go-sdk/crypto" + "github.com/onflow/flow-go/engine/execution/computation" "github.com/onflow/flow-go/engine/execution/testutil" "github.com/onflow/flow-go/fvm"