diff --git a/internal/cadence/linter.go b/internal/cadence/linter.go index 179a10f05..814fe5de5 100644 --- a/internal/cadence/linter.go +++ b/internal/cadence/linter.go @@ -69,8 +69,8 @@ func newLinter(state *flowkit.State) *linter { // Create checker configs for both standard and script // Scripts have a different stdlib than contracts and transactions - l.checkerStandardConfig = l.newCheckerConfig(util.NewStandardLibrary()) - l.checkerScriptConfig = l.newCheckerConfig(util.NewScriptStandardLibrary()) + l.checkerStandardConfig = l.newCheckerConfig(util.NewCheckerEnvironment()) + l.checkerScriptConfig = l.newCheckerConfig(util.NewScriptCheckerEnvironment()) return l } @@ -154,10 +154,13 @@ func (l *linter) lintFile( } // Create a new checker config with the given standard library -func (l *linter) newCheckerConfig(lib util.StandardLibrary) *sema.Config { +func (l *linter) newCheckerConfig(env *util.CheckerEnvironment) *sema.Config { return &sema.Config{ - BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { - return lib.BaseValueActivation + BaseValueActivationHandler: func(location common.Location) *sema.VariableActivation { + return env.GetBaseValueActivation(location) + }, + BaseTypeActivationHandler: func(location common.Location) *sema.VariableActivation { + return env.GetBaseTypeActivation(location) }, AccessCheckMode: sema.AccessCheckModeStrict, PositionInfoEnabled: true, // Must be enabled for linters diff --git a/internal/migrate/staging_validator.go b/internal/migrate/staging_validator.go index 63fac7c85..fe1a421d3 100644 --- a/internal/migrate/staging_validator.go +++ b/internal/migrate/staging_validator.go @@ -68,6 +68,9 @@ type stagingValidatorImpl struct { // Cache for contract checkers which are reused during program checking & used for the update checker checkingCache map[common.Location]*cachedCheckingResult + + // Environment for the stdlib + env *util.CheckerEnvironment } type node map[common.Location]node @@ -174,6 +177,14 @@ func newStagingValidator(flow flowkit.Services) *stagingValidatorImpl { } func (v *stagingValidatorImpl) Validate(stagedContracts []stagedContractUpdate) error { + // Setup the environment for the stdlib + chainId, ok := chainIdMap[v.flow.Network().Name] + if !ok { + return fmt.Errorf("unsupported network: %s", v.flow.Network().Name) + } + v.env = util.NewCheckerEnvironment() + v.env.SetupFVM(chainId) + v.stagedContracts = make(map[common.AddressLocation]stagedContractUpdate) for _, stagedContract := range stagedContracts { v.stagedContracts[stagedContract.DeployLocation] = stagedContract @@ -408,9 +419,13 @@ func (v *stagingValidatorImpl) checkContract( &sema.Config{ AccessCheckMode: sema.AccessCheckModeStrict, AttachmentsEnabled: true, - BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation { + BaseValueActivationHandler: func(location common.Location) *sema.VariableActivation { + // Only checking contracts, so no need to consider script standard library + return v.env.GetBaseValueActivation(location) + }, + BaseTypeActivationHandler: func(location common.Location) *sema.VariableActivation { // Only checking contracts, so no need to consider script standard library - return util.NewStandardLibrary().BaseValueActivation + return v.env.GetBaseTypeActivation(location) }, LocationHandler: v.resolveLocation, ImportHandler: v.resolveImport, diff --git a/internal/migrate/staging_validator_test.go b/internal/migrate/staging_validator_test.go index afa612adf..b6b01b9ce 100644 --- a/internal/migrate/staging_validator_test.go +++ b/internal/migrate/staging_validator_test.go @@ -762,4 +762,64 @@ func Test_StagingValidator(t *testing.T) { require.Nil(t, err) }) + + t.Run("import InternalEVM fails with wrong location", func(t *testing.T) { + // setup mocks + srv := setupValidatorMocks(t, []mockNetworkAccount{ + { + address: flow.HexToAddress("01"), + contracts: map[string][]byte{"Foo": []byte(` + pub contract Foo { + init() {} + }`)}, + }, + }) + + validator := newStagingValidator(srv) + err := validator.Validate([]stagedContractUpdate{ + { + DeployLocation: simpleAddressLocation("0x01.Foo"), + SourceLocation: common.StringLocation("./Foo.cdc"), + Code: []byte(` + access(all) contract Foo { + init() { + log(InternalEVM) + } + }`), + }, + }) + + var validatorErr *stagingValidatorError + require.ErrorAs(t, err, &validatorErr) + + var checkerErr *sema.CheckerError + require.ErrorAs(t, validatorErr.errors[simpleAddressLocation("0x01.Foo")], &checkerErr) + require.ErrorContains(t, checkerErr, "cannot find variable in this scope: `InternalEVM`") + }) + + t.Run("EVM import works", func(t *testing.T) { + location := simpleAddressLocation("0x01.Test") + sourceCodeLocation := common.StringLocation("./Test.cdc") + oldContract := ` + pub contract Test { + pub fun test() {} + }` + newContract := ` + import EVM from 0x8c5303eaa26202d6 + access(all) contract Test { + access(all) fun test() {} + }` + + // setup mocks + srv := setupValidatorMocks(t, []mockNetworkAccount{ + { + address: flow.HexToAddress("01"), + contracts: map[string][]byte{"Test": []byte(oldContract)}, + }, + }) + + validator := newStagingValidator(srv) + err := validator.Validate([]stagedContractUpdate{{location, sourceCodeLocation, []byte(newContract)}}) + require.NoError(t, err) + }) } diff --git a/internal/util/checker_environment.go b/internal/util/checker_environment.go new file mode 100644 index 000000000..6f1cbda87 --- /dev/null +++ b/internal/util/checker_environment.go @@ -0,0 +1,416 @@ +/* + * Cadence - The resource-oriented smart contract programming language + * + * Copyright 2019-2022 Dapper Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package util + +import ( + "github.com/onflow/cadence" + "github.com/onflow/cadence/runtime" + "github.com/onflow/cadence/runtime/common" + "github.com/onflow/cadence/runtime/errors" + "github.com/onflow/cadence/runtime/interpreter" + "github.com/onflow/cadence/runtime/sema" + "github.com/onflow/cadence/runtime/stdlib" + + "github.com/onflow/flow-go/fvm/evm" + evmstdlib "github.com/onflow/flow-go/fvm/evm/stdlib" + "github.com/onflow/flow-go/model/flow" +) + +type CheckerEnvironment struct { + defaultBaseValueActivation *sema.VariableActivation + defaultBaseTypeActivation *sema.VariableActivation + baseValueActivationsByLocation map[common.Location]*sema.VariableActivation + baseTypeActivationsByLocation map[common.Location]*sema.VariableActivation +} + +var _ runtime.Environment = CheckerEnvironment{} + +func NewCheckerEnvironment() *CheckerEnvironment { + env := newCheckerEnvironment() + for _, valueDeclaration := range stdlib.DefaultStandardLibraryValues(env) { + env.DeclareValue(valueDeclaration, nil) + } + return env +} + +func NewScriptCheckerEnvironment() *CheckerEnvironment { + env := newCheckerEnvironment() + for _, valueDeclaration := range stdlib.DefaultScriptStandardLibraryValues(env) { + env.DeclareValue(valueDeclaration, nil) + } + return env +} + +func newCheckerEnvironment() *CheckerEnvironment { + return &CheckerEnvironment{ + defaultBaseValueActivation: sema.NewVariableActivation(sema.BaseValueActivation), + defaultBaseTypeActivation: sema.NewVariableActivation(sema.BaseTypeActivation), + baseValueActivationsByLocation: make(map[common.Location]*sema.VariableActivation), + baseTypeActivationsByLocation: make(map[common.Location]*sema.VariableActivation), + } +} + +func (e CheckerEnvironment) SetupFVM(chainId flow.ChainID) { + // Set up the EVM standard library + evmstdlib.SetupEnvironment(e, nil, evm.ContractAccountAddress(chainId)) +} + +func (e CheckerEnvironment) GetBaseValueActivation(location common.Location) (baseValueActivation *sema.VariableActivation) { + if location == nil { + return e.defaultBaseValueActivation + } + + baseValueActivation = e.baseValueActivationsByLocation[location] + if baseValueActivation == nil { + baseValueActivation = sema.NewVariableActivation(e.defaultBaseValueActivation) + e.baseValueActivationsByLocation[location] = baseValueActivation + } + return +} + +func (e CheckerEnvironment) GetBaseTypeActivation(location common.Location) (baseTypeActivation *sema.VariableActivation) { + if location == nil { + return e.defaultBaseTypeActivation + } + + baseTypeActivation = e.baseTypeActivationsByLocation[location] + if baseTypeActivation == nil { + baseTypeActivation = sema.NewVariableActivation(e.defaultBaseTypeActivation) + e.baseTypeActivationsByLocation[location] = baseTypeActivation + } + return +} + +/* + * Implement required interface methods + */ + +func (e CheckerEnvironment) DeclareValue(valueDeclaration stdlib.StandardLibraryValue, location common.Location) { + e.GetBaseValueActivation(location).DeclareValue(valueDeclaration) +} + +func (e CheckerEnvironment) DeclareType(typeDeclaration stdlib.StandardLibraryType, location common.Location) { + e.GetBaseTypeActivation(location).DeclareType(typeDeclaration) +} + +/* + * The following methods are not implemented, as they are not used in the type-checking process. + * They are only used in the execution process. + */ +func (CheckerEnvironment) ProgramLog(_ string, _ interpreter.LocationRange) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) UnsafeRandom() (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetBlockAtHeight(_ uint64) (stdlib.Block, bool, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetCurrentBlockHeight() (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetAccountBalance(_ common.Address) (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetAccountAvailableBalance(_ common.Address) (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) CommitStorageTemporarily(_ *interpreter.Interpreter) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetStorageUsed(_ common.Address) (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetStorageCapacity(_ common.Address) (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetAccountKey(_ common.Address, _ uint32) (*stdlib.AccountKey, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetAccountContractNames(_ common.Address) ([]string, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) GetAccountContractCode(_ common.AddressLocation) ([]byte, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) EmitEvent( + _ *interpreter.Interpreter, + _ interpreter.LocationRange, + _ *sema.CompositeType, + _ []interpreter.Value, +) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) AddEncodedAccountKey(_ common.Address, _ []byte) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) RevokeEncodedAccountKey(_ common.Address, _ int) ([]byte, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) AddAccountKey( + _ common.Address, + _ *stdlib.PublicKey, + _ sema.HashAlgorithm, + _ int, +) ( + *stdlib.AccountKey, + error, +) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) RevokeAccountKey(_ common.Address, _ uint32) (*stdlib.AccountKey, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) ParseAndCheckProgram(_ []byte, _ common.Location, _ bool) (*interpreter.Program, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) RecordContractUpdate(_ common.AddressLocation, _ *interpreter.CompositeValue) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) ContractUpdateRecorded(_ common.AddressLocation) bool { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) InterpretContract( + _ common.AddressLocation, + _ *interpreter.Program, + _ string, + _ stdlib.DeployedContractConstructorInvocation, +) (*interpreter.CompositeValue, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) TemporarilyRecordCode(_ common.AddressLocation, _ []byte) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) RemoveAccountContractCode(_ common.AddressLocation) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) RecordContractRemoval(_ common.AddressLocation) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) CreateAccount(_ common.Address) (address common.Address, err error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) ValidatePublicKey(_ *stdlib.PublicKey) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) VerifySignature( + _ []byte, + _ string, + _ []byte, + _ []byte, + _ sema.SignatureAlgorithm, + _ sema.HashAlgorithm, +) (bool, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) BLSVerifyPOP(_ *stdlib.PublicKey, _ []byte) (bool, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) Hash(_ []byte, _ string, _ sema.HashAlgorithm) ([]byte, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) AccountKeysCount(_ common.Address) (uint32, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) BLSAggregatePublicKeys(_ []*stdlib.PublicKey) (*stdlib.PublicKey, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) BLSAggregateSignatures(_ [][]byte) ([]byte, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) GenerateAccountID(_ common.Address) (uint64, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) ReadRandom(_ []byte) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) StartContractAddition(_ common.AddressLocation) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) EndContractAddition(_ common.AddressLocation) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) IsContractBeingAdded(_ common.AddressLocation) bool { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (CheckerEnvironment) SetCompositeValueFunctionsHandler(_ common.TypeID, _ stdlib.CompositeValueFunctionsHandler) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) Configure( + runtimeInterface runtime.Interface, + codesAndPrograms runtime.CodesAndPrograms, + storage *runtime.Storage, + coverageReport *runtime.CoverageReport, +) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) Interpret( + location common.Location, + program *interpreter.Program, + f runtime.InterpretFunc, +) ( + interpreter.Value, + *interpreter.Interpreter, + error, +) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) CommitStorage(inter *interpreter.Interpreter) error { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) NewAccountValue(inter *interpreter.Interpreter, address interpreter.AddressValue) interpreter.Value { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} + +func (e CheckerEnvironment) DecodeArgument(argument []byte, argumentType cadence.Type) (cadence.Value, error) { + // Implementation should never be called, + // only its definition is used for type-checking + panic(errors.NewUnreachableError()) +} diff --git a/internal/util/stdlib.go b/internal/util/stdlib.go deleted file mode 100644 index 2f28c944c..000000000 --- a/internal/util/stdlib.go +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Cadence - The resource-oriented smart contract programming language - * - * Copyright 2019-2022 Dapper Labs, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// NOTE: This file is a copy of the file https://github.com/onflow/cadence-tools/blob/master/languageserver/server/stdlib.go - -package util - -import ( - "github.com/onflow/cadence/runtime/common" - "github.com/onflow/cadence/runtime/errors" - "github.com/onflow/cadence/runtime/interpreter" - "github.com/onflow/cadence/runtime/sema" - "github.com/onflow/cadence/runtime/stdlib" -) - -type StandardLibrary struct { - BaseValueActivation *sema.VariableActivation -} - -var _ stdlib.StandardLibraryHandler = StandardLibrary{} - -func (StandardLibrary) ProgramLog(_ string, _ interpreter.LocationRange) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) UnsafeRandom() (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetBlockAtHeight(_ uint64) (stdlib.Block, bool, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetCurrentBlockHeight() (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetAccountBalance(_ common.Address) (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetAccountAvailableBalance(_ common.Address) (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) CommitStorageTemporarily(_ *interpreter.Interpreter) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetStorageUsed(_ common.Address) (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetStorageCapacity(_ common.Address) (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetAccountKey(_ common.Address, _ uint32) (*stdlib.AccountKey, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetAccountContractNames(_ common.Address) ([]string, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) GetAccountContractCode(_ common.AddressLocation) ([]byte, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) EmitEvent( - _ *interpreter.Interpreter, - _ interpreter.LocationRange, - _ *sema.CompositeType, - _ []interpreter.Value, -) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) AddEncodedAccountKey(_ common.Address, _ []byte) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) RevokeEncodedAccountKey(_ common.Address, _ int) ([]byte, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) AddAccountKey( - _ common.Address, - _ *stdlib.PublicKey, - _ sema.HashAlgorithm, - _ int, -) ( - *stdlib.AccountKey, - error, -) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) RevokeAccountKey(_ common.Address, _ uint32) (*stdlib.AccountKey, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) ParseAndCheckProgram(_ []byte, _ common.Location, _ bool) (*interpreter.Program, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) UpdateAccountContractCode(_ common.AddressLocation, _ []byte) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) RecordContractUpdate(_ common.AddressLocation, _ *interpreter.CompositeValue) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) ContractUpdateRecorded(_ common.AddressLocation) bool { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) InterpretContract( - _ common.AddressLocation, - _ *interpreter.Program, - _ string, - _ stdlib.DeployedContractConstructorInvocation, -) (*interpreter.CompositeValue, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) TemporarilyRecordCode(_ common.AddressLocation, _ []byte) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) RemoveAccountContractCode(_ common.AddressLocation) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) RecordContractRemoval(_ common.AddressLocation) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) CreateAccount(_ common.Address) (address common.Address, err error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) ValidatePublicKey(_ *stdlib.PublicKey) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) VerifySignature( - _ []byte, - _ string, - _ []byte, - _ []byte, - _ sema.SignatureAlgorithm, - _ sema.HashAlgorithm, -) (bool, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) BLSVerifyPOP(_ *stdlib.PublicKey, _ []byte) (bool, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) Hash(_ []byte, _ string, _ sema.HashAlgorithm) ([]byte, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) AccountKeysCount(_ common.Address) (uint32, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) BLSAggregatePublicKeys(_ []*stdlib.PublicKey) (*stdlib.PublicKey, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) BLSAggregateSignatures(_ [][]byte) ([]byte, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (l StandardLibrary) GenerateAccountID(_ common.Address) (uint64, error) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (l StandardLibrary) ReadRandom(_ []byte) error { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) StartContractAddition(_ common.AddressLocation) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) EndContractAddition(_ common.AddressLocation) { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func (StandardLibrary) IsContractBeingAdded(_ common.AddressLocation) bool { - // Implementation should never be called, - // only its definition is used for type-checking - panic(errors.NewUnreachableError()) -} - -func NewStandardLibrary() (result StandardLibrary) { - result.BaseValueActivation = sema.NewVariableActivation(sema.BaseValueActivation) - for _, valueDeclaration := range stdlib.DefaultStandardLibraryValues(result) { - result.BaseValueActivation.DeclareValue(valueDeclaration) - } - return -} - -func NewScriptStandardLibrary() (result StandardLibrary) { - result.BaseValueActivation = sema.NewVariableActivation(sema.BaseValueActivation) - for _, declaration := range stdlib.DefaultScriptStandardLibraryValues(result) { - result.BaseValueActivation.DeclareValue(declaration) - } - return -}