diff --git a/cmd/util/ledger/migrations/change_contract_code_migration.go b/cmd/util/ledger/migrations/change_contract_code_migration.go index 9c335fb9573..c2715bdc8d0 100644 --- a/cmd/util/ledger/migrations/change_contract_code_migration.go +++ b/cmd/util/ledger/migrations/change_contract_code_migration.go @@ -326,10 +326,7 @@ func SystemContractChanges(chainID flow.ChainID) []SystemContractChange { // EVM related contracts NewSystemContractChange( systemContracts.EVMContract, - evm.ContractCode( - systemContracts.FlowToken.Address, - true, - ), + evm.ContractCode(systemContracts.FlowToken.Address), ), } } diff --git a/fvm/bootstrap.go b/fvm/bootstrap.go index 089734173b6..7ce37e0828b 100644 --- a/fvm/bootstrap.go +++ b/fvm/bootstrap.go @@ -76,13 +76,7 @@ type BootstrapParams struct { minimumStorageReservation cadence.UFix64 storagePerFlow cadence.UFix64 restrictedAccountCreationEnabled cadence.Bool - - // `setupEVMEnabled` == true && `evmAbiOnly` == true will enable the ABI-only EVM - // `setupEVMEnabled` == true && `evmAbiOnly` == false will enable the full EVM functionality - // `setupEVMEnabled` == false will disable EVM - // This will allow to quickly disable the ABI-only EVM, in case there's a bug or something. - setupEVMEnabled cadence.Bool - evmAbiOnly cadence.Bool + setupEVMEnabled cadence.Bool // versionFreezePeriod is the number of blocks in the future where the version // changes are frozen. The Node version beacon manages the freeze period, @@ -225,13 +219,6 @@ func WithSetupEVMEnabled(enabled cadence.Bool) BootstrapProcedureOption { } } -func WithEVMABIOnly(evmAbiOnly cadence.Bool) BootstrapProcedureOption { - return func(bp *BootstrapProcedure) *BootstrapProcedure { - bp.evmAbiOnly = evmAbiOnly - return bp - } -} - func WithRestrictedContractDeployment(restricted *bool) BootstrapProcedureOption { return func(bp *BootstrapProcedure) *BootstrapProcedure { bp.restrictedContractDeployment = restricted @@ -830,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, bool(b.evmAbiOnly)), + stdlib.ContractCode(flowTokenAddress), stdlib.ContractName, ) // WithEVMEnabled should only be used after we create an account for storage diff --git a/fvm/evm/stdlib/abiOnlyContract.cdc b/fvm/evm/stdlib/abiOnlyContract.cdc deleted file mode 100644 index 45378726215..00000000000 --- a/fvm/evm/stdlib/abiOnlyContract.cdc +++ /dev/null @@ -1,60 +0,0 @@ -access(all) -contract EVM { - - /// EVMAddress is an EVM-compatible address - access(all) - struct EVMAddress { - - /// Bytes of the address - access(all) - let bytes: [UInt8; 20] - - /// Constructs a new EVM address from the given byte representation - init(bytes: [UInt8; 20]) { - self.bytes = bytes - } - - } - - access(all) - fun encodeABI(_ values: [AnyStruct]): [UInt8] { - return InternalEVM.encodeABI(values) - } - - access(all) - fun decodeABI(types: [Type], data: [UInt8]): [AnyStruct] { - return InternalEVM.decodeABI(types: types, data: data) - } - - access(all) - fun encodeABIWithSignature( - _ signature: String, - _ values: [AnyStruct] - ): [UInt8] { - let methodID = HashAlgorithm.KECCAK_256.hash( - signature.utf8 - ).slice(from: 0, upTo: 4) - let arguments = InternalEVM.encodeABI(values) - - return methodID.concat(arguments) - } - - access(all) - fun decodeABIWithSignature( - _ signature: String, - types: [Type], - data: [UInt8] - ): [AnyStruct] { - let methodID = HashAlgorithm.KECCAK_256.hash( - signature.utf8 - ).slice(from: 0, upTo: 4) - - for byte in methodID { - if byte != data.removeFirst() { - panic("signature mismatch") - } - } - - return InternalEVM.decodeABI(types: types, data: data) - } -} diff --git a/fvm/evm/stdlib/contract.go b/fvm/evm/stdlib/contract.go index 9b1979e1aa1..49cf25858e4 100644 --- a/fvm/evm/stdlib/contract.go +++ b/fvm/evm/stdlib/contract.go @@ -27,16 +27,9 @@ import ( //go:embed contract.cdc var contractCode string -//go:embed abiOnlyContract.cdc -var abiOnlyContractCode string - var flowTokenImportPattern = regexp.MustCompile(`(?m)^import "FlowToken"\n`) -func ContractCode(flowTokenAddress flow.Address, evmAbiOnly bool) []byte { - if evmAbiOnly { - return []byte(abiOnlyContractCode) - } - +func ContractCode(flowTokenAddress flow.Address) []byte { return []byte(flowTokenImportPattern.ReplaceAllString( contractCode, fmt.Sprintf("import FlowToken from %s", flowTokenAddress.HexWithPrefix()), diff --git a/fvm/evm/stdlib/contract_test.go b/fvm/evm/stdlib/contract_test.go index ba5bf0e66f0..0ae46833331 100644 --- a/fvm/evm/stdlib/contract_test.go +++ b/fvm/evm/stdlib/contract_test.go @@ -170,7 +170,6 @@ func deployContracts( runtimeInterface *TestRuntimeInterface, transactionEnvironment runtime.Environment, nextTransactionLocation func() common.TransactionLocation, - evmAbiOnly bool, ) { contractsAddressHex := contractsAddress.Hex() @@ -223,7 +222,7 @@ func deployContracts( }, { name: stdlib.ContractName, - code: stdlib.ContractCode(contractsAddress, evmAbiOnly), + code: stdlib.ContractCode(contractsAddress), }, } @@ -344,7 +343,6 @@ func TestEVMEncodeABI(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -473,7 +471,6 @@ func TestEVMEncodeABIComputation(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -569,7 +566,6 @@ func TestEVMEncodeABIComputationEmptyDynamicVariables(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -674,7 +670,6 @@ func TestEVMEncodeABIComputationDynamicVariablesAboveChunkSize(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -773,7 +768,6 @@ func TestEVMDecodeABI(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -908,7 +902,6 @@ func TestEVMDecodeABIComputation(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1182,7 +1175,6 @@ func TestEVMEncodeDecodeABIRoundtrip(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1261,7 +1253,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1348,7 +1339,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1434,7 +1424,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1521,7 +1510,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1608,7 +1596,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1705,7 +1692,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1792,7 +1778,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1879,7 +1864,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -1966,7 +1950,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2053,7 +2036,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2140,7 +2122,6 @@ func TestEVMEncodeDecodeABIErrors(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2272,7 +2253,6 @@ func TestEVMEncodeABIWithSignature(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2406,7 +2386,6 @@ func TestEVMDecodeABIWithSignature(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2521,7 +2500,6 @@ func TestEVMDecodeABIWithSignatureMismatch(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2631,7 +2609,6 @@ func TestEVMAddressConstructionAndReturn(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - true, ) // Run script @@ -2724,7 +2701,6 @@ func TestBalanceConstructionAndReturn(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -2858,7 +2834,6 @@ func TestEVMRun(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -2984,7 +2959,6 @@ func TestEVMCreateCadenceOwnedAccount(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // reset events @@ -3137,7 +3111,6 @@ func TestCadenceOwnedAccountCall(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -3257,7 +3230,6 @@ func TestEVMAddressDeposit(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -3371,7 +3343,6 @@ func TestCOADeposit(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -3534,7 +3505,6 @@ func TestCadenceOwnedAccountWithdraw(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // reset events @@ -3667,7 +3637,6 @@ func TestCadenceOwnedAccountDeploy(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -3755,7 +3724,6 @@ func RunEVMScript( runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script @@ -3931,114 +3899,6 @@ func TestEVMAccountCodeHash(t *testing.T) { RunEVMScript(t, handler, script, expectedCodeHashValue) } -func TestEVMAccountBalanceForABIOnlyContract(t *testing.T) { - - t.Parallel() - - contractsAddress := flow.BytesToAddress([]byte{0x1}) - - expectedBalanceValue, err := cadence.NewUFix64FromParts(1, 1337000) - require.NoError(t, err) - - handler := &testContractHandler{ - flowTokenAddress: common.Address(contractsAddress), - accountByAddress: func(fromAddress types.Address, isAuthorized bool) types.Account { - assert.Equal(t, types.Address{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, fromAddress) - assert.False(t, isAuthorized) - - return &testFlowAccount{ - address: fromAddress, - balance: func() types.Balance { - return types.NewBalanceFromUFix64(expectedBalanceValue) - }, - } - }, - } - - transactionEnvironment := newEVMTransactionEnvironment(handler, contractsAddress) - scriptEnvironment := newEVMScriptEnvironment(handler, contractsAddress) - - rt := runtime.NewInterpreterRuntime(runtime.Config{}) - - script := []byte(` - import EVM from 0x1 - - access(all) - fun main(): EVM.Balance { - let cadenceOwnedAccount <- EVM.createCadenceOwnedAccount() - let balance = cadenceOwnedAccount.balance() - destroy cadenceOwnedAccount - return balance - } - `) - - accountCodes := map[common.Location][]byte{} - var events []cadence.Event - - runtimeInterface := &TestRuntimeInterface{ - Storage: NewTestLedger(nil, nil), - OnGetSigningAccounts: func() ([]runtime.Address, error) { - return []runtime.Address{runtime.Address(contractsAddress)}, nil - }, - OnResolveLocation: LocationResolver, - OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error { - accountCodes[location] = code - return nil - }, - OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { - code = accountCodes[location] - return code, nil - }, - OnEmitEvent: func(event cadence.Event) error { - events = append(events, event) - return nil - }, - OnDecodeArgument: func(b []byte, t cadence.Type) (cadence.Value, error) { - return json.Decode(nil, b) - }, - } - - nextTransactionLocation := NewTransactionLocationGenerator() - nextScriptLocation := NewScriptLocationGenerator() - - // Deploy contracts - - deployContracts( - t, - rt, - contractsAddress, - runtimeInterface, - transactionEnvironment, - nextTransactionLocation, - true, - ) - - // Run script - - _, err = rt.ExecuteScript( - runtime.Script{ - Source: script, - }, - runtime.Context{ - Interface: runtimeInterface, - Environment: scriptEnvironment, - Location: nextScriptLocation(), - }, - ) - require.Error(t, err) - - assert.ErrorContains( - t, - err, - "error: cannot find type in this scope: `EVM.Balance`", - ) - assert.ErrorContains( - t, - err, - "error: value of type `EVM` has no member `createCadenceOwnedAccount`", - ) -} - func TestEVMValidateCOAOwnershipProof(t *testing.T) { t.Parallel() @@ -4123,7 +3983,6 @@ func TestEVMValidateCOAOwnershipProof(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) setupTx := []byte(` @@ -4246,7 +4105,6 @@ func TestInternalEVMAccess(t *testing.T) { runtimeInterface, transactionEnvironment, nextTransactionLocation, - false, ) // Run script diff --git a/fvm/fvm_test.go b/fvm/fvm_test.go index 53adf81cd4a..900a9f7a56f 100644 --- a/fvm/fvm_test.go +++ b/fvm/fvm_test.go @@ -3119,59 +3119,6 @@ func TestEVM(t *testing.T) { }), ) - // this test makes sure that only ABI encoding/decoding functionality is - // available through the EVM contract, when bootstraped with `WithEVMABIOnly` - t.Run("with ABI only EVM", newVMTest(). - withBootstrapProcedureOptions( - fvm.WithSetupEVMEnabled(true), - fvm.WithEVMABIOnly(true), - ). - withContextOptions( - fvm.WithEVMEnabled(true), - ). - run(func( - t *testing.T, - vm fvm.VM, - chain flow.Chain, - ctx fvm.Context, - snapshotTree snapshot.SnapshotTree, - ) { - txBody := flow.NewTransactionBody(). - SetScript([]byte(fmt.Sprintf(` - import EVM from %s - - transaction { - execute { - let data = EVM.encodeABI(["John Doe", UInt64(33), false]) - log(data.length) - assert(data.length == 160) - - let acc <- EVM.createCadenceOwnedAccount() - destroy acc - } - } - `, chain.ServiceAddress().HexWithPrefix()))). - SetProposalKey(chain.ServiceAddress(), 0, 0). - SetPayer(chain.ServiceAddress()) - - err := testutil.SignTransactionAsServiceAccount(txBody, 0, chain) - require.NoError(t, err) - - _, output, err := vm.Run( - ctx, - fvm.Transaction(txBody, 0), - snapshotTree) - - require.NoError(t, err) - require.Error(t, output.Err) - assert.ErrorContains( - t, - output.Err, - "value of type `EVM` has no member `createCadenceOwnedAccount`", - ) - }), - ) - // this test makes sure the execution error is correctly handled and returned as a correct type t.Run("execution reverted", newVMTest(). withBootstrapProcedureOptions(fvm.WithSetupEVMEnabled(true)).